Compare commits
22 Commits
xemacs_20_
...
fileutils_
Author | SHA1 | Date | |
---|---|---|---|
|
1d7491be0d | ||
|
15cc0113a9 | ||
|
9532dadc2e | ||
|
94715ef718 | ||
|
44bb75cf6e | ||
|
4d2072ce65 | ||
|
eb36f97c50 | ||
|
a76522a990 | ||
|
71187a5e51 | ||
|
b54a5d2dfd | ||
|
134ec106b3 | ||
|
1b90ed4fcc | ||
|
3fcc477b25 | ||
|
81c75477f4 | ||
|
8b025ff2c2 | ||
|
2de9ea5c7d | ||
|
d9e6288b7a | ||
|
8d78559597 | ||
|
2a281d0a53 | ||
|
28dfff5752 | ||
|
7d0d3db11c | ||
|
63c475d400 |
69
ChangeLog
69
ChangeLog
@@ -1,5 +1,74 @@
|
||||
1998-07-03 Martin baulig <martin@home-of-linux.org>
|
||||
|
||||
* macros/gnome-libgtop-sysdeps.m4: No longer use
|
||||
`glibtop_machine.h' for Linux.
|
||||
|
||||
* sysdeps/linux/glibtop_machine.h: Removed.
|
||||
|
||||
* sysdeps/guile/guile.awk: Using `scm_append'
|
||||
instead of `gh_append'.
|
||||
|
||||
* sysdeps/guile/names/guile-names.awk: dito.
|
||||
|
||||
* sysdeps/linux/*.c: Using code from stable branch again.
|
||||
|
||||
* include/glibtop/parameter.h: New file.
|
||||
|
||||
* lib/parameter.c: New file.
|
||||
|
||||
* lib/{open, init}.c: Done some more work on server
|
||||
initialization
|
||||
|
||||
1998-06-21 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* perl/*: Added perl interface.
|
||||
|
||||
* sysdeps/linux/cpu.c: Bug fix.
|
||||
|
||||
* include/glibtop/global.h: Only including guile header files
|
||||
within libgtop.
|
||||
|
||||
* configure.in (LIGBTOP_LIBS): Added `-lgtop'.
|
||||
|
||||
* Makefile.am: Creating `perl/Makefile.PL' from `perl/Makefile.PL.in'
|
||||
and `perl/Libgtop.xs' using `perl/perl.awk'.
|
||||
|
||||
1998-06-18 Martin Baulig <baulig@taurus.uni-trier.de>
|
||||
|
||||
* sysdeps/linux/*.c: Reverted some stuff from 06-07-1998
|
||||
since it was too buggy.
|
||||
|
||||
* glibtop.h (_glibtop): New field `server_port'.
|
||||
|
||||
* lib/xmalloc.c (glibtop_strdup_r): New function.
|
||||
|
||||
* lib/gnuclient.c: Removed.
|
||||
|
||||
* lib/{command, write, read}.c: Changed client <-> server
|
||||
interface to make less system calls.
|
||||
|
||||
* src/daemon/main.c: Changed server side of interface.
|
||||
|
||||
* include/glibtop/command.h (struct _glibtop_response): New
|
||||
structure to return data from the server to the client.
|
||||
|
||||
1998-06-14 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* glibtop.h (struct _glibtop): Added `socket' field.
|
||||
|
||||
* include/glibtop/gnuserv.h: New file. Imported from xemacs 20.3.
|
||||
|
||||
* sysdeps/common/gnuslib.c: New file. Imported from xemacs 20.3
|
||||
|
||||
* lib/gnuclient.c: New file. Imported from xemacs 20.3
|
||||
|
||||
* sysdeps/daemon/gnuserv.c: New file. Imported from xemacs 20.3
|
||||
|
||||
* sysdeps/daemon: New directory.
|
||||
|
||||
* configure.in (LIBGTOP_LIBS, LIBGTOP_GUILE_LIBS): Added
|
||||
`$X_LIBS -lXau' when we have xauth.
|
||||
|
||||
* acconfig.h (HAVE_XAUTH): New tag.
|
||||
|
||||
* configure.in: Added check for `HAVE_XAUTH'.
|
||||
|
27
Makefile.am
27
Makefile.am
@@ -22,6 +22,9 @@ release:
|
||||
confexecdir=$(libdir)
|
||||
confexec_DATA = $(top_builddir)/libgtopConf.sh
|
||||
|
||||
noinst_DATA = $(top_builddir)/perl/Makefile.PL \
|
||||
$(top_builddir)/perl/Libgtop.xs
|
||||
|
||||
## to automatically rebuild aclocal.m4 if any of the macros in
|
||||
## `macros/' change
|
||||
@MAINT@include macros/macros.dep
|
||||
@@ -51,3 +54,27 @@ libgtopConf.sh: libgtopConf.sh.in Makefile
|
||||
-e 's,\@libgtop_want_examples\@,$(libgtop_want_examples),g' \
|
||||
< $(srcdir)/libgtopConf.sh.in > libgtopConf.tmp \
|
||||
&& mv libgtopConf.tmp libgtopConf.sh
|
||||
|
||||
perl/Makefile.PL: perl/Makefile.PL.in Makefile
|
||||
## Use sed and then mv to avoid problems if the user interrupts.
|
||||
sed -e 's,\@LIBGTOP_LIBDIR\@,$(libdir),g' \
|
||||
-e 's,\@LIBGTOP_INCLUDEDIR\@,$(includedir),g' \
|
||||
-e 's,\@LIBGTOP_LIBS\@,$(LIBGTOP_LIBS),g' \
|
||||
-e 's,\@LIBGTOP_INCS\@,$(LIBGTOP_INCS),g' \
|
||||
-e 's,\@LIBGTOP_GUILE_LIBS\@,$(LIBGTOP_GUILE_LIBS),g' \
|
||||
-e 's,\@LIBGTOP_GUILE_INCS\@,$(LIBGTOP_GUILE_INCS),g' \
|
||||
-e 's,\@LIBGTOP_BINDIR\@,$(LIBGTOP_BINDIR),g' \
|
||||
-e 's,\@LIBGTOP_SERVER\@,$(LIBGTOP_SERVER),g' \
|
||||
-e 's,\@libgtop_sysdeps_dir\@,$(libgtop_sysdeps_dir),g' \
|
||||
-e 's,\@libgtop_need_server\@,$(libgtop_need_server),g' \
|
||||
-e 's,\@libgtop_use_machine_h\@,$(libgtop_use_machine_h),g' \
|
||||
-e 's,\@libgtop_guile_found\@,$(libgtop_guile_found),g' \
|
||||
-e 's,\@libgtop_want_names\@,$(libgtop_want_names),g' \
|
||||
-e 's,\@libgtop_want_guile_names\@,$(libgtop_want_guile_names),g' \
|
||||
-e 's,\@libgtop_want_examples\@,$(libgtop_want_examples),g' \
|
||||
< $(srcdir)/perl/Makefile.PL.in > perl/Makefile.tmp \
|
||||
&& mv perl/Makefile.tmp perl/Makefile.PL
|
||||
|
||||
perl/Libgtop.xs: perl/perl.awk $(top_builddir)/config.h $(top_srcdir)/features.def
|
||||
$(AWK) -f $(top_srcdir)/perl/perl.awk < $(top_srcdir)/features.def > perl/lgt-t
|
||||
mv perl/lgt-t perl/Libgtop.xs
|
||||
|
12
configure.in
12
configure.in
@@ -6,6 +6,8 @@ AC_INIT(copyright.txt)
|
||||
AM_CONFIG_HEADER(config.h)
|
||||
AC_CANONICAL_SYSTEM
|
||||
|
||||
AM_INIT_AUTOMAKE(libgtop, 0.01)
|
||||
|
||||
AM_ACLOCAL_INCLUDE(macros)
|
||||
|
||||
AC_ISC_POSIX
|
||||
@@ -32,8 +34,6 @@ export cross_compiling
|
||||
|
||||
AM_PROG_LIBTOOL
|
||||
|
||||
AM_INIT_AUTOMAKE(libgtop, 0.01)
|
||||
|
||||
dnl If you want to use libgtop without gnome, comment the following line out.
|
||||
GNOME_INIT_HOOK(gnome_found=yes)
|
||||
|
||||
@@ -121,7 +121,7 @@ test -z "$with_xauth" && { AC_CHECK_LIB(Xau, XauGetAuthByAddr,[:],with_xauth=no,
|
||||
test -z "$with_xauth" && with_xauth=yes
|
||||
if test "$with_xauth" = "yes"; then
|
||||
AC_DEFINE(HAVE_XAUTH)
|
||||
XE_SPACE(libs_xauth, $X_EXTRA_LIBS -lXau $libs_x $X_PRE_LIBS)
|
||||
XE_SPACE(libs_xauth, $X_LIBS -lXau)
|
||||
fi
|
||||
AC_SUBST(libs_xauth)
|
||||
|
||||
@@ -154,7 +154,7 @@ AC_SUBST(LIBSUPPORT)
|
||||
AC_SUBST(SUPPORTINCS)
|
||||
|
||||
dnl These definitions are expanded in make.
|
||||
LIBGTOP_LIBS='-L$(libdir)'
|
||||
LIBGTOP_LIBS='-L$(libdir) -lgtop'
|
||||
LIBGTOP_INCS='-I$(includedir)'
|
||||
LIBGTOP_GUILE_LIBS="$LIBGTOP_LIBS"
|
||||
LIBGTOP_GUILE_INCS="$LIBGTOP_INCS"
|
||||
@@ -186,8 +186,8 @@ fi
|
||||
|
||||
AC_SUBST(libgtop_want_guile_names)
|
||||
|
||||
LIBGTOP_LIBS="$LIBGTOP_LIBS -lgtop_common"
|
||||
LIBGTOP_GUILE_LIBS="$LIBGTOP_GUILE_LIBS -lgtop_common"
|
||||
LIBGTOP_LIBS="$LIBGTOP_LIBS -lgtop_common $libs_xauth"
|
||||
LIBGTOP_GUILE_LIBS="$LIBGTOP_GUILE_LIBS -lgtop_common $libs_xauth"
|
||||
|
||||
if test "x$need_server" = "xyes" ; then
|
||||
LIBGTOP_LIBS="$LIBGTOP_LIBS -lgtop"
|
||||
|
@@ -16,20 +16,20 @@ bin_PROGRAMS = first first_static second second_static \
|
||||
EXTRA_PROGRAMS = third third_static
|
||||
|
||||
first_SOURCES = first.c
|
||||
first_LDADD = $(top_builddir)/sysdeps/common/libgtop_common.la \
|
||||
$(top_builddir)/lib/libgtop.la \
|
||||
first_LDADD = $(top_builddir)/lib/libgtop.la \
|
||||
$(top_builddir)/sysdeps/common/libgtop_common.la \
|
||||
$(top_builddir)/sysdeps/@sysdeps_dir@/libgtop_sysdeps.la \
|
||||
@INTLLIBS@ @LIBSUPPORT@
|
||||
@INTLLIBS@ @LIBSUPPORT@ @libs_xauth@
|
||||
|
||||
first_static_SOURCES = $(first_SOURCES)
|
||||
first_static_LDADD = $(first_LDADD)
|
||||
first_static_LDFLAGS = -static
|
||||
|
||||
second_SOURCES = second.c
|
||||
second_LDADD = $(top_builddir)/sysdeps/common/libgtop_common.la \
|
||||
$(top_builddir)/lib/libgtop.la \
|
||||
second_LDADD = $(top_builddir)/lib/libgtop.la \
|
||||
$(top_builddir)/sysdeps/common/libgtop_common.la \
|
||||
$(top_builddir)/sysdeps/@sysdeps_dir@/libgtop_sysdeps.la \
|
||||
@INTLLIBS@ @LIBSUPPORT@
|
||||
@INTLLIBS@ @LIBSUPPORT@ @libs_xauth@
|
||||
|
||||
second_static_SOURCES = $(second_SOURCES)
|
||||
second_static_LDADD = $(second_LDADD)
|
||||
@@ -46,7 +46,7 @@ third_LDADD = $(top_builddir)/sysdeps/guile/libgtop_guile.la \
|
||||
$(top_builddir)/lib/libgtop.la \
|
||||
$(top_builddir)/sysdeps/common/libgtop_common.la \
|
||||
$(top_builddir)/sysdeps/@sysdeps_dir@/libgtop_sysdeps.la \
|
||||
@GUILE_LIBS@ @INTLLIBS@ @LIBSUPPORT@
|
||||
@GUILE_LIBS@ @INTLLIBS@ @LIBSUPPORT@ @libs_xauth@
|
||||
|
||||
third_static_SOURCES = $(third_SOURCES)
|
||||
third_static_LDADD = $(third_LDADD)
|
||||
|
371
examples/first.c
371
examples/first.c
@@ -26,6 +26,8 @@
|
||||
#include <glibtop/close.h>
|
||||
#include <glibtop/xmalloc.h>
|
||||
|
||||
#include <glibtop/parameter.h>
|
||||
|
||||
#include <glibtop/union.h>
|
||||
#include <glibtop/sysdeps.h>
|
||||
|
||||
@@ -38,7 +40,8 @@ main (int argc, char *argv [])
|
||||
{
|
||||
glibtop_union data;
|
||||
glibtop_sysdeps sysdeps;
|
||||
unsigned c, count, i, *ptr;
|
||||
unsigned c, method, count, port, i, *ptr;
|
||||
char buffer [BUFSIZ];
|
||||
pid_t pid, ppid;
|
||||
|
||||
count = PROFILE_COUNT;
|
||||
@@ -47,98 +50,114 @@ main (int argc, char *argv [])
|
||||
bindtextdomain (PACKAGE, GTOPLOCALEDIR);
|
||||
textdomain (PACKAGE);
|
||||
|
||||
glibtop_init ();
|
||||
glibtop_init_r (&glibtop_global_server, 0, GLIBTOP_INIT_NO_OPEN);
|
||||
|
||||
glibtop_get_parameter (GLIBTOP_PARAM_METHOD, &method, sizeof (method));
|
||||
|
||||
printf ("Method = %d\n", method);
|
||||
|
||||
count = glibtop_get_parameter (GLIBTOP_PARAM_COMMAND, buffer, BUFSIZ);
|
||||
buffer [count] = 0;
|
||||
|
||||
printf ("Command = '%s'\n", buffer);
|
||||
|
||||
count = glibtop_get_parameter (GLIBTOP_PARAM_HOST, buffer, BUFSIZ);
|
||||
buffer [count] = 0;
|
||||
|
||||
glibtop_get_parameter (GLIBTOP_PARAM_PORT, &port, sizeof (port));
|
||||
|
||||
printf ("Host = '%s' - %u\n\n", buffer, port);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
glibtop_get_cpu (&data.cpu);
|
||||
|
||||
fprintf (stderr, "CPU (0x%08lx): %lu, %lu, %lu, %lu, %lu, %lu\n",
|
||||
data.cpu.flags, data.cpu.total, data.cpu.user, data.cpu.nice,
|
||||
data.cpu.sys, data.cpu.idle, data.cpu.frequency);
|
||||
printf ("CPU (0x%08lx): %lu, %lu, %lu, %lu, %lu, %lu\n",
|
||||
data.cpu.flags, data.cpu.total, data.cpu.user, data.cpu.nice,
|
||||
data.cpu.sys, data.cpu.idle, data.cpu.frequency);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
glibtop_get_mem (&data.mem);
|
||||
|
||||
fprintf (stderr, "Memory (0x%08lx): %lu, %lu, %lu, %lu, %lu, %lu, %lu, %lu\n",
|
||||
data.mem.flags, data.mem.total, data.mem.used, data.mem.free,
|
||||
data.mem.shared, data.mem.buffer, data.mem.cached,
|
||||
data.mem.user, data.mem.locked);
|
||||
printf ("Memory (0x%08lx): %lu, %lu, %lu, %lu, %lu, %lu, %lu, %lu\n",
|
||||
data.mem.flags, data.mem.total, data.mem.used, data.mem.free,
|
||||
data.mem.shared, data.mem.buffer, data.mem.cached,
|
||||
data.mem.user, data.mem.locked);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
glibtop_get_swap (&data.swap);
|
||||
|
||||
fprintf (stderr, "Swap (0x%08lx): %lu, %lu, %lu\n", data.swap.flags,
|
||||
data.swap.total, data.swap.used, data.swap.free);
|
||||
printf ("Swap (0x%08lx): %lu, %lu, %lu\n", data.swap.flags,
|
||||
data.swap.total, data.swap.used, data.swap.free);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
glibtop_get_uptime (&data.uptime);
|
||||
|
||||
fprintf (stderr, "Uptime (0x%08lx): %f, %f\n", data.uptime.flags,
|
||||
data.uptime.uptime, data.uptime.idletime);
|
||||
printf ("Uptime (0x%08lx): %f, %f\n", data.uptime.flags,
|
||||
data.uptime.uptime, data.uptime.idletime);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
glibtop_get_loadavg (&data.loadavg);
|
||||
|
||||
fprintf (stderr, "Loadavg (0x%08lx): %f, %f, %f\n", data.loadavg.flags,
|
||||
data.loadavg.loadavg [0], data.loadavg.loadavg [1],
|
||||
data.loadavg.loadavg [2]);
|
||||
printf ("Loadavg (0x%08lx): %f, %f, %f\n", data.loadavg.flags,
|
||||
data.loadavg.loadavg [0], data.loadavg.loadavg [1],
|
||||
data.loadavg.loadavg [2]);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
glibtop_get_shm_limits (&data.shm_limits);
|
||||
|
||||
fprintf (stderr, "Shm Limits (0x%08lx): %ld, %ld, %ld, %ld, %ld\n",
|
||||
data.shm_limits.flags, data.shm_limits.shmmax,
|
||||
data.shm_limits.shmmin, data.shm_limits.shmmni,
|
||||
data.shm_limits.shmseg, data.shm_limits.shmall);
|
||||
printf ("Shm Limits (0x%08lx): %ld, %ld, %ld, %ld, %ld\n",
|
||||
data.shm_limits.flags, data.shm_limits.shmmax,
|
||||
data.shm_limits.shmmin, data.shm_limits.shmmni,
|
||||
data.shm_limits.shmseg, data.shm_limits.shmall);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
glibtop_get_msg_limits (&data.msg_limits);
|
||||
|
||||
fprintf (stderr, "Msg Limits (0x%08lx): %ld, %ld, %ld, %ld, %ld, %ld, %ld\n",
|
||||
data.msg_limits.flags, data.msg_limits.msgpool,
|
||||
data.msg_limits.msgmap, data.msg_limits.msgmax,
|
||||
data.msg_limits.msgmnb, data.msg_limits.msgmni,
|
||||
data.msg_limits.msgssz, data.msg_limits.msgtql);
|
||||
printf ("Msg Limits (0x%08lx): %ld, %ld, %ld, %ld, %ld, %ld, %ld\n",
|
||||
data.msg_limits.flags, data.msg_limits.msgpool,
|
||||
data.msg_limits.msgmap, data.msg_limits.msgmax,
|
||||
data.msg_limits.msgmnb, data.msg_limits.msgmni,
|
||||
data.msg_limits.msgssz, data.msg_limits.msgtql);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
glibtop_get_sem_limits (&data.sem_limits);
|
||||
|
||||
fprintf (stderr, "Sem Limits (0x%08lx): "
|
||||
"%ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld\n",
|
||||
data.sem_limits.flags, data.sem_limits.semmap,
|
||||
data.sem_limits.semmni, data.sem_limits.semmns,
|
||||
data.sem_limits.semmnu, data.sem_limits.semmsl,
|
||||
data.sem_limits.semopm, data.sem_limits.semume,
|
||||
data.sem_limits.semusz, data.sem_limits.semvmx,
|
||||
data.sem_limits.semaem);
|
||||
printf ("Sem Limits (0x%08lx): "
|
||||
"%ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld\n",
|
||||
data.sem_limits.flags, data.sem_limits.semmap,
|
||||
data.sem_limits.semmni, data.sem_limits.semmns,
|
||||
data.sem_limits.semmnu, data.sem_limits.semmsl,
|
||||
data.sem_limits.semopm, data.sem_limits.semume,
|
||||
data.sem_limits.semusz, data.sem_limits.semvmx,
|
||||
data.sem_limits.semaem);
|
||||
|
||||
fprintf (stderr, "\n");
|
||||
printf ("\n");
|
||||
|
||||
glibtop_get_sysdeps (&sysdeps);
|
||||
|
||||
fprintf (stderr, "Sysdeps (0x%08lx): %lu, %lu, %lu, %lu, %lu, "
|
||||
"%lu, %lu, %lu, %lu, %lu, %lu, %lu, %lu, %lu, %lu, %lu\n",
|
||||
sysdeps.flags, sysdeps.cpu, sysdeps.mem, sysdeps.swap,
|
||||
sysdeps.uptime, sysdeps.loadavg, sysdeps.shm_limits,
|
||||
sysdeps.msg_limits, sysdeps.sem_limits,
|
||||
sysdeps.proclist, sysdeps.proc_state,
|
||||
sysdeps.proc_uid, sysdeps.proc_mem,
|
||||
sysdeps.proc_time, sysdeps.proc_signal,
|
||||
sysdeps.proc_kernel, sysdeps.proc_segment);
|
||||
printf ("Sysdeps (0x%08lx): %lu, %lu, %lu, %lu, %lu, "
|
||||
"%lu, %lu, %lu, %lu, %lu, %lu, %lu, %lu, %lu, %lu, %lu\n",
|
||||
sysdeps.flags, sysdeps.cpu, sysdeps.mem, sysdeps.swap,
|
||||
sysdeps.uptime, sysdeps.loadavg, sysdeps.shm_limits,
|
||||
sysdeps.msg_limits, sysdeps.sem_limits,
|
||||
sysdeps.proclist, sysdeps.proc_state,
|
||||
sysdeps.proc_uid, sysdeps.proc_mem,
|
||||
sysdeps.proc_time, sysdeps.proc_signal,
|
||||
sysdeps.proc_kernel, sysdeps.proc_segment);
|
||||
|
||||
fprintf (stderr, "\n");
|
||||
printf ("\n");
|
||||
|
||||
ptr = glibtop_get_proclist (&data.proclist);
|
||||
|
||||
fprintf (stderr, "Proclist (0x%08lx): %ld, %ld, %ld\n",
|
||||
data.proclist.flags, data.proclist.number,
|
||||
data.proclist.size, data.proclist.total);
|
||||
printf ("Proclist (0x%08lx): %ld, %ld, %ld\n",
|
||||
data.proclist.flags, data.proclist.number,
|
||||
data.proclist.size, data.proclist.total);
|
||||
|
||||
if (ptr) {
|
||||
fprintf (stderr, "\nProcess: ");
|
||||
printf ("\nProcess: ");
|
||||
for (i = 0; i < data.proclist.number; i++)
|
||||
fprintf (stderr, "%s%u", i ? ", " : "", ptr [i]);
|
||||
fprintf (stderr, "\n");
|
||||
printf ("%s%u", i ? ", " : "", ptr [i]);
|
||||
printf ("\n");
|
||||
}
|
||||
|
||||
glibtop_free (ptr);
|
||||
@@ -146,218 +165,218 @@ main (int argc, char *argv [])
|
||||
pid = getpid ();
|
||||
ppid = getppid ();
|
||||
|
||||
fprintf (stderr, "\n");
|
||||
printf ("\n");
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
glibtop_get_proc_state (&data.proc_state, pid);
|
||||
|
||||
fprintf (stderr, "Proc_State PID %5u (0x%08lx): '%s', %c, %u, %u\n",
|
||||
pid, data.proc_state.flags, data.proc_state.cmd,
|
||||
data.proc_state.state, data.proc_state.uid,
|
||||
data.proc_state.gid);
|
||||
printf ("Proc_State PID %5u (0x%08lx): '%s', %c, %u, %u\n",
|
||||
pid, data.proc_state.flags, data.proc_state.cmd,
|
||||
data.proc_state.state, data.proc_state.uid,
|
||||
data.proc_state.gid);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
glibtop_get_proc_uid (&data.proc_uid, pid);
|
||||
|
||||
fprintf (stderr, "Proc_Uid PID %5u (0x%08lx): "
|
||||
"%d %d %d %d %d %d %d %d %d %d %d %d\n",
|
||||
pid, data.proc_uid.flags, data.proc_uid.uid,
|
||||
data.proc_uid.euid, data.proc_uid.gid,
|
||||
data.proc_uid.egid, data.proc_uid.pid,
|
||||
data.proc_uid.ppid, data.proc_uid.pgrp,
|
||||
data.proc_uid.session, data.proc_uid.tty,
|
||||
data.proc_uid.tpgid, data.proc_uid.priority,
|
||||
data.proc_uid.nice);
|
||||
printf ("Proc_Uid PID %5u (0x%08lx): "
|
||||
"%d %d %d %d %d %d %d %d %d %d %d %d\n",
|
||||
pid, data.proc_uid.flags, data.proc_uid.uid,
|
||||
data.proc_uid.euid, data.proc_uid.gid,
|
||||
data.proc_uid.egid, data.proc_uid.pid,
|
||||
data.proc_uid.ppid, data.proc_uid.pgrp,
|
||||
data.proc_uid.session, data.proc_uid.tty,
|
||||
data.proc_uid.tpgid, data.proc_uid.priority,
|
||||
data.proc_uid.nice);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
glibtop_get_proc_mem (&data.proc_mem, pid);
|
||||
|
||||
fprintf (stderr, "Proc_Mem PID %5u (0x%08lx): "
|
||||
"%ld %ld %ld %ld %ld %ld\n", pid, data.proc_mem.flags,
|
||||
data.proc_mem.size, data.proc_mem.vsize,
|
||||
data.proc_mem.resident, data.proc_mem.share,
|
||||
data.proc_mem.rss, data.proc_mem.rss_rlim);
|
||||
printf ("Proc_Mem PID %5u (0x%08lx): "
|
||||
"%ld %ld %ld %ld %ld %ld\n", pid, data.proc_mem.flags,
|
||||
data.proc_mem.size, data.proc_mem.vsize,
|
||||
data.proc_mem.resident, data.proc_mem.share,
|
||||
data.proc_mem.rss, data.proc_mem.rss_rlim);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
glibtop_get_proc_time (&data.proc_time, pid);
|
||||
|
||||
fprintf (stderr, "Proc_Time PID %5u (0x%08lx): "
|
||||
"%ld %ld %ld %ld %ld %ld %ld\n", pid, data.proc_time.flags,
|
||||
data.proc_time.start_time, data.proc_time.utime,
|
||||
data.proc_time.stime, data.proc_time.cutime,
|
||||
data.proc_time.cstime, data.proc_time.timeout,
|
||||
data.proc_time.it_real_value);
|
||||
printf ("Proc_Time PID %5u (0x%08lx): "
|
||||
"%ld %ld %ld %ld %ld %ld %ld\n", pid, data.proc_time.flags,
|
||||
data.proc_time.start_time, data.proc_time.utime,
|
||||
data.proc_time.stime, data.proc_time.cutime,
|
||||
data.proc_time.cstime, data.proc_time.timeout,
|
||||
data.proc_time.it_real_value);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
glibtop_get_proc_signal (&data.proc_signal, pid);
|
||||
|
||||
fprintf (stderr, "Proc_Signal PID %5u (0x%08lx): "
|
||||
"%d %d %d %d\n", pid, data.proc_signal.flags,
|
||||
data.proc_signal.signal, data.proc_signal.blocked,
|
||||
data.proc_signal.sigignore, data.proc_signal.sigcatch);
|
||||
printf ("Proc_Signal PID %5u (0x%08lx): "
|
||||
"%d %d %d %d\n", pid, data.proc_signal.flags,
|
||||
data.proc_signal.signal, data.proc_signal.blocked,
|
||||
data.proc_signal.sigignore, data.proc_signal.sigcatch);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
glibtop_get_proc_kernel (&data.proc_kernel, pid);
|
||||
|
||||
fprintf (stderr, "Proc_Kernel PID %5u (0x%08lx): "
|
||||
"%lu %lu %lu %lu %lu %lu %lu %lu\n", pid,
|
||||
data.proc_kernel.flags, data.proc_kernel.k_flags,
|
||||
data.proc_kernel.min_flt, data.proc_kernel.maj_flt,
|
||||
data.proc_kernel.cmin_flt, data.proc_kernel.cmaj_flt,
|
||||
data.proc_kernel.kstk_esp, data.proc_kernel.kstk_eip,
|
||||
data.proc_kernel.wchan);
|
||||
printf ("Proc_Kernel PID %5u (0x%08lx): "
|
||||
"%lu %lu %lu %lu %lu %lu %lu %lu\n", pid,
|
||||
data.proc_kernel.flags, data.proc_kernel.k_flags,
|
||||
data.proc_kernel.min_flt, data.proc_kernel.maj_flt,
|
||||
data.proc_kernel.cmin_flt, data.proc_kernel.cmaj_flt,
|
||||
data.proc_kernel.kstk_esp, data.proc_kernel.kstk_eip,
|
||||
data.proc_kernel.wchan);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
glibtop_get_proc_segment (&data.proc_segment, pid);
|
||||
|
||||
fprintf (stderr, "Proc_Segment PID %5u (0x%08lx): "
|
||||
"%ld %ld %ld %ld %lu %lu %lu\n", pid, data.proc_segment.flags,
|
||||
data.proc_segment.trs, data.proc_segment.lrs,
|
||||
data.proc_segment.drs, data.proc_segment.dt,
|
||||
data.proc_segment.start_code, data.proc_segment.end_code,
|
||||
data.proc_segment.start_stack);
|
||||
printf ("Proc_Segment PID %5u (0x%08lx): "
|
||||
"%ld %ld %ld %ld %lu %lu %lu\n", pid, data.proc_segment.flags,
|
||||
data.proc_segment.trs, data.proc_segment.lrs,
|
||||
data.proc_segment.drs, data.proc_segment.dt,
|
||||
data.proc_segment.start_code, data.proc_segment.end_code,
|
||||
data.proc_segment.start_stack);
|
||||
|
||||
fprintf (stderr, "\n");
|
||||
printf ("\n");
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
glibtop_get_proc_state (&data.proc_state, ppid);
|
||||
|
||||
fprintf (stderr, "Proc_State PPID %5u (0x%08lx): '%s', %c, %u, %u\n",
|
||||
ppid, data.proc_state.flags, data.proc_state.cmd,
|
||||
data.proc_state.state, data.proc_state.uid,
|
||||
data.proc_state.gid);
|
||||
printf ("Proc_State PPID %5u (0x%08lx): '%s', %c, %u, %u\n",
|
||||
ppid, data.proc_state.flags, data.proc_state.cmd,
|
||||
data.proc_state.state, data.proc_state.uid,
|
||||
data.proc_state.gid);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
glibtop_get_proc_uid (&data.proc_uid, ppid);
|
||||
|
||||
fprintf (stderr, "Proc_Uid PPID %5u (0x%08lx): "
|
||||
"%d %d %d %d %d %d %d %d %d %d %d %d\n",
|
||||
ppid, data.proc_uid.flags, data.proc_uid.uid,
|
||||
data.proc_uid.euid, data.proc_uid.gid,
|
||||
data.proc_uid.egid, data.proc_uid.pid,
|
||||
data.proc_uid.ppid, data.proc_uid.pgrp,
|
||||
data.proc_uid.session, data.proc_uid.tty,
|
||||
data.proc_uid.tpgid, data.proc_uid.priority,
|
||||
data.proc_uid.nice);
|
||||
printf ("Proc_Uid PPID %5u (0x%08lx): "
|
||||
"%d %d %d %d %d %d %d %d %d %d %d %d\n",
|
||||
ppid, data.proc_uid.flags, data.proc_uid.uid,
|
||||
data.proc_uid.euid, data.proc_uid.gid,
|
||||
data.proc_uid.egid, data.proc_uid.pid,
|
||||
data.proc_uid.ppid, data.proc_uid.pgrp,
|
||||
data.proc_uid.session, data.proc_uid.tty,
|
||||
data.proc_uid.tpgid, data.proc_uid.priority,
|
||||
data.proc_uid.nice);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
glibtop_get_proc_mem (&data.proc_mem, ppid);
|
||||
|
||||
fprintf (stderr, "Proc_Mem PPID %5u (0x%08lx): "
|
||||
"%ld %ld %ld %ld %ld %ld\n", ppid, data.proc_mem.flags,
|
||||
data.proc_mem.size, data.proc_mem.vsize,
|
||||
data.proc_mem.resident, data.proc_mem.share,
|
||||
data.proc_mem.rss, data.proc_mem.rss_rlim);
|
||||
printf ("Proc_Mem PPID %5u (0x%08lx): "
|
||||
"%ld %ld %ld %ld %ld %ld\n", ppid, data.proc_mem.flags,
|
||||
data.proc_mem.size, data.proc_mem.vsize,
|
||||
data.proc_mem.resident, data.proc_mem.share,
|
||||
data.proc_mem.rss, data.proc_mem.rss_rlim);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
glibtop_get_proc_time (&data.proc_time, ppid);
|
||||
|
||||
fprintf (stderr, "Proc_Time PPID %5u (0x%08lx): "
|
||||
"%ld %ld %ld %ld %ld %ld %ld\n", ppid, data.proc_time.flags,
|
||||
data.proc_time.start_time, data.proc_time.utime,
|
||||
data.proc_time.stime, data.proc_time.cutime,
|
||||
data.proc_time.cstime, data.proc_time.timeout,
|
||||
data.proc_time.it_real_value);
|
||||
printf ("Proc_Time PPID %5u (0x%08lx): "
|
||||
"%ld %ld %ld %ld %ld %ld %ld\n", ppid, data.proc_time.flags,
|
||||
data.proc_time.start_time, data.proc_time.utime,
|
||||
data.proc_time.stime, data.proc_time.cutime,
|
||||
data.proc_time.cstime, data.proc_time.timeout,
|
||||
data.proc_time.it_real_value);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
glibtop_get_proc_signal (&data.proc_signal, ppid);
|
||||
|
||||
fprintf (stderr, "Proc_Signal PPID %5u (0x%08lx): "
|
||||
"%d %d %d %d\n", ppid, data.proc_signal.flags,
|
||||
data.proc_signal.signal, data.proc_signal.blocked,
|
||||
data.proc_signal.sigignore, data.proc_signal.sigcatch);
|
||||
printf ("Proc_Signal PPID %5u (0x%08lx): "
|
||||
"%d %d %d %d\n", ppid, data.proc_signal.flags,
|
||||
data.proc_signal.signal, data.proc_signal.blocked,
|
||||
data.proc_signal.sigignore, data.proc_signal.sigcatch);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
glibtop_get_proc_kernel (&data.proc_kernel, ppid);
|
||||
|
||||
fprintf (stderr, "Proc_Kernel PPID %5u (0x%08lx): "
|
||||
"%lu %lu %lu %lu %lu %lu %lu %lu\n", ppid,
|
||||
data.proc_kernel.flags, data.proc_kernel.k_flags,
|
||||
data.proc_kernel.min_flt, data.proc_kernel.maj_flt,
|
||||
data.proc_kernel.cmin_flt, data.proc_kernel.cmaj_flt,
|
||||
data.proc_kernel.kstk_esp, data.proc_kernel.kstk_eip,
|
||||
data.proc_kernel.wchan);
|
||||
printf ("Proc_Kernel PPID %5u (0x%08lx): "
|
||||
"%lu %lu %lu %lu %lu %lu %lu %lu\n", ppid,
|
||||
data.proc_kernel.flags, data.proc_kernel.k_flags,
|
||||
data.proc_kernel.min_flt, data.proc_kernel.maj_flt,
|
||||
data.proc_kernel.cmin_flt, data.proc_kernel.cmaj_flt,
|
||||
data.proc_kernel.kstk_esp, data.proc_kernel.kstk_eip,
|
||||
data.proc_kernel.wchan);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
glibtop_get_proc_segment (&data.proc_segment, ppid);
|
||||
|
||||
fprintf (stderr, "Proc_Segment PPID %5u (0x%08lx): "
|
||||
"%ld %ld %ld %ld %lu %lu %lu\n", ppid, data.proc_segment.flags,
|
||||
data.proc_segment.trs, data.proc_segment.lrs,
|
||||
data.proc_segment.drs, data.proc_segment.dt,
|
||||
data.proc_segment.start_code, data.proc_segment.end_code,
|
||||
data.proc_segment.start_stack);
|
||||
printf ("Proc_Segment PPID %5u (0x%08lx): "
|
||||
"%ld %ld %ld %ld %lu %lu %lu\n", ppid, data.proc_segment.flags,
|
||||
data.proc_segment.trs, data.proc_segment.lrs,
|
||||
data.proc_segment.drs, data.proc_segment.dt,
|
||||
data.proc_segment.start_code, data.proc_segment.end_code,
|
||||
data.proc_segment.start_stack);
|
||||
|
||||
fprintf (stderr, "\n");
|
||||
printf ("\n");
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
glibtop_get_proc_state (&data.proc_state, 1);
|
||||
|
||||
fprintf (stderr, "Proc_State INIT %5u (0x%08lx): '%s', %c, %u, %u\n",
|
||||
1, data.proc_state.flags, data.proc_state.cmd,
|
||||
data.proc_state.state, data.proc_state.uid,
|
||||
data.proc_state.gid);
|
||||
printf ("Proc_State INIT %5u (0x%08lx): '%s', %c, %u, %u\n",
|
||||
1, data.proc_state.flags, data.proc_state.cmd,
|
||||
data.proc_state.state, data.proc_state.uid,
|
||||
data.proc_state.gid);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
glibtop_get_proc_uid (&data.proc_uid, 1);
|
||||
|
||||
fprintf (stderr, "Proc_Uid INIT %5u (0x%08lx): "
|
||||
"%d %d %d %d %d %d %d %d %d %d %d %d\n",
|
||||
1, data.proc_uid.flags, data.proc_uid.uid,
|
||||
data.proc_uid.euid, data.proc_uid.gid,
|
||||
data.proc_uid.egid, data.proc_uid.pid,
|
||||
data.proc_uid.ppid, data.proc_uid.pgrp,
|
||||
data.proc_uid.session, data.proc_uid.tty,
|
||||
data.proc_uid.tpgid, data.proc_uid.priority,
|
||||
data.proc_uid.nice);
|
||||
printf ("Proc_Uid INIT %5u (0x%08lx): "
|
||||
"%d %d %d %d %d %d %d %d %d %d %d %d\n",
|
||||
1, data.proc_uid.flags, data.proc_uid.uid,
|
||||
data.proc_uid.euid, data.proc_uid.gid,
|
||||
data.proc_uid.egid, data.proc_uid.pid,
|
||||
data.proc_uid.ppid, data.proc_uid.pgrp,
|
||||
data.proc_uid.session, data.proc_uid.tty,
|
||||
data.proc_uid.tpgid, data.proc_uid.priority,
|
||||
data.proc_uid.nice);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
glibtop_get_proc_mem (&data.proc_mem, 1);
|
||||
|
||||
fprintf (stderr, "Proc_Mem INIT %5u (0x%08lx): "
|
||||
"%ld %ld %ld %ld %ld %ld\n", 1, data.proc_mem.flags,
|
||||
data.proc_mem.size, data.proc_mem.vsize,
|
||||
data.proc_mem.resident, data.proc_mem.share,
|
||||
data.proc_mem.rss, data.proc_mem.rss_rlim);
|
||||
printf ("Proc_Mem INIT %5u (0x%08lx): "
|
||||
"%ld %ld %ld %ld %ld %ld\n", 1, data.proc_mem.flags,
|
||||
data.proc_mem.size, data.proc_mem.vsize,
|
||||
data.proc_mem.resident, data.proc_mem.share,
|
||||
data.proc_mem.rss, data.proc_mem.rss_rlim);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
glibtop_get_proc_time (&data.proc_time, 1);
|
||||
|
||||
fprintf (stderr, "Proc_Time INIT %5u (0x%08lx): "
|
||||
"%ld %ld %ld %ld %ld %ld %ld\n", 1, data.proc_time.flags,
|
||||
data.proc_time.start_time, data.proc_time.utime,
|
||||
data.proc_time.stime, data.proc_time.cutime,
|
||||
data.proc_time.cstime, data.proc_time.timeout,
|
||||
data.proc_time.it_real_value);
|
||||
printf ("Proc_Time INIT %5u (0x%08lx): "
|
||||
"%ld %ld %ld %ld %ld %ld %ld\n", 1, data.proc_time.flags,
|
||||
data.proc_time.start_time, data.proc_time.utime,
|
||||
data.proc_time.stime, data.proc_time.cutime,
|
||||
data.proc_time.cstime, data.proc_time.timeout,
|
||||
data.proc_time.it_real_value);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
glibtop_get_proc_signal (&data.proc_signal, 1);
|
||||
|
||||
fprintf (stderr, "Proc_Signal INIT %5u (0x%08lx): "
|
||||
"%d %d %d %d\n", 1, data.proc_signal.flags,
|
||||
data.proc_signal.signal, data.proc_signal.blocked,
|
||||
data.proc_signal.sigignore, data.proc_signal.sigcatch);
|
||||
printf ("Proc_Signal INIT %5u (0x%08lx): "
|
||||
"%d %d %d %d\n", 1, data.proc_signal.flags,
|
||||
data.proc_signal.signal, data.proc_signal.blocked,
|
||||
data.proc_signal.sigignore, data.proc_signal.sigcatch);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
glibtop_get_proc_kernel (&data.proc_kernel, 1);
|
||||
|
||||
fprintf (stderr, "Proc_Kernel INIT %5u (0x%08lx): "
|
||||
"%lu %lu %lu %lu %lu %lu %lu %lu\n", 1,
|
||||
data.proc_kernel.flags, data.proc_kernel.k_flags,
|
||||
data.proc_kernel.min_flt, data.proc_kernel.maj_flt,
|
||||
data.proc_kernel.cmin_flt, data.proc_kernel.cmaj_flt,
|
||||
data.proc_kernel.kstk_esp, data.proc_kernel.kstk_eip,
|
||||
data.proc_kernel.wchan);
|
||||
printf ("Proc_Kernel INIT %5u (0x%08lx): "
|
||||
"%lu %lu %lu %lu %lu %lu %lu %lu\n", 1,
|
||||
data.proc_kernel.flags, data.proc_kernel.k_flags,
|
||||
data.proc_kernel.min_flt, data.proc_kernel.maj_flt,
|
||||
data.proc_kernel.cmin_flt, data.proc_kernel.cmaj_flt,
|
||||
data.proc_kernel.kstk_esp, data.proc_kernel.kstk_eip,
|
||||
data.proc_kernel.wchan);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
glibtop_get_proc_segment (&data.proc_segment, 1);
|
||||
|
||||
fprintf (stderr, "Proc_Segment INIT %5u (0x%08lx): "
|
||||
"%ld %ld %ld %ld %lu %lu %lu\n", 1, data.proc_segment.flags,
|
||||
data.proc_segment.trs, data.proc_segment.lrs,
|
||||
data.proc_segment.drs, data.proc_segment.dt,
|
||||
data.proc_segment.start_code, data.proc_segment.end_code,
|
||||
data.proc_segment.start_stack);
|
||||
printf ("Proc_Segment INIT %5u (0x%08lx): "
|
||||
"%ld %ld %ld %ld %lu %lu %lu\n", 1, data.proc_segment.flags,
|
||||
data.proc_segment.trs, data.proc_segment.lrs,
|
||||
data.proc_segment.drs, data.proc_segment.dt,
|
||||
data.proc_segment.start_code, data.proc_segment.end_code,
|
||||
data.proc_segment.start_stack);
|
||||
|
||||
exit (0);
|
||||
}
|
||||
|
@@ -35,12 +35,14 @@ typedef struct _glibtop glibtop;
|
||||
|
||||
struct _glibtop
|
||||
{
|
||||
int fd; /* Server file descriptor */
|
||||
unsigned flags;
|
||||
unsigned method; /* Server Method */
|
||||
#ifdef HAVE_GLIBTOP_MACHINE_H
|
||||
glibtop_machine machine; /* Machine dependent data */
|
||||
#endif
|
||||
int input [2]; /* Pipe client <- server */
|
||||
int output [2]; /* Pipe client -> server */
|
||||
int socket; /* Accepted connection of a socket */
|
||||
unsigned long os_version_code; /* Version code of the operating system */
|
||||
const char *name; /* Program name for error messages */
|
||||
const char *server_command; /* Command used to invoke server */
|
||||
@@ -48,6 +50,7 @@ struct _glibtop
|
||||
const char *server_user; /* Name of the user on the target host */
|
||||
const char *server_rsh; /* Command used to connect to the target host */
|
||||
unsigned long features; /* Server is required for this features */
|
||||
unsigned long server_port; /* Port on which daemon is listening */
|
||||
pid_t pid; /* PID of the server */
|
||||
};
|
||||
|
||||
|
@@ -5,4 +5,5 @@ glibtop_HEADERS = close.h loadavg.h prockernel.h procstate.h \
|
||||
proctime.h shm_limits.h version.h cpu.h msg_limits.h \
|
||||
procmem.h procuid.h swap.h write.h error.h open.h \
|
||||
procsegment.h read.h sysdeps.h xmalloc.h global.h \
|
||||
output.h procsignal.h read_data.h union.h
|
||||
output.h procsignal.h read_data.h union.h types.h \
|
||||
parameter.h
|
||||
|
@@ -50,13 +50,30 @@ __BEGIN_DECLS
|
||||
|
||||
#define GLIBTOP_MAX_CMND 18
|
||||
|
||||
typedef struct _glibtop_command glibtop_command;
|
||||
#define _GLIBTOP_PARAM_SIZE 16
|
||||
|
||||
typedef struct _glibtop_command glibtop_command;
|
||||
typedef struct _glibtop_response glibtop_response;
|
||||
|
||||
struct _glibtop_command
|
||||
{
|
||||
glibtop server;
|
||||
unsigned command;
|
||||
size_t size;
|
||||
glibtop server;
|
||||
unsigned command;
|
||||
size_t size, data_size;
|
||||
char parameter [_GLIBTOP_PARAM_SIZE];
|
||||
};
|
||||
|
||||
union _glibtop_response_union
|
||||
{
|
||||
glibtop_union data;
|
||||
glibtop_sysdeps sysdeps;
|
||||
};
|
||||
|
||||
struct _glibtop_response
|
||||
{
|
||||
off_t offset;
|
||||
size_t size, data_size;
|
||||
union _glibtop_response_union u;
|
||||
};
|
||||
|
||||
#define glibtop_call(p1, p2, p3, p4) glibtop_call_r(glibtop_global_server, p1, p2, p3, p4)
|
||||
|
@@ -62,6 +62,11 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef WITHOUT_GUILE
|
||||
#undef HAVE_GUILE
|
||||
#undef GLIBTOP_GUILE_NAMES
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_GUILE
|
||||
#include <guile/gh.h>
|
||||
#endif
|
||||
|
@@ -56,8 +56,8 @@ static char header_rcsid [] = "!Header: gnuserv.h,v 2.4 95/02/16 11:58:11 arup a
|
||||
|
||||
|
||||
#define INTERNET_DOMAIN_SOCKETS
|
||||
#define UNIX_DOMAIN_SOCKETS
|
||||
/* #define SYSV_IPC */
|
||||
// #define UNIX_DOMAIN_SOCKETS
|
||||
// #define SYSV_IPC
|
||||
|
||||
/*
|
||||
* Define additional authentication protocols to be used. These methods will
|
||||
@@ -77,7 +77,7 @@ static char header_rcsid [] = "!Header: gnuserv.h,v 2.4 95/02/16 11:58:11 arup a
|
||||
* stuff related to supporting MIT-MAGIC-COOKIE-1
|
||||
*/
|
||||
|
||||
#define MCOOKIE_SCREEN "999" /* screen # to use as the gnuserv cookie */
|
||||
#define MCOOKIE_SCREEN "42980" /* screen # to use as the gnuserv cookie */
|
||||
#define MCOOKIE_NAME "MAGIC-1" /* authentication protocol name */
|
||||
#define MCOOKIE_X_NAME "MIT-MAGIC-COOKIE-1" /* as needed by X */
|
||||
|
||||
@@ -155,9 +155,8 @@ static char header_rcsid [] = "!Header: gnuserv.h,v 2.4 95/02/16 11:58:11 arup a
|
||||
#undef TRUE
|
||||
#define TRUE 1
|
||||
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
extern char *progname;
|
||||
// extern char *optarg;
|
||||
// extern int optind;
|
||||
|
||||
/* The casts shut Sun's compiler up and are safe in the context these
|
||||
are actually used. */
|
||||
@@ -177,15 +176,18 @@ extern char *progname;
|
||||
#define CONN_IPC 2
|
||||
|
||||
/* function declarations */
|
||||
int make_connection (char *hostarg, int portarg, int *s);
|
||||
extern int glibtop_make_connection __P((const char *, int, int *));
|
||||
|
||||
#ifdef SYSV_IPC
|
||||
void disconnect_from_ipc_server();
|
||||
#endif
|
||||
|
||||
#if defined(INTERNET_DOMAIN_SOCKETS) || defined(UNIX_DOMAIN_SOCKETS)
|
||||
void send_string (int s, const char *msg);
|
||||
void disconnect_from_server (int s, int echo);
|
||||
int read_line (int s, char *dest);
|
||||
// void send_string (int s, const char *msg);
|
||||
// void disconnect_from_server (int s, int echo);
|
||||
// int read_line (int s, char *dest);
|
||||
#endif
|
||||
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
int internet_addr (char *host);
|
||||
extern long glibtop_internet_addr __P((const char *));
|
||||
#endif
|
||||
|
@@ -26,8 +26,19 @@
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#define _GLIBTOP_INIT_STATE_INIT 0x10000
|
||||
#define _GLIBTOP_INIT_STATE_OPEN 0x20000
|
||||
#define _GLIBTOP_INIT_STATE_SERVER 0x40000
|
||||
|
||||
#define GLIBTOP_INIT_NO_OPEN 1
|
||||
#define GLIBTOP_INIT_NO_INIT 2
|
||||
|
||||
#define GLIBTOP_OPEN_NO_OVERRIDE 1
|
||||
|
||||
#define GLIBTOP_METHOD_DIRECT 1
|
||||
#define GLIBTOP_METHOD_PIPE 2
|
||||
#define GLIBTOP_METHOD_INET 3
|
||||
|
||||
extern void glibtop_open_l __P((glibtop *, const char *, const unsigned long, const unsigned));
|
||||
|
||||
extern void glibtop_open_r __P((glibtop *, const char *, const unsigned long, const unsigned));
|
||||
|
42
include/glibtop/parameter.h
Normal file
42
include/glibtop/parameter.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the Gnome Top Library.
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
The Gnome Top Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The Gnome Top Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#ifndef __GLIBTOP_PARAMETER_H__
|
||||
#define __GLIBTOP_PARAMETER_H__
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/open.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#define GLIBTOP_PARAM_METHOD 1
|
||||
#define GLIBTOP_PARAM_FEATURES 2
|
||||
#define GLIBTOP_PARAM_COMMAND 3
|
||||
#define GLIBTOP_PARAM_HOST 4
|
||||
#define GLIBTOP_PARAM_PORT 5
|
||||
|
||||
#define glibtop_get_parameter(p1,p2,p3) glibtop_get_parameter_l(glibtop_global_server,p1,p2,p3)
|
||||
#define glibtop_set_parameter(p1,p2,p3) glibtop_set_parameter_l(glibtop_global_server,p1,p2,p3)
|
||||
|
||||
extern size_t glibtop_get_parameter_l __P((glibtop *, const unsigned, void *, size_t));
|
||||
extern void glibtop_set_parameter_l __P((glibtop *, const unsigned, const void *, size_t));
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
@@ -30,11 +30,13 @@ __BEGIN_DECLS
|
||||
#define glibtop_malloc(p1) glibtop_malloc_r(glibtop_global_server, p1)
|
||||
#define glibtop_calloc(p1, p2) glibtop_calloc_r(glibtop_global_server, p1, p2)
|
||||
#define glibtop_realloc(p1, p2) glibtop_realloc_r(glibtop_global_server, p1, p2)
|
||||
#define glibtop_strdup(p2) glibtop_strdup_r(glibtop_global_server, p1)
|
||||
#define glibtop_free(p1) glibtop_free_r(glibtop_global_server, p1)
|
||||
|
||||
extern void *glibtop_malloc_r __P((glibtop *, size_t));
|
||||
extern void *glibtop_calloc_r __P((glibtop *, size_t, size_t));
|
||||
extern void *glibtop_realloc_r __P((glibtop *, void *, size_t));
|
||||
extern char *glibtop_strdup_r __P((glibtop *, const char *));
|
||||
extern void glibtop_free_r __P((glibtop *, void *));
|
||||
|
||||
__END_DECLS
|
||||
|
@@ -4,11 +4,12 @@ INCLUDES = -I$(top_builddir) -I$(top_srcdir) @machine_incs@ \
|
||||
-I$(top_srcdir)/include -I$(top_srcdir)/intl @GUILE_INCS@ \
|
||||
-DGTOPLOCALEDIR=\"$(datadir)/locale\" -D_GNU_SOURCE
|
||||
|
||||
CFLAGS = -Wall -W @CFLAGS@ -DGTOP_SERVER=\""@LIBGTOP_SERVER@"\"
|
||||
CFLAGS = -Wall -W @CFLAGS@ -DGTOP_SERVER=\""@LIBGTOP_SERVER@"\" -DDEBUG
|
||||
|
||||
lib_LTLIBRARIES = libgtop.la
|
||||
|
||||
libgtop_la_SOURCES = init.c open.c close.c command.c read.c read_data.c write.c lib.c
|
||||
libgtop_la_SOURCES = init.c open.c close.c command.c read.c read_data.c \
|
||||
write.c lib.c parameter.c
|
||||
|
||||
BUILT_SOURCES = lib.c
|
||||
|
||||
@@ -19,3 +20,4 @@ lib.c: lib.awk $(top_builddir)/config.h $(top_builddir)/features.def
|
||||
EXTRA_DIST = lib.awk
|
||||
|
||||
CLEANFILES = lib.c
|
||||
|
||||
|
@@ -28,27 +28,52 @@
|
||||
|
||||
void *
|
||||
glibtop_call_l (glibtop *server, unsigned command, size_t send_size, void *send_buf,
|
||||
size_t recv_size, void *recv_buf)
|
||||
size_t recv_size, void *recv_buf)
|
||||
{
|
||||
glibtop_command *cmnd;
|
||||
void *ptr;
|
||||
glibtop_command cmnd;
|
||||
glibtop_response response;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
cmnd = glibtop_calloc_r (server, 1, sizeof (glibtop_command));
|
||||
memset (&cmnd, 0, sizeof (glibtop_command));
|
||||
|
||||
memcpy (&cmnd.server, server, sizeof (glibtop));
|
||||
|
||||
memcpy (&cmnd->server, server, sizeof (glibtop));
|
||||
cmnd.command = command;
|
||||
|
||||
/* If send_size is less than _GLIBTOP_PARAM_SIZE (normally 16 Bytes), we
|
||||
* send it together with command, so we only need one system call instead
|
||||
* of two. */
|
||||
|
||||
#ifdef DEBUG
|
||||
// fprintf (stderr, "COMMAND: send_size = %d; command = %d; sizeof (cmnd) = %d\n",
|
||||
// send_size, command, sizeof (glibtop_command));
|
||||
#endif
|
||||
|
||||
if (send_size <= _GLIBTOP_PARAM_SIZE) {
|
||||
memcpy (cmnd.parameter, send_buf, send_size);
|
||||
cmnd.size = send_size;
|
||||
} else {
|
||||
cmnd.data_size = send_size;
|
||||
}
|
||||
|
||||
cmnd->command = command;
|
||||
cmnd->size = send_size;
|
||||
|
||||
glibtop_write_l (server, sizeof (glibtop_command), cmnd);
|
||||
glibtop_write_l (server, send_size, send_buf);
|
||||
glibtop_read_l (server, recv_size, recv_buf);
|
||||
|
||||
ptr = glibtop_read_data_l (server);
|
||||
|
||||
glibtop_free_r (server, cmnd);
|
||||
|
||||
return ptr;
|
||||
glibtop_write_l (server, sizeof (glibtop_command), &cmnd);
|
||||
// glibtop_write_l (server, cmnd.data_size, send_buf);
|
||||
|
||||
glibtop_read_l (server, sizeof (glibtop_response), &response);
|
||||
|
||||
fprintf (stderr, "RESPONSE: %d - %d\n", response.offset, response.data_size);
|
||||
|
||||
if (recv_buf)
|
||||
memcpy (recv_buf, ((char *) &response) + response.offset, recv_size);
|
||||
|
||||
if (response.data_size) {
|
||||
void *ptr = glibtop_malloc_r (server, response.data_size);
|
||||
|
||||
glibtop_read_l (server, response.data_size, ptr);
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
620
lib/gnuclient.c
620
lib/gnuclient.c
@@ -1,620 +0,0 @@
|
||||
/* -*-C-*-
|
||||
Client code to allow local and remote editing of files by XEmacs.
|
||||
Copyright (C) 1989 Free Software Foundation, Inc.
|
||||
Copyright (C) 1995 Sun Microsystems, Inc.
|
||||
Copyright (C) 1997 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of XEmacs.
|
||||
|
||||
XEmacs is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2, or (at your option) any
|
||||
later version.
|
||||
|
||||
XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with XEmacs; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
|
||||
Author: Andy Norman (ange@hplb.hpl.hp.com), based on
|
||||
'etc/emacsclient.c' from the GNU Emacs 18.52 distribution.
|
||||
|
||||
Please mail bugs and suggestions to the author at the above address.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file incorporates new features added by Bob Weiner <weiner@mot.com>,
|
||||
* Darrell Kindred <dkindred@cmu.edu> and Arup Mukherjee <arup@cmu.edu>.
|
||||
* GNUATTACH support added by Ben Wing <wing@xemacs.org>.
|
||||
* Please see the note at the end of the README file for details.
|
||||
*
|
||||
* (If gnuserv came bundled with your emacs, the README file is probably
|
||||
* ../etc/gnuserv.README relative to the directory containing this file)
|
||||
*/
|
||||
|
||||
#if 0
|
||||
/* Hand-munged RCS header */
|
||||
static char rcsid [] = "!Header: gnuclient.c,v 2.2 95/12/12 01:39:21 wing nene !";
|
||||
#endif
|
||||
|
||||
#include "gnuserv.h"
|
||||
#include "getopt.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif /* HAVE_STRING_H */
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif /* HAVE_UNISTD_H */
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#if !defined(SYSV_IPC) && !defined(UNIX_DOMAIN_SOCKETS) && \
|
||||
!defined(INTERNET_DOMAIN_SOCKETS)
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
fprintf (stderr, "Sorry, the Emacs server is only "
|
||||
"supported on systems that have\n");
|
||||
fprintf (stderr, "Unix Domain sockets, Internet Domain "
|
||||
"sockets or System V IPC.\n");
|
||||
exit (1);
|
||||
} /* main */
|
||||
#else /* SYSV_IPC || UNIX_DOMAIN_SOCKETS || INTERNET_DOMAIN_SOCKETS */
|
||||
|
||||
static char cwd[MAXPATHLEN+2]; /* current working directory when calculated */
|
||||
static char *cp = NULL; /* ptr into valid bit of cwd above */
|
||||
|
||||
static pid_t emacs_pid; /* Process id for emacs process */
|
||||
|
||||
void initialize_signals (void);
|
||||
|
||||
static void
|
||||
tell_emacs_to_resume (int sig)
|
||||
{
|
||||
char buffer[GSERV_BUFSZ+1];
|
||||
int s; /* socket / msqid to server */
|
||||
int connect_type; /* CONN_UNIX, CONN_INTERNET, or
|
||||
ONN_IPC */
|
||||
|
||||
/* Why is SYSV so retarded? */
|
||||
/* We want emacs to realize that we are resuming */
|
||||
signal(SIGCONT, tell_emacs_to_resume);
|
||||
|
||||
connect_type = make_connection (NULL, (u_short) 0, &s);
|
||||
|
||||
sprintf(buffer,"(gnuserv-eval '(resume-pid-console %d))", (int)getpid());
|
||||
send_string(s, buffer);
|
||||
|
||||
#ifdef SYSV_IPC
|
||||
if (connect_type == (int) CONN_IPC)
|
||||
disconnect_from_ipc_server (s, msgp, FALSE);
|
||||
#else /* !SYSV_IPC */
|
||||
if (connect_type != (int) CONN_IPC)
|
||||
disconnect_from_server (s, FALSE);
|
||||
#endif /* !SYSV_IPC */
|
||||
}
|
||||
|
||||
static void
|
||||
pass_signal_to_emacs (int sig)
|
||||
{
|
||||
if (kill (emacs_pid, sig) == -1)
|
||||
{
|
||||
fprintf (stderr, "gnuattach: Could not pass signal to emacs process\n");
|
||||
exit (1);
|
||||
}
|
||||
initialize_signals ();
|
||||
}
|
||||
|
||||
void
|
||||
initialize_signals ()
|
||||
{
|
||||
/* Set up signal handler to pass relevant signals to emacs process.
|
||||
We used to send SIGSEGV, SIGBUS, SIGPIPE, SIGILL and others to
|
||||
Emacs, but I think it's better not to. I can see no reason why
|
||||
Emacs should SIGSEGV whenever gnuclient SIGSEGV-s, etc. */
|
||||
signal (SIGHUP, pass_signal_to_emacs);
|
||||
signal (SIGQUIT, pass_signal_to_emacs);
|
||||
signal (SIGINT, pass_signal_to_emacs);
|
||||
#ifdef SIGWINCH
|
||||
signal (SIGWINCH, pass_signal_to_emacs);
|
||||
#endif
|
||||
|
||||
/* We want emacs to realize that we are resuming */
|
||||
signal (SIGCONT, tell_emacs_to_resume);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
get_current_working_directory -- return the cwd.
|
||||
*/
|
||||
static char *
|
||||
get_current_working_directory (void)
|
||||
{
|
||||
if (cp == NULL)
|
||||
{ /* haven't calculated it yet */
|
||||
#ifdef BSD
|
||||
if (getwd (cwd) == 0)
|
||||
#else /* !BSD */
|
||||
if (getcwd (cwd,MAXPATHLEN) == NULL)
|
||||
#endif /* !BSD */
|
||||
{
|
||||
perror (progname);
|
||||
fprintf (stderr, "%s: unable to get current working directory\n",
|
||||
progname);
|
||||
exit (1);
|
||||
} /* if */
|
||||
|
||||
/* on some systems, cwd can look like '@machine/' ... */
|
||||
/* ignore everything before the first '/' */
|
||||
for (cp = cwd; *cp && *cp != '/'; ++cp)
|
||||
;
|
||||
|
||||
} /* if */
|
||||
|
||||
return cp;
|
||||
|
||||
} /* get_current_working_directory */
|
||||
|
||||
|
||||
/*
|
||||
filename_expand -- try to convert the given filename into a fully-qualified
|
||||
pathname.
|
||||
*/
|
||||
static void
|
||||
filename_expand (char *fullpath, char *filename)
|
||||
/* fullpath - returned full pathname */
|
||||
/* filename - filename to expand */
|
||||
{
|
||||
int len;
|
||||
|
||||
fullpath[0] = '\0';
|
||||
|
||||
if (filename[0] && filename[0] != '/')
|
||||
{ /* relative filename */
|
||||
strcat (fullpath, get_current_working_directory ());
|
||||
len = strlen (fullpath);
|
||||
|
||||
if (len > 0 && fullpath[len-1] == '/') /* trailing slash already? */
|
||||
; /* yep */
|
||||
else
|
||||
strcat (fullpath, "/"); /* nope, append trailing slash */
|
||||
} /* if */
|
||||
|
||||
strcat (fullpath,filename);
|
||||
|
||||
} /* filename_expand */
|
||||
|
||||
/* Encase the string in quotes, escape all the backslashes and quotes
|
||||
in string. */
|
||||
static char *
|
||||
clean_string (CONST char *s)
|
||||
{
|
||||
int i = 0;
|
||||
char *p, *res;
|
||||
|
||||
for (p = s; *p; p++, i++)
|
||||
{
|
||||
if (*p == '\\' || *p == '\"')
|
||||
++i;
|
||||
else if (*p == '\004')
|
||||
i += 3;
|
||||
}
|
||||
p = res = (char *)malloc (i + 2 + 1);
|
||||
*p++ = '\"';
|
||||
for (; *s; p++, s++)
|
||||
{
|
||||
switch (*s)
|
||||
{
|
||||
case '\\':
|
||||
*p++ = '\\';
|
||||
*p = '\\';
|
||||
break;
|
||||
case '\"':
|
||||
*p++ = '\\';
|
||||
*p = '\"';
|
||||
break;
|
||||
case '\004':
|
||||
*p++ = '\\';
|
||||
*p++ = 'C';
|
||||
*p++ = '-';
|
||||
*p = 'd';
|
||||
break;
|
||||
default:
|
||||
*p = *s;
|
||||
}
|
||||
}
|
||||
*p++ = '\"';
|
||||
*p = '\0';
|
||||
return res;
|
||||
}
|
||||
|
||||
#define GET_ARGUMENT(var, desc) do { \
|
||||
if (*(p + 1)) (var) = p + 1; \
|
||||
else \
|
||||
{ \
|
||||
if (!argv[++i]) \
|
||||
{ \
|
||||
fprintf (stderr, "%s: `%s' must be followed by an argument\n", \
|
||||
progname, desc); \
|
||||
exit (1); \
|
||||
} \
|
||||
(var) = argv[i]; \
|
||||
} \
|
||||
over = 1; \
|
||||
} while (0)
|
||||
|
||||
/* A strdup immitation. */
|
||||
static char *
|
||||
my_strdup (CONST char *s)
|
||||
{
|
||||
char *new = malloc (strlen (s) + 1);
|
||||
if (new)
|
||||
strcpy (new, s);
|
||||
return new;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
int starting_line = 1; /* line to start editing at */
|
||||
char command[MAXPATHLEN+50]; /* emacs command buffer */
|
||||
char fullpath[MAXPATHLEN+1]; /* full pathname to file */
|
||||
char *eval_form = NULL; /* form to evaluate with `-eval' */
|
||||
char *eval_function = NULL; /* function to evaluate with `-f' */
|
||||
char *load_library = NULL; /* library to load */
|
||||
int quick = 0; /* quick edit, don't wait for user to
|
||||
finish */
|
||||
int batch = 0; /* batch mode */
|
||||
int view = 0; /* view only. */
|
||||
int nofiles = 0;
|
||||
int errflg = 0; /* option error */
|
||||
int s; /* socket / msqid to server */
|
||||
int connect_type; /* CONN_UNIX, CONN_INTERNET, or
|
||||
* CONN_IPC */
|
||||
int suppress_windows_system = 0;
|
||||
char *display = NULL;
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
char *hostarg = NULL; /* remote hostname */
|
||||
char *remotearg;
|
||||
char thishost[HOSTNAMSZ]; /* this hostname */
|
||||
char remotepath[MAXPATHLEN+1]; /* remote pathname */
|
||||
char *path;
|
||||
int rflg = 0; /* pathname given on cmdline */
|
||||
char *portarg;
|
||||
u_short port = 0; /* port to server */
|
||||
#endif /* INTERNET_DOMAIN_SOCKETS */
|
||||
#ifdef SYSV_IPC
|
||||
struct msgbuf *msgp; /* message */
|
||||
#endif /* SYSV_IPC */
|
||||
char *tty = NULL;
|
||||
char buffer[GSERV_BUFSZ + 1]; /* buffer to read pid */
|
||||
char result[GSERV_BUFSZ + 1];
|
||||
int i;
|
||||
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
memset (remotepath, 0, sizeof (remotepath));
|
||||
#endif /* INTERNET_DOMAIN_SOCKETS */
|
||||
|
||||
progname = strrchr (argv[0], '/');
|
||||
if (progname)
|
||||
++progname;
|
||||
else
|
||||
progname = argv[0];
|
||||
|
||||
display = getenv ("DISPLAY");
|
||||
if (!display)
|
||||
suppress_windows_system = 1;
|
||||
else
|
||||
display = my_strdup (display);
|
||||
|
||||
for (i = 1; argv[i] && !errflg; i++)
|
||||
{
|
||||
if (*argv[i] != '-')
|
||||
break;
|
||||
else if (*argv[i] == '-'
|
||||
&& (*(argv[i] + 1) == '\0'
|
||||
|| (*(argv[i] + 1) == '-' && *(argv[i] + 2) == '\0')))
|
||||
{
|
||||
/* `-' or `--' */
|
||||
++i;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!strcmp (argv[i], "-batch") || !strcmp (argv[i], "--batch"))
|
||||
batch = 1;
|
||||
else if (!strcmp (argv[i], "-eval") || !strcmp (argv[i], "--eval"))
|
||||
{
|
||||
if (!argv[++i])
|
||||
{
|
||||
fprintf (stderr, "%s: `-eval' must be followed by an argument\n",
|
||||
progname);
|
||||
exit (1);
|
||||
}
|
||||
eval_form = argv[i];
|
||||
}
|
||||
else if (!strcmp (argv[i], "-display") || !strcmp (argv[i], "--display"))
|
||||
{
|
||||
suppress_windows_system = 0;
|
||||
if (!argv[++i])
|
||||
{
|
||||
fprintf (stderr,
|
||||
"%s: `-display' must be followed by an argument\n",
|
||||
progname);
|
||||
exit (1);
|
||||
}
|
||||
if (display)
|
||||
free (display);
|
||||
/* no need to strdup. */
|
||||
display = argv[i];
|
||||
}
|
||||
else if (!strcmp (argv[i], "-nw"))
|
||||
suppress_windows_system = 1;
|
||||
else
|
||||
{
|
||||
/* Iterate over one-letter options. */
|
||||
char *p;
|
||||
int over = 0;
|
||||
for (p = argv[i] + 1; *p && !over; p++)
|
||||
{
|
||||
switch (*p)
|
||||
{
|
||||
case 'q':
|
||||
quick = 1;
|
||||
break;
|
||||
case 'v':
|
||||
view = 1;
|
||||
break;
|
||||
case 'f':
|
||||
GET_ARGUMENT (eval_function, "-f");
|
||||
break;
|
||||
case 'l':
|
||||
GET_ARGUMENT (load_library, "-l");
|
||||
break;
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
case 'h':
|
||||
GET_ARGUMENT (hostarg, "-h");
|
||||
break;
|
||||
case 'p':
|
||||
GET_ARGUMENT (portarg, "-p");
|
||||
port = atoi (portarg);
|
||||
break;
|
||||
case 'r':
|
||||
GET_ARGUMENT (remotearg, "-r");
|
||||
strcpy (remotepath, remotearg);
|
||||
rflg = 1;
|
||||
break;
|
||||
#endif /* INTERNET_DOMAIN_SOCKETS */
|
||||
default:
|
||||
errflg = 1;
|
||||
}
|
||||
} /* for */
|
||||
} /* else */
|
||||
} /* for */
|
||||
|
||||
if (errflg)
|
||||
{
|
||||
fprintf (stderr,
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
"usage: %s [-nw] [-display display] [-q] [-v] [-l library]\n"
|
||||
" [-batch] [-f function] [-eval form]\n"
|
||||
" [-h host] [-p port] [-r remote-path] [[+line] file] ...\n",
|
||||
#else /* !INTERNET_DOMAIN_SOCKETS */
|
||||
"usage: %s [-nw] [-q] [-v] [-l library] [-f function] [-eval form] "
|
||||
"[[+line] path] ...\n",
|
||||
#endif /* !INTERNET_DOMAIN_SOCKETS */
|
||||
progname);
|
||||
exit (1);
|
||||
}
|
||||
if (batch && argv[i])
|
||||
{
|
||||
fprintf (stderr, "%s: Cannot specify `-batch' with file names\n",
|
||||
progname);
|
||||
exit (1);
|
||||
}
|
||||
if (suppress_windows_system && hostarg)
|
||||
{
|
||||
fprintf (stderr, "%s: Remote editing is available only on X\n",
|
||||
progname);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
*result = '\0';
|
||||
if (eval_function || eval_form || load_library)
|
||||
{
|
||||
#if defined(INTERNET_DOMAIN_SOCKETS)
|
||||
connect_type = make_connection (hostarg, port, &s);
|
||||
#else
|
||||
connect_type = make_connection (NULL, (u_short) 0, &s);
|
||||
#endif
|
||||
sprintf (command, "(gnuserv-eval%s '(progn ", quick ? "-quickly" : "");
|
||||
send_string (s, command);
|
||||
if (load_library)
|
||||
{
|
||||
sprintf (command, " (load-library %s)", clean_string (load_library));
|
||||
send_string (s, command);
|
||||
}
|
||||
if (eval_form)
|
||||
{
|
||||
sprintf (command, " %s", eval_form);
|
||||
send_string (s, command);
|
||||
}
|
||||
if (eval_function)
|
||||
{
|
||||
sprintf (command, " (%s)", eval_function);
|
||||
send_string (s, command);
|
||||
}
|
||||
send_string (s, "))");
|
||||
send_string (s, EOT_STR);
|
||||
if (read_line (s, result) == 0)
|
||||
{
|
||||
fprintf (stderr, "%s: Could not read\n", progname);
|
||||
exit (1);
|
||||
}
|
||||
} /* eval_function || eval_form || load_library */
|
||||
else if (batch)
|
||||
{
|
||||
fprintf (stderr, "%s: `-batch' requires an evaluation\n",
|
||||
progname);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if (!batch)
|
||||
{
|
||||
if (suppress_windows_system)
|
||||
{
|
||||
tty = ttyname (0);
|
||||
if (!tty)
|
||||
{
|
||||
fprintf (stderr, "%s: Not connected to a tty", progname);
|
||||
exit (1);
|
||||
}
|
||||
#if defined(INTERNET_DOMAIN_SOCKETS)
|
||||
connect_type = make_connection (hostarg, port, &s);
|
||||
#else
|
||||
connect_type = make_connection (NULL, (u_short) 0, &s);
|
||||
#endif
|
||||
send_string (s, "(gnuserv-eval '(emacs-pid))");
|
||||
send_string (s, EOT_STR);
|
||||
|
||||
if (read_line (s, buffer) == 0)
|
||||
{
|
||||
fprintf (stderr, "%s: Could not establish Emacs procces id\n",
|
||||
progname);
|
||||
exit (1);
|
||||
}
|
||||
/* Don't do disconnect_from_server becasue we have already read
|
||||
data, and disconnect doesn't do anything else. */
|
||||
#ifndef INTERNET_DOMAIN_SOCKETS
|
||||
if (connect_type == (int) CONN_IPC)
|
||||
disconnect_from_ipc_server (s, msgp, FALSE);
|
||||
#endif /* !SYSV_IPC */
|
||||
|
||||
emacs_pid = (pid_t)atol(buffer);
|
||||
initialize_signals();
|
||||
} /* suppress_windows_system */
|
||||
|
||||
#if defined(INTERNET_DOMAIN_SOCKETS)
|
||||
connect_type = make_connection (hostarg, port, &s);
|
||||
#else
|
||||
connect_type = make_connection (NULL, (u_short) 0, &s);
|
||||
#endif
|
||||
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
if (connect_type == (int) CONN_INTERNET)
|
||||
{
|
||||
char *ptr;
|
||||
gethostname (thishost, HOSTNAMSZ);
|
||||
if (!rflg)
|
||||
{ /* attempt to generate a path
|
||||
* to this machine */
|
||||
if ((ptr = getenv ("GNU_NODE")) != NULL)
|
||||
/* user specified a path */
|
||||
strcpy (remotepath, ptr);
|
||||
}
|
||||
#if 0 /* This is really bogus... re-enable it if you must have it! */
|
||||
#if defined (hp9000s300) || defined (hp9000s800)
|
||||
else if (strcmp (thishost,hostarg))
|
||||
{ /* try /net/thishost */
|
||||
strcpy (remotepath, "/net/"); /* (this fails using internet
|
||||
addresses) */
|
||||
strcat (remotepath, thishost);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{ /* same machines, no need for path */
|
||||
remotepath[0] = '\0'; /* default is the empty path */
|
||||
}
|
||||
#endif /* INTERNET_DOMAIN_SOCKETS */
|
||||
|
||||
#ifdef SYSV_IPC
|
||||
if ((msgp = (struct msgbuf *)
|
||||
malloc (sizeof *msgp + GSERV_BUFSZ)) == NULL)
|
||||
{
|
||||
fprintf (stderr, "%s: not enough memory for message buffer\n", progname);
|
||||
exit (1);
|
||||
} /* if */
|
||||
|
||||
msgp->mtext[0] = '\0'; /* ready for later strcats */
|
||||
#endif /* SYSV_IPC */
|
||||
|
||||
if (suppress_windows_system)
|
||||
{
|
||||
char *term = getenv ("TERM");
|
||||
if (!term)
|
||||
{
|
||||
fprintf (stderr, "%s: unknown terminal type\n", progname);
|
||||
exit (1);
|
||||
}
|
||||
sprintf (command, "(gnuserv-edit-files '(tty %s %s %d) '(",
|
||||
clean_string (tty), clean_string (term), (int)getpid ());
|
||||
}
|
||||
else /* !suppress_windows_system */
|
||||
{
|
||||
sprintf (command, "(gnuserv-edit-files '(x %s) '(",
|
||||
clean_string (display));
|
||||
} /* !suppress_windows_system */
|
||||
send_string (s, command);
|
||||
|
||||
if (!argv[i])
|
||||
nofiles = 1;
|
||||
|
||||
for (; argv[i]; i++)
|
||||
{
|
||||
if (i < argc - 1 && *argv[i] == '+')
|
||||
starting_line = atoi (argv[i++]);
|
||||
else
|
||||
starting_line = 1;
|
||||
/* If the last argument is +something, treat it as a file. */
|
||||
if (i == argc)
|
||||
{
|
||||
starting_line = 1;
|
||||
--i;
|
||||
}
|
||||
filename_expand (fullpath, argv[i]);
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
path = malloc (strlen (remotepath) + strlen (fullpath) + 1);
|
||||
sprintf (path, "%s%s", remotepath, fullpath);
|
||||
#else
|
||||
path = my_strdup (fullpath);
|
||||
#endif
|
||||
sprintf (command, "(%d . %s)", starting_line, clean_string (path));
|
||||
send_string (s, command);
|
||||
free (path);
|
||||
} /* for */
|
||||
|
||||
sprintf (command, ")%s%s",
|
||||
(quick || (nofiles && !suppress_windows_system)) ? " 'quick" : "",
|
||||
view ? " 'view" : "");
|
||||
send_string (s, command);
|
||||
send_string (s, ")");
|
||||
|
||||
#ifdef SYSV_IPC
|
||||
if (connect_type == (int) CONN_IPC)
|
||||
disconnect_from_ipc_server (s, msgp, FALSE);
|
||||
#else /* !SYSV_IPC */
|
||||
if (connect_type != (int) CONN_IPC)
|
||||
disconnect_from_server (s, FALSE);
|
||||
#endif /* !SYSV_IPC */
|
||||
} /* not batch */
|
||||
|
||||
if (batch && !quick)
|
||||
printf ("%s\n", result);
|
||||
|
||||
return 0;
|
||||
|
||||
} /* main */
|
||||
|
||||
#endif /* SYSV_IPC || UNIX_DOMAIN_SOCKETS || INTERNET_DOMAIN_SOCKETS */
|
169
lib/init.c
169
lib/init.c
@@ -20,23 +20,168 @@
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/open.h>
|
||||
#include <glibtop/xmalloc.h>
|
||||
#include <glibtop/parameter.h>
|
||||
|
||||
static glibtop _glibtop_global_server;
|
||||
glibtop *glibtop_global_server = NULL;
|
||||
#ifndef DEFAULT_PORT
|
||||
#define DEFAULT_PORT 42800
|
||||
#endif
|
||||
|
||||
static glibtop _glibtop_global_server;
|
||||
glibtop *glibtop_global_server = &_glibtop_global_server;
|
||||
|
||||
|
||||
void
|
||||
_init_server (glibtop *server, const unsigned features)
|
||||
{
|
||||
char *command, *temp;
|
||||
|
||||
/* Try to get server command, but don't override if already
|
||||
* set via glibtop_set_parameter () */
|
||||
|
||||
if (server->server_command == NULL) {
|
||||
const char *temp = getenv ("LIBGTOP_SERVER") ?
|
||||
getenv ("LIBGTOP_SERVER") : GTOP_SERVER;
|
||||
|
||||
server->server_command = glibtop_strdup_r (server, temp);
|
||||
}
|
||||
|
||||
if (server->server_rsh == NULL) {
|
||||
const char *temp = getenv ("LIBGTOP_RSH") ?
|
||||
getenv ("LIBGTOP_RSH") : "/usr/bin/ssh";
|
||||
|
||||
server->server_rsh = glibtop_strdup_r (server, temp);
|
||||
}
|
||||
|
||||
/* Try to get server method, but don't override if already
|
||||
* set via glibtop_set_parameter () */
|
||||
|
||||
if (server->method) return;
|
||||
|
||||
/* If server->command doesn't start with a colon, then it is
|
||||
* the full pathname of the server executable. */
|
||||
|
||||
if (server->server_command [0] != ':') {
|
||||
if (features & glibtop_server_features) {
|
||||
|
||||
/* We really need the server. */
|
||||
|
||||
server->method = GLIBTOP_METHOD_PIPE;
|
||||
|
||||
} else {
|
||||
|
||||
/* Fine. No server is needed, so we call the
|
||||
* sysdeps functions directly. */
|
||||
|
||||
server->method = GLIBTOP_METHOD_DIRECT;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* If the first character of 'server_command' is a colon,
|
||||
* the first field is the method to connect to the server. */
|
||||
|
||||
/* Everything up to the next colon is the method. */
|
||||
|
||||
command = glibtop_strdup_r (server, server->server_command+1);
|
||||
temp = strstr (command, ":");
|
||||
if (temp) *temp = 0;
|
||||
|
||||
/* Dispatch method. */
|
||||
|
||||
if (!strcmp (command, "direct")) {
|
||||
|
||||
/* Use sysdeps dir instead of connecting to server
|
||||
* even if using the server would be required on
|
||||
* the current system. */
|
||||
|
||||
server->method = GLIBTOP_METHOD_DIRECT;
|
||||
|
||||
} else if (!strcmp (command, "inet")) {
|
||||
|
||||
server->method = GLIBTOP_METHOD_INET;
|
||||
|
||||
/* Connect to internet server. */
|
||||
|
||||
if (temp == NULL) {
|
||||
/* If no value was set, we use 'localhost'. */
|
||||
if (server->server_host == NULL)
|
||||
server->server_host = glibtop_strdup_r
|
||||
(server, "localhost");
|
||||
} else {
|
||||
char *temp2 = strstr (temp+1, ":");
|
||||
if (temp2) *temp2 = 0;
|
||||
|
||||
/* Override default. */
|
||||
if (server->server_host)
|
||||
glibtop_free_r (server, (char *) server->server_host);
|
||||
|
||||
server->server_host = glibtop_strdup_r
|
||||
(server, temp+1);
|
||||
|
||||
temp = temp2;
|
||||
}
|
||||
|
||||
if (temp == NULL) {
|
||||
/* If no value was set, we use DEFAULT_PORT. */
|
||||
if (server->server_port == 0)
|
||||
server->server_port = DEFAULT_PORT;
|
||||
} else {
|
||||
char *temp2 = strstr (temp+1, ":");
|
||||
if (temp2) *temp2 = 0;
|
||||
|
||||
if (sscanf (temp+1, "%ld", &server->server_port) != 1)
|
||||
server->server_port = DEFAULT_PORT;
|
||||
|
||||
temp = temp2 ? temp2 + 1 : temp2;
|
||||
}
|
||||
} else {
|
||||
glibtop_error_r (server, "Unknown server method '%s'",
|
||||
server->server_command+1);
|
||||
}
|
||||
|
||||
glibtop_free_r (server, command);
|
||||
}
|
||||
|
||||
glibtop *
|
||||
glibtop_init_r (glibtop **server, const unsigned long features,
|
||||
const unsigned flags)
|
||||
glibtop_init_r (glibtop **server_ptr, const unsigned long features,
|
||||
const unsigned flags)
|
||||
{
|
||||
if (*server != NULL)
|
||||
return *server;
|
||||
glibtop *server;
|
||||
|
||||
if (glibtop_global_server == NULL) {
|
||||
glibtop_global_server = &_glibtop_global_server;
|
||||
glibtop_open_l (glibtop_global_server, "glibtop",
|
||||
features, flags);
|
||||
if (server_ptr == NULL)
|
||||
return NULL;
|
||||
|
||||
if (*server_ptr == NULL)
|
||||
*server_ptr = glibtop_global_server;
|
||||
|
||||
server = *server_ptr;
|
||||
|
||||
/* Should we do the initialization? */
|
||||
|
||||
if (flags & GLIBTOP_INIT_NO_INIT)
|
||||
return server;
|
||||
|
||||
/* Do the initialization, but only if not already initialized. */
|
||||
|
||||
if ((server->flags & _GLIBTOP_INIT_STATE_INIT) == 0) {
|
||||
_init_server (server, features);
|
||||
|
||||
server->flags |= _GLIBTOP_INIT_STATE_INIT;
|
||||
}
|
||||
|
||||
/* Should we open the server? */
|
||||
|
||||
if (flags & GLIBTOP_INIT_NO_OPEN)
|
||||
return server;
|
||||
|
||||
/* Open server, but only if not already opened. */
|
||||
|
||||
return *server = glibtop_global_server;
|
||||
if ((server->flags & _GLIBTOP_INIT_STATE_OPEN) == 0)
|
||||
glibtop_open_l (glibtop_global_server, "glibtop",
|
||||
features, flags);
|
||||
|
||||
return server;
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ BEGIN {
|
||||
print "";
|
||||
|
||||
print "#include <glibtop.h>";
|
||||
print "#include <glibtop/open.h>";
|
||||
print "#include <glibtop/sysdeps.h>";
|
||||
print "#include <glibtop/command.h>";
|
||||
|
||||
@@ -29,7 +30,9 @@ function output(feature) {
|
||||
print "{";
|
||||
print "\tglibtop_init_r (&server, GLIBTOP_SYSDEPS_"toupper(feature)", 0);";
|
||||
print "";
|
||||
print "\tif (server->features & GLIBTOP_SYSDEPS_"toupper(feature)") {";
|
||||
print "\tif ((server->flags & _GLIBTOP_INIT_STATE_SERVER) &&";
|
||||
print "\t (server->features & GLIBTOP_SYSDEPS_"toupper(feature)"))";
|
||||
print "\t{";
|
||||
|
||||
if (feature ~ /^proc_/) {
|
||||
print "\t\t"prefix"glibtop_call_l (server, GLIBTOP_CMND_"toupper(feature)", sizeof (pid_t),";
|
||||
|
138
lib/open.c
138
lib/open.c
@@ -25,132 +25,44 @@
|
||||
#include <glibtop/command.h>
|
||||
#include <glibtop/xmalloc.h>
|
||||
|
||||
#include <glibtop/gnuserv.h>
|
||||
|
||||
/* Opens pipe to gtop server. Returns 0 on success and -1 on error. */
|
||||
|
||||
void
|
||||
glibtop_open_l (glibtop *server, const char *program_name,
|
||||
const unsigned long features, const unsigned flags)
|
||||
const unsigned long features, const unsigned flags)
|
||||
{
|
||||
char version [BUFSIZ], buffer [BUFSIZ];
|
||||
char *server_command, *server_rsh, *temp;
|
||||
char *server_host, *server_user;
|
||||
glibtop_sysdeps sysdeps;
|
||||
|
||||
memset (server, 0, sizeof (glibtop));
|
||||
|
||||
server->name = program_name;
|
||||
|
||||
/* Is the user allowed to override the server ? */
|
||||
/* It is important to set _GLIBTOP_INIT_STATE_OPEN here when we
|
||||
* do recursive calls to glibtop_init_r (). */
|
||||
|
||||
if ((flags & GLIBTOP_OPEN_NO_OVERRIDE) == 0) {
|
||||
server->flags |= _GLIBTOP_INIT_STATE_OPEN;
|
||||
|
||||
/* Try to get data from environment. */
|
||||
if (server->method == GLIBTOP_METHOD_INET) {
|
||||
int connect_type;
|
||||
|
||||
fprintf (stderr, "Connecting to '%s' port %d.\n",
|
||||
server->server_host, server->server_port);
|
||||
|
||||
temp = getenv ("LIBGTOP_SERVER") ?
|
||||
getenv ("LIBGTOP_SERVER") : GTOP_SERVER;
|
||||
connect_type = glibtop_make_connection
|
||||
(server->server_host, server->server_port,
|
||||
&server->socket);
|
||||
|
||||
server_command = glibtop_malloc_r (server, strlen (temp) + 1);
|
||||
|
||||
strcpy (server_command, temp);
|
||||
|
||||
temp = getenv ("LIBGTOP_RSH") ?
|
||||
getenv ("LIBGTOP_RSH") : "rsh";
|
||||
|
||||
server_rsh = glibtop_malloc_r (server, strlen (temp) + 1);
|
||||
|
||||
strcpy (server_rsh, temp);
|
||||
|
||||
/* Extract host and user information. */
|
||||
|
||||
temp = strstr (server_command, ":");
|
||||
|
||||
if (temp) {
|
||||
*temp = 0;
|
||||
server_host = server_command;
|
||||
server_command = temp+1;
|
||||
|
||||
temp = strstr (server_host, "@");
|
||||
|
||||
if (temp) {
|
||||
*temp = 0;
|
||||
server_user = server_host;
|
||||
server_host = temp+1;
|
||||
} else {
|
||||
server_user = NULL;
|
||||
}
|
||||
} else {
|
||||
server_host = NULL;
|
||||
server_user = NULL;
|
||||
}
|
||||
|
||||
/* Store everything in `server'. */
|
||||
|
||||
server->server_command = server_command;
|
||||
server->server_host = server_host;
|
||||
server->server_user = server_user;
|
||||
server->server_rsh = server_rsh;
|
||||
}
|
||||
|
||||
/* Get server features. */
|
||||
|
||||
if (server->server_host == NULL) {
|
||||
server->features = glibtop_server_features;
|
||||
|
||||
if (server->features == 0)
|
||||
return;
|
||||
server->features = -1;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* Fork and exec server. */
|
||||
/* If the server has been started, ask it for its features. */
|
||||
|
||||
if (pipe (server->input) || pipe (server->output))
|
||||
glibtop_error_r (server, _("cannot make a pipe: %s\n"),
|
||||
strerror (errno));
|
||||
|
||||
server->pid = fork ();
|
||||
|
||||
if (server->pid < 0) {
|
||||
glibtop_error_r (server, _("%s: fork failed: %s\n"),
|
||||
strerror (errno));
|
||||
} else if (server->pid == 0) {
|
||||
close (0); close (1); /* close (2); */
|
||||
close (server->input [0]); close (server->output [1]);
|
||||
dup2 (server->input [1], 1); /* dup2 (server->input [1], 2); */
|
||||
dup2 (server->output [0], 0);
|
||||
|
||||
if (server_host) {
|
||||
if (server_user) {
|
||||
execl (server->server_rsh, "-l",
|
||||
server->server_user, server->server_host,
|
||||
server->server_command, NULL);
|
||||
} else {
|
||||
execl (server->server_rsh,
|
||||
server->server_host, server_command, NULL);
|
||||
}
|
||||
} else {
|
||||
execl (server->server_command, NULL);
|
||||
}
|
||||
|
||||
_exit (2);
|
||||
if (server->flags & _GLIBTOP_INIT_STATE_SERVER) {
|
||||
glibtop_sysdeps sysdeps;
|
||||
|
||||
glibtop_call_l (server, GLIBTOP_CMND_SYSDEPS, 0, NULL,
|
||||
sizeof (glibtop_sysdeps), &sysdeps);
|
||||
|
||||
server->features = sysdeps.features;
|
||||
}
|
||||
|
||||
fprintf (stderr, "PID: %d\n", server->pid);
|
||||
|
||||
close (server->input [1]);
|
||||
close (server->output [0]);
|
||||
|
||||
sprintf (version, "%s server %s ready.\n", PACKAGE, VERSION);
|
||||
|
||||
glibtop_read_l (server, strlen (version), buffer);
|
||||
|
||||
if (memcmp (version, buffer, strlen (version)))
|
||||
glibtop_error_r (server, _("server version is not %s"), VERSION);
|
||||
|
||||
fprintf (stderr, "Calling GLITOP_CMND_SYSDEPS ...\n");
|
||||
|
||||
glibtop_call_l (server, GLIBTOP_CMND_SYSDEPS, 0, NULL,
|
||||
sizeof (glibtop_sysdeps), &sysdeps);
|
||||
|
||||
server->features = sysdeps.features;
|
||||
|
||||
fprintf (stderr, "Features: %lu\n", server->features);
|
||||
}
|
||||
|
62
lib/parameter.c
Normal file
62
lib/parameter.c
Normal file
@@ -0,0 +1,62 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the Gnome Top Library.
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
The Gnome Top Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The Gnome Top Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/parameter.h>
|
||||
|
||||
#define _write_data(ptr,size) \
|
||||
if ((data_ptr == NULL) || (data_size < size)) return -size; \
|
||||
if (ptr == NULL) { strcpy (data_ptr, ""); return 1; } \
|
||||
memcpy (data_ptr, ptr, size); \
|
||||
return size;
|
||||
|
||||
#define _strlen(ptr) (ptr ? strlen (ptr) : 0)
|
||||
|
||||
size_t
|
||||
glibtop_get_parameter_l (glibtop *server, const unsigned parameter,
|
||||
void *data_ptr, size_t data_size)
|
||||
{
|
||||
switch (parameter) {
|
||||
case GLIBTOP_PARAM_METHOD:
|
||||
_write_data (&server->method,
|
||||
sizeof (server->method));
|
||||
case GLIBTOP_PARAM_FEATURES:
|
||||
_write_data (&server->features,
|
||||
sizeof (server->features));
|
||||
case GLIBTOP_PARAM_COMMAND:
|
||||
_write_data (server->server_command,
|
||||
_strlen(server->server_command));
|
||||
case GLIBTOP_PARAM_HOST:
|
||||
_write_data (server->server_host,
|
||||
_strlen(server->server_host));
|
||||
case GLIBTOP_PARAM_PORT:
|
||||
_write_data (&server->server_port,
|
||||
sizeof (server->server_port));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
glibtop_set_parameter_l (glibtop *server, const unsigned parameter,
|
||||
const void *data_ptr, size_t data_size)
|
||||
{
|
||||
}
|
49
lib/read.c
49
lib/read.c
@@ -23,19 +23,48 @@
|
||||
|
||||
/* Reads some data from server. */
|
||||
|
||||
static void
|
||||
do_read (int s, void *ptr, size_t total_size)
|
||||
{
|
||||
int nread;
|
||||
size_t already_read = 0, remaining = total_size;
|
||||
|
||||
while (already_read < total_size) {
|
||||
nread = recv (s, ptr, remaining, 0);
|
||||
|
||||
if (nread == 0) {
|
||||
close (s);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (nread <= 0) {
|
||||
glibtop_error_io ("recv");
|
||||
return;
|
||||
}
|
||||
|
||||
already_read += nread;
|
||||
remaining -= nread;
|
||||
(char *) ptr += nread;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
glibtop_read_l (glibtop *server, size_t size, void *buf)
|
||||
{
|
||||
size_t ssize;
|
||||
int ret = 0;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
if (read (server->input [0], &ssize, sizeof (size_t)) < 0)
|
||||
glibtop_error_r (server, _("read size: %s"), strerror (errno));
|
||||
|
||||
if (size != ssize)
|
||||
glibtop_error_r (server, _("got %d bytes but requested %d"), ssize, size);
|
||||
|
||||
if (read (server->input [0], buf, size) < 0)
|
||||
glibtop_error_r (server, _("read %d bytes: %s"), size, strerror (errno));
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "LIBRARY: really reading %d bytes.\n", size);
|
||||
#endif
|
||||
|
||||
if (server->socket) {
|
||||
do_read (server->socket, buf, size);
|
||||
} else {
|
||||
ret = read (server->input [0], buf, size);
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
glibtop_error_io_r (server, _("read %d bytes"), size);
|
||||
}
|
||||
|
@@ -29,20 +29,39 @@ glibtop_read_data_l (glibtop *server)
|
||||
{
|
||||
size_t size;
|
||||
void *ptr;
|
||||
int ret;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
if (read (server->input [0], &size, sizeof (size_t)) < 0)
|
||||
glibtop_error_r (server, _("read data size: %s"),
|
||||
strerror (errno));
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "LIBRARY: reading %d data bytes.\n", sizeof (size_t));
|
||||
#endif
|
||||
|
||||
if (server->socket) {
|
||||
ret = recv (server->socket, &size, sizeof (size_t), 0);
|
||||
} else {
|
||||
ret = read (server->input [0], &size, sizeof (size_t));
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
glibtop_error_io_r (server, _("read data size"));
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "LIBRARY: really reading %d data bytes (ret = %d).\n", size, ret);
|
||||
#endif
|
||||
|
||||
if (!size) return NULL;
|
||||
|
||||
ptr = glibtop_malloc_r (server, size);
|
||||
|
||||
if (read (server->input [0], ptr, size) < 0)
|
||||
glibtop_error_r (server, _("read data %d bytes: %s"),
|
||||
size, strerror (errno));
|
||||
if (server->socket) {
|
||||
ret = recv (server->socket, ptr, size, 0);
|
||||
} else {
|
||||
ret = read (server->input [0], ptr, size);
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
glibtop_error_io_r (server, _("read data %d bytes"));
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
21
lib/write.c
21
lib/write.c
@@ -26,13 +26,22 @@
|
||||
void
|
||||
glibtop_write_l (glibtop *server, size_t size, void *buf)
|
||||
{
|
||||
int ret;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
if (write (server->output [1], &size, sizeof (size_t)) < 0)
|
||||
glibtop_error_r (server, _("write size: %s"), strerror (errno));
|
||||
if (size == 0) return;
|
||||
|
||||
if (!size) return;
|
||||
|
||||
if (write (server->output [1], buf, size) < 0)
|
||||
glibtop_error_r (server, _("write %d bytes: %s"), size, strerror (errno));
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "LIBRARY: really writing %d bytes.\n", size);
|
||||
#endif
|
||||
|
||||
if (server->socket) {
|
||||
ret = send (server->socket, buf, size, 0);
|
||||
} else {
|
||||
ret = write (server->output [1], buf, size);
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
glibtop_error_io_r (server, _("write %d bytes"), size);
|
||||
}
|
||||
|
1
perl/.cvsignore
Normal file
1
perl/.cvsignore
Normal file
@@ -0,0 +1 @@
|
||||
Libgtop.xs Makefile blib pm_to_blib Libgtop.c Libgtop.bs Makefile.PL
|
5
perl/Changes
Normal file
5
perl/Changes
Normal file
@@ -0,0 +1,5 @@
|
||||
Revision history for Perl extension Libgtop.
|
||||
|
||||
0.01 Sun Jun 21 21:00:59 1998
|
||||
- original version; created by h2xs 1.18
|
||||
|
26
perl/Libgtop.pm
Normal file
26
perl/Libgtop.pm
Normal file
@@ -0,0 +1,26 @@
|
||||
package Libgtop;
|
||||
|
||||
use strict;
|
||||
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
|
||||
|
||||
require Exporter;
|
||||
require DynaLoader;
|
||||
require AutoLoader;
|
||||
|
||||
@ISA = qw(Exporter DynaLoader);
|
||||
# Items to export into callers namespace by default. Note: do not export
|
||||
# names by default without a very good reason. Use EXPORT_OK instead.
|
||||
# Do not simply export all your public functions/methods/constants.
|
||||
@EXPORT = qw(
|
||||
|
||||
);
|
||||
$VERSION = '0.01';
|
||||
|
||||
bootstrap Libgtop $VERSION;
|
||||
|
||||
# Preloaded methods go here.
|
||||
|
||||
# Autoload methods go after __END__, and are processed by the autosplit program.
|
||||
|
||||
1;
|
||||
__END__
|
8
perl/MANIFEST
Normal file
8
perl/MANIFEST
Normal file
@@ -0,0 +1,8 @@
|
||||
.cvsignore
|
||||
Changes
|
||||
Libgtop.pm
|
||||
MANIFEST
|
||||
Makefile.PL.in
|
||||
new.pl
|
||||
perl.awk
|
||||
test.pl
|
10
perl/Makefile.PL.in
Normal file
10
perl/Makefile.PL.in
Normal file
@@ -0,0 +1,10 @@
|
||||
# -*-cperl-*-
|
||||
use ExtUtils::MakeMaker;
|
||||
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
|
||||
# the contents of the Makefile that is written.
|
||||
WriteMakefile('NAME' => 'Libgtop',
|
||||
'VERSION_FROM' => 'Libgtop.pm',
|
||||
'LIBS' => ['@LIBGTOP_GUILE_LIBS@'],
|
||||
'DEFINE' => '',
|
||||
'INC' => '@LIBGTOP_GUILE_INCS@',
|
||||
);
|
13
perl/new.pl
Executable file
13
perl/new.pl
Executable file
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/perl -w
|
||||
|
||||
require 5.004;
|
||||
|
||||
use blib;
|
||||
use strict;
|
||||
use Libgtop;
|
||||
|
||||
print "CPU Usage: ".join (':', Libgtop::cpu)."\n";
|
||||
print "Memory Usage: ".join (':', Libgtop::mem)."\n";
|
||||
print "Swap Usage: ".join (':', Libgtop::swap)."\n";
|
||||
|
||||
|
86
perl/perl.awk
Normal file
86
perl/perl.awk
Normal file
@@ -0,0 +1,86 @@
|
||||
BEGIN {
|
||||
print "/* Libgtop.xs */";
|
||||
print "/* This is a generated file. Please modify `perl.awk' */";
|
||||
print "";
|
||||
|
||||
print "#ifdef __cplusplus";
|
||||
print "extern \"C\" {";
|
||||
print "#endif";
|
||||
print "#include \"EXTERN.h\"";
|
||||
print "#include \"perl.h\"";
|
||||
print "#include \"XSUB.h\"";
|
||||
print "#ifdef __cplusplus";
|
||||
print "}";
|
||||
print "#endif";
|
||||
print "";
|
||||
print "#undef PACKAGE";
|
||||
print "";
|
||||
print "#include <glibtop.h>";
|
||||
print "#include <glibtop/union.h>";
|
||||
print "";
|
||||
print "MODULE = Libgtop\t\tPACKAGE = Libgtop";
|
||||
print "";
|
||||
|
||||
convert["long"] = "newSViv";
|
||||
convert["ulong"] = "newSViv";
|
||||
convert["double"] = "newSVnv";
|
||||
}
|
||||
|
||||
/^(\w+)/ {
|
||||
feature = $1;
|
||||
|
||||
print "void";
|
||||
if (feature ~ /^proc_/) {
|
||||
print feature"(pid)";
|
||||
print "\tunsigned\tpid;";
|
||||
} else {
|
||||
print feature"()";
|
||||
}
|
||||
|
||||
print "PREINIT:";
|
||||
print "\tglibtop_"feature" "feature";";
|
||||
|
||||
if (feature ~ /^proclist/) {
|
||||
print "\tunsigned i, *ptr;";
|
||||
print "PPCODE:";
|
||||
print "\tptr = glibtop_get_proclist (&proclist);";
|
||||
print "";
|
||||
print "\tif (ptr) {";
|
||||
print "\t\tfor (i = 0; i < proclist.number; i++)";
|
||||
print "\t\t\tXPUSHs (sv_2mortal (newSViv (ptr [i])));";
|
||||
print "\t}";
|
||||
print "";
|
||||
print "\tglibtop_free (ptr);";
|
||||
} else {
|
||||
print "PPCODE:";
|
||||
if (feature ~ /^proc_/) {
|
||||
print "\tglibtop_get_"feature" (&"feature", pid);";
|
||||
} else {
|
||||
print "\tglibtop_get_"feature" (&"feature");";
|
||||
}
|
||||
print "";
|
||||
|
||||
nr_elements = split ($2, elements, /:/);
|
||||
for (element = 1; element <= nr_elements; element++) {
|
||||
list = elements[element];
|
||||
type = elements[element];
|
||||
sub(/\(.*/, "", type);
|
||||
sub(/^\w+\(/, "", list); sub(/\)$/, "", list);
|
||||
count = split (list, fields, /,/);
|
||||
for (field = 1; field <= count; field++) {
|
||||
if (type ~ /^str$/) {
|
||||
print "\tXPUSHs (sv_2mortal (newSVpv ("$1"."fields[field]", 0)));";
|
||||
} else {
|
||||
if (type ~ /^char$/) {
|
||||
print "\tXPUSHs (sv_2mortal (newSVpv (&"$1"."fields[field]", 1)));";
|
||||
} else {
|
||||
print "\tXPUSHs (sv_2mortal ("convert[type]" ("$1"."fields[field]")));";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
print "";
|
||||
}
|
||||
|
20
perl/test.pl
Normal file
20
perl/test.pl
Normal file
@@ -0,0 +1,20 @@
|
||||
# Before `make install' is performed this script should be runnable with
|
||||
# `make test'. After `make install' it should work as `perl test.pl'
|
||||
|
||||
######################### We start with some black magic to print on failure.
|
||||
|
||||
# Change 1..1 below to 1..last_test_to_print .
|
||||
# (It may become useful if the test is moved to ./t subdirectory.)
|
||||
|
||||
BEGIN { $| = 1; print "1..1\n"; }
|
||||
END {print "not ok 1\n" unless $loaded;}
|
||||
use Libgtop;
|
||||
$loaded = 1;
|
||||
print "ok 1\n";
|
||||
|
||||
######################### End of black magic.
|
||||
|
||||
# Insert your test code below (better if it prints "ok 13"
|
||||
# (correspondingly "not ok 13") depending on the success of chunk 13
|
||||
# of the test code):
|
||||
|
124
po/fr.po
124
po/fr.po
@@ -6,7 +6,7 @@
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: libgtop VERSION\n"
|
||||
"POT-Creation-Date: 1998-05-31 22:31+0200\n"
|
||||
"POT-Creation-Date: 1998-06-20 15:28+0200\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: Vincent Renardias <vincent@waw.com>\n"
|
||||
"Language-Team: Vincent Renardias <vincent@waw.com>\n"
|
||||
@@ -17,67 +17,67 @@ msgstr ""
|
||||
#: lib/open.c:36
|
||||
#, c-format
|
||||
msgid "cannot make a pipe: %s\n"
|
||||
msgstr ""
|
||||
msgstr "impossible de cr<63><72>r un tube: %s\n"
|
||||
|
||||
#: lib/open.c:41
|
||||
#, c-format
|
||||
msgid "%s: fork failed: %s\n"
|
||||
msgstr ""
|
||||
msgstr "%s: duplication <20>chou<6F>e: %s\n"
|
||||
|
||||
#: lib/open.c:59
|
||||
#, c-format
|
||||
msgid "server version is not %s"
|
||||
msgstr ""
|
||||
msgstr "la version du serveur n'est pas %s"
|
||||
|
||||
#: lib/read.c:34
|
||||
#, c-format
|
||||
msgid "read size: %s"
|
||||
msgstr ""
|
||||
msgstr "taille lue: %s"
|
||||
|
||||
#: lib/read.c:37
|
||||
#, c-format
|
||||
msgid "got %d bytes but requested %d"
|
||||
msgstr ""
|
||||
msgstr "obtenu %d octets, mais %d <20>taient demand<6E>s"
|
||||
|
||||
#: lib/read.c:40
|
||||
#, c-format
|
||||
msgid "read %d bytes: %s"
|
||||
msgstr ""
|
||||
msgstr "lecture de %d octets: %s"
|
||||
|
||||
#: lib/write.c:32
|
||||
#, c-format
|
||||
msgid "write size: %s"
|
||||
msgstr ""
|
||||
msgstr "taille <20>crite: %s"
|
||||
|
||||
#: lib/write.c:37
|
||||
#, c-format
|
||||
msgid "write %d bytes: %s"
|
||||
msgstr ""
|
||||
msgstr "<EFBFBD>crit %d octets: %s"
|
||||
|
||||
#: lib/read_data.c:36
|
||||
#, c-format
|
||||
msgid "read data size: %s"
|
||||
msgstr ""
|
||||
msgstr "taille de la lecture: %s"
|
||||
|
||||
#: lib/read_data.c:46
|
||||
#, c-format
|
||||
msgid "read data %d bytes: %s"
|
||||
msgstr ""
|
||||
msgstr "lecture de %d octets de donn<6E>es: %s"
|
||||
|
||||
#: sysdeps/common/xmalloc.c:32
|
||||
#, c-format
|
||||
msgid "malloc %d bytes: %s"
|
||||
msgstr ""
|
||||
msgstr "malloc de %d octets: %s"
|
||||
|
||||
#: sysdeps/common/xmalloc.c:44
|
||||
#, c-format
|
||||
msgid "calloc %d block (%d bytes each): %s"
|
||||
msgstr ""
|
||||
msgstr "calloc de %d blocks (%d octets chacuns): %s"
|
||||
|
||||
#: sysdeps/common/xmalloc.c:56
|
||||
#, c-format
|
||||
msgid "realloc %d bytes: %s"
|
||||
msgstr ""
|
||||
msgstr "realloc de %d octets: %s"
|
||||
|
||||
#: sysdeps/names/sysdeps.c:42 sysdeps/names/sysdeps.c:62
|
||||
msgid "CPU Usage"
|
||||
@@ -93,7 +93,7 @@ msgstr "Utilisation du Swap"
|
||||
|
||||
#: sysdeps/names/sysdeps.c:45 sysdeps/names/sysdeps.c:65
|
||||
msgid "System Uptime"
|
||||
msgstr ""
|
||||
msgstr "Uptime du syst<73>me"
|
||||
|
||||
#: sysdeps/names/sysdeps.c:46 sysdeps/names/sysdeps.c:66
|
||||
msgid "Load Averange"
|
||||
@@ -117,31 +117,31 @@ msgstr "Liste des taches en cours d'
|
||||
|
||||
#: sysdeps/names/sysdeps.c:51 sysdeps/names/sysdeps.c:71
|
||||
msgid "Process Status information"
|
||||
msgstr ""
|
||||
msgstr "Information sur l'<27>tat du processus"
|
||||
|
||||
#: sysdeps/names/sysdeps.c:52 sysdeps/names/sysdeps.c:72
|
||||
msgid "Process UID and TTY information"
|
||||
msgstr ""
|
||||
msgstr "Information UID et TTY du processus"
|
||||
|
||||
#: sysdeps/names/sysdeps.c:53 sysdeps/names/sysdeps.c:73
|
||||
msgid "Process Memory information"
|
||||
msgstr ""
|
||||
msgstr "Information M<>moire du Processus"
|
||||
|
||||
#: sysdeps/names/sysdeps.c:54 sysdeps/names/sysdeps.c:74
|
||||
msgid "Process Time information"
|
||||
msgstr ""
|
||||
msgstr "Information Temporelle sur le processus"
|
||||
|
||||
#: sysdeps/names/sysdeps.c:55 sysdeps/names/sysdeps.c:75
|
||||
msgid "Process Signal information"
|
||||
msgstr ""
|
||||
msgstr "Information sur les signaux du processus"
|
||||
|
||||
#: sysdeps/names/sysdeps.c:56 sysdeps/names/sysdeps.c:76
|
||||
msgid "Process Kernel Data information"
|
||||
msgstr ""
|
||||
msgstr "Information sur les donn<6E>es noyau du processus"
|
||||
|
||||
#: sysdeps/names/sysdeps.c:57 sysdeps/names/sysdeps.c:77
|
||||
msgid "Process Segment information"
|
||||
msgstr ""
|
||||
msgstr "Information sur la segmentation du processus"
|
||||
|
||||
#: sysdeps/names/cpu.c:37
|
||||
msgid "Total CPU Time"
|
||||
@@ -153,7 +153,7 @@ msgstr "Temps CPU en mode utilisateur"
|
||||
|
||||
#: sysdeps/names/cpu.c:39
|
||||
msgid "CPU Time in User Mode (nice)"
|
||||
msgstr ""
|
||||
msgstr "Temps CPU en mode utilisateur (nice)"
|
||||
|
||||
#: sysdeps/names/cpu.c:40
|
||||
msgid "CPU Time in System Mode"
|
||||
@@ -165,7 +165,7 @@ msgstr "Temps CPU pour la tache inactive"
|
||||
|
||||
#: sysdeps/names/cpu.c:42
|
||||
msgid "Tick Frequency"
|
||||
msgstr ""
|
||||
msgstr "Fr<EFBFBD>quence des ticks"
|
||||
|
||||
#: sysdeps/names/cpu.c:47
|
||||
msgid "The number of jiffies (1/100ths of a second) since system boot"
|
||||
@@ -175,31 +175,31 @@ msgstr "Nombre de jiffies (1/100e de seconde) depuis le boot du syst
|
||||
msgid ""
|
||||
"The number of jiffies (1/100ths of a second) that the system spent in user "
|
||||
"mode"
|
||||
msgstr ""
|
||||
msgstr "Le nombre de jiffies (1/100<30>me de seconde) que le systme a pass<73> en mode utilisateur"
|
||||
|
||||
#: sysdeps/names/cpu.c:51
|
||||
msgid ""
|
||||
"The number of jiffies (1/100ths of a second) that the system spent in user "
|
||||
"mode with low priority (nice)"
|
||||
msgstr ""
|
||||
msgstr "Le nombre de jiffies (1/100<30>me de seconde) que le syst<73>me a pass<73> en mode utilisateur en priorit<69> basse (nice)"
|
||||
|
||||
#: sysdeps/names/cpu.c:53
|
||||
msgid ""
|
||||
"The number of jiffies (1/100ths of a second) that the system spent in system "
|
||||
"mode"
|
||||
msgstr ""
|
||||
msgstr "Le nombre de jiffies (1/100<30>me de seconde) que le syst<73>me a pass<73> en mode syst<73>me"
|
||||
|
||||
#: sysdeps/names/cpu.c:55
|
||||
msgid ""
|
||||
"The number of jiffies (1/100ths of a second) that the system spend in the "
|
||||
"idle task"
|
||||
msgstr ""
|
||||
msgstr "Le nombre de jiffies (1/100<30>me de seconde) que le systme a pass<73> dans le processus inactif (idle task)"
|
||||
|
||||
#: sysdeps/names/cpu.c:57
|
||||
msgid ""
|
||||
"All of the above values are in jiffies (1/100ths of a second) unless "
|
||||
"otherwise stated in this field (i.e. 'frequency != 100')"
|
||||
msgstr ""
|
||||
msgstr "Toutes les valeurs ci-dessus sont exprim<69>es en jiffies (1/100<30>me de seconde) sauf pr<70>cision contraire (i.e.: fr<66>quence != 100)"
|
||||
|
||||
#: sysdeps/names/loadavg.c:36
|
||||
msgid "Load Average"
|
||||
@@ -207,7 +207,7 @@ msgstr "Charge Moyenne"
|
||||
|
||||
#: sysdeps/names/loadavg.c:41
|
||||
msgid "Number of jobs running simultaneously averaged over 1, 5 and 15 minutes"
|
||||
msgstr ""
|
||||
msgstr "Nombre de processus tournant simultannement en moyenne sur 1, 5 et 15 minutes"
|
||||
|
||||
#: sysdeps/names/mem.c:39
|
||||
msgid "Total Memory"
|
||||
@@ -231,7 +231,7 @@ msgstr "Tampons"
|
||||
|
||||
#: sysdeps/names/mem.c:44
|
||||
msgid "Cached"
|
||||
msgstr ""
|
||||
msgstr "Dans le cache"
|
||||
|
||||
#: sysdeps/names/mem.c:45
|
||||
msgid "User"
|
||||
@@ -247,83 +247,83 @@ msgstr "M
|
||||
|
||||
#: sysdeps/names/mem.c:52
|
||||
msgid "Used memory size in kB"
|
||||
msgstr ""
|
||||
msgstr "M<EFBFBD>moire utilis<69>e en Ko"
|
||||
|
||||
#: sysdeps/names/mem.c:53
|
||||
msgid "Free memory size in kB"
|
||||
msgstr ""
|
||||
msgstr "M<EFBFBD>moire libre en Ko"
|
||||
|
||||
#: sysdeps/names/mem.c:54
|
||||
msgid "Shared memory size in kB"
|
||||
msgstr ""
|
||||
msgstr "M<EFBFBD>moire partag<61>e en Ko"
|
||||
|
||||
#: sysdeps/names/mem.c:55
|
||||
msgid "Size of buffers kB"
|
||||
msgstr ""
|
||||
msgstr "Taille des tampons en Ko"
|
||||
|
||||
#: sysdeps/names/mem.c:56
|
||||
msgid "Size of cached memory in kB"
|
||||
msgstr ""
|
||||
msgstr "Taille de la m<>moire dans le cache en Ko"
|
||||
|
||||
#: sysdeps/names/mem.c:57
|
||||
msgid "Memory used from user processes in kB"
|
||||
msgstr ""
|
||||
msgstr "M<EFBFBD>moire utilis<69>e par les processus utilisateurs en Ko"
|
||||
|
||||
#: sysdeps/names/mem.c:58
|
||||
msgid "Memory in locked pages in kB"
|
||||
msgstr ""
|
||||
msgstr "M<EFBFBD>moire dans les pages v<>rouill<6C>es en Ko"
|
||||
|
||||
#: sysdeps/names/swap.c:36 sysdeps/names/swap.c:43
|
||||
msgid "Total Swap Space"
|
||||
msgstr ""
|
||||
msgstr "Taille totalle de la zone d'<27>change"
|
||||
|
||||
#: sysdeps/names/swap.c:37 sysdeps/names/swap.c:44
|
||||
msgid "Used Swap Space"
|
||||
msgstr ""
|
||||
msgstr "Taille utilis<69>e de la zone d'<27>change"
|
||||
|
||||
#: sysdeps/names/swap.c:38 sysdeps/names/swap.c:45
|
||||
msgid "Free Swap Space"
|
||||
msgstr ""
|
||||
msgstr "Espace libre de la zone d'<27>change"
|
||||
|
||||
#: sysdeps/names/uptime.c:36
|
||||
msgid "Uptime"
|
||||
msgstr ""
|
||||
msgstr "Uptime"
|
||||
|
||||
#: sysdeps/names/uptime.c:37
|
||||
msgid "Idletime"
|
||||
msgstr ""
|
||||
msgstr "Idletime"
|
||||
|
||||
#: sysdeps/names/uptime.c:42
|
||||
msgid "Time in seconds since system boot"
|
||||
msgstr ""
|
||||
msgstr "Temps en secondes depuis le d<>marrage du syst<73>me"
|
||||
|
||||
#: sysdeps/names/uptime.c:43
|
||||
msgid "Time in seconds the system spent in the idle task since system boot"
|
||||
msgstr ""
|
||||
msgstr "Temps en secondes pass<73> dans le processus inactif depuis le d<>marrage du syst<73>me"
|
||||
|
||||
#: sysdeps/names/shm_limits.c:37 sysdeps/names/shm_limits.c:46
|
||||
msgid "Max segment size"
|
||||
msgstr ""
|
||||
msgstr "Taille maximum des segments"
|
||||
|
||||
#: sysdeps/names/shm_limits.c:38 sysdeps/names/shm_limits.c:47
|
||||
msgid "Min segment size"
|
||||
msgstr ""
|
||||
msgstr "Taille minimum des segments"
|
||||
|
||||
#: sysdeps/names/shm_limits.c:39 sysdeps/names/shm_limits.c:48
|
||||
msgid "Max number of segments"
|
||||
msgstr ""
|
||||
msgstr "Nombre maximum des segments"
|
||||
|
||||
#: sysdeps/names/shm_limits.c:40 sysdeps/names/shm_limits.c:49
|
||||
msgid "Max shared segments per process"
|
||||
msgstr ""
|
||||
msgstr "Nombre maximum de segments partag<61>s par processus"
|
||||
|
||||
#: sysdeps/names/shm_limits.c:41 sysdeps/names/shm_limits.c:50
|
||||
msgid "Max total shared memory"
|
||||
msgstr ""
|
||||
msgstr "Taille totalle de la m<>moire partag<61>e"
|
||||
|
||||
#: sysdeps/names/msg_limits.c:37 sysdeps/names/msg_limits.c:48
|
||||
msgid "Size in kilobytes of message pool"
|
||||
msgstr ""
|
||||
msgstr "Taille en kilo-octets du pool de messages"
|
||||
|
||||
#: sysdeps/names/msg_limits.c:38 sysdeps/names/msg_limits.c:49
|
||||
msgid "Number of entries in message map"
|
||||
@@ -331,23 +331,23 @@ msgstr ""
|
||||
|
||||
#: sysdeps/names/msg_limits.c:39 sysdeps/names/msg_limits.c:50
|
||||
msgid "Max size of message"
|
||||
msgstr ""
|
||||
msgstr "Taille maximum des messages"
|
||||
|
||||
#: sysdeps/names/msg_limits.c:40 sysdeps/names/msg_limits.c:51
|
||||
msgid "Default max size of queue"
|
||||
msgstr ""
|
||||
msgstr "Taille maximum par d<>faut de la queue"
|
||||
|
||||
#: sysdeps/names/msg_limits.c:41 sysdeps/names/msg_limits.c:52
|
||||
msgid "Max queues system wide"
|
||||
msgstr ""
|
||||
msgstr "Nombre maximum de queues dans le syst<73>me"
|
||||
|
||||
#: sysdeps/names/msg_limits.c:42 sysdeps/names/msg_limits.c:53
|
||||
msgid "Message segment size"
|
||||
msgstr ""
|
||||
msgstr "Taille des segments de messages"
|
||||
|
||||
#: sysdeps/names/msg_limits.c:43 sysdeps/names/msg_limits.c:54
|
||||
msgid "Number of system message headers"
|
||||
msgstr ""
|
||||
msgstr "Nombre d'entetes de messages syst<73>me"
|
||||
|
||||
#: sysdeps/names/sem_limits.c:39 sysdeps/names/sem_limits.c:53
|
||||
msgid "Number of entries in semaphore map"
|
||||
@@ -355,19 +355,19 @@ msgstr ""
|
||||
|
||||
#: sysdeps/names/sem_limits.c:40 sysdeps/names/sem_limits.c:54
|
||||
msgid "Max number of arrays"
|
||||
msgstr ""
|
||||
msgstr "Nombre maximum de tables"
|
||||
|
||||
#: sysdeps/names/sem_limits.c:41 sysdeps/names/sem_limits.c:55
|
||||
msgid "Max semaphores system wide"
|
||||
msgstr ""
|
||||
msgstr "Nombre maximum de s<>maphores dans le syst<73>me"
|
||||
|
||||
#: sysdeps/names/sem_limits.c:42 sysdeps/names/sem_limits.c:56
|
||||
msgid "Number of undo structures system wide"
|
||||
msgstr ""
|
||||
msgstr "Nombre de structures 'undo' dans le syst<73>me"
|
||||
|
||||
#: sysdeps/names/sem_limits.c:43 sysdeps/names/sem_limits.c:57
|
||||
msgid "Max semaphores per array"
|
||||
msgstr ""
|
||||
msgstr "Nombre maximum de s<>maphores par table"
|
||||
|
||||
#: sysdeps/names/sem_limits.c:44 sysdeps/names/sem_limits.c:58
|
||||
msgid "Max ops per semop call"
|
||||
@@ -379,11 +379,11 @@ msgstr ""
|
||||
|
||||
#: sysdeps/names/sem_limits.c:46 sysdeps/names/sem_limits.c:60
|
||||
msgid "sizeof struct sem_undo"
|
||||
msgstr ""
|
||||
msgstr "sizeof struct sem_undo"
|
||||
|
||||
#: sysdeps/names/sem_limits.c:47 sysdeps/names/sem_limits.c:61
|
||||
msgid "Semaphore max value"
|
||||
msgstr ""
|
||||
msgstr "Valeur maximum d'un s<>maphore"
|
||||
|
||||
#: sysdeps/names/sem_limits.c:48 sysdeps/names/sem_limits.c:62
|
||||
msgid "Adjust on exit max value"
|
||||
|
@@ -1 +1 @@
|
||||
SUBDIRS = server proxy
|
||||
SUBDIRS = server proxy daemon
|
||||
|
3
src/daemon/.cvsignore
Normal file
3
src/daemon/.cvsignore
Normal file
@@ -0,0 +1,3 @@
|
||||
Makefile.in
|
||||
Makefile
|
||||
gnuserv
|
25
src/daemon/Makefile.am
Normal file
25
src/daemon/Makefile.am
Normal file
@@ -0,0 +1,25 @@
|
||||
LINK = $(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -o $@
|
||||
|
||||
INCLUDES = -I$(top_builddir) -I$(top_srcdir) @machine_incs@ \
|
||||
-I$(top_srcdir)/include -I$(top_srcdir)/intl @GUILE_INCS@ \
|
||||
-DGTOPLOCALEDIR=\"$(datadir)/locale\" -D_GNU_SOURCE
|
||||
|
||||
CFLAGS = -Wall -W @CFLAGS@ -DGTOP_SERVER=\""@LIBGTOP_SERVER@"\" -DDEBUG -DREAL_DEBUG
|
||||
|
||||
bin_PROGRAMS = gnuserv
|
||||
|
||||
EXTRA_PROGRAMS = gtop_daemon
|
||||
|
||||
gnuserv_SOURCES = gnuserv.c main.c
|
||||
gnuserv_LDADD = $(top_builddir)/lib/libgtop.la \
|
||||
$(top_builddir)/sysdeps/common/libgtop_common.la \
|
||||
$(top_builddir)/sysdeps/@sysdeps_dir@/libgtop_sysdeps.la \
|
||||
@INTLLIBS@ @LIBSUPPORT@ @X_LIBS@ -lXau
|
||||
gnuserv_LDFLAGS = -static
|
||||
|
||||
gtop_daemon_SOURCES = main.c inet.c loop.c output.c version.c
|
||||
gtop_daemon_LDADD = $(top_builddir)/lib/libgtop.la \
|
||||
$(top_builddir)/sysdeps/common/libgtop_common.la \
|
||||
$(top_builddir)/sysdeps/@sysdeps_dir@/libgtop_sysdeps.la \
|
||||
@INTLLIBS@ @LIBSUPPORT@
|
||||
gtop_daemon_LDFLAGS = -static
|
@@ -1,620 +0,0 @@
|
||||
/* -*-C-*-
|
||||
Client code to allow local and remote editing of files by XEmacs.
|
||||
Copyright (C) 1989 Free Software Foundation, Inc.
|
||||
Copyright (C) 1995 Sun Microsystems, Inc.
|
||||
Copyright (C) 1997 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of XEmacs.
|
||||
|
||||
XEmacs is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2, or (at your option) any
|
||||
later version.
|
||||
|
||||
XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with XEmacs; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
|
||||
Author: Andy Norman (ange@hplb.hpl.hp.com), based on
|
||||
'etc/emacsclient.c' from the GNU Emacs 18.52 distribution.
|
||||
|
||||
Please mail bugs and suggestions to the author at the above address.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file incorporates new features added by Bob Weiner <weiner@mot.com>,
|
||||
* Darrell Kindred <dkindred@cmu.edu> and Arup Mukherjee <arup@cmu.edu>.
|
||||
* GNUATTACH support added by Ben Wing <wing@xemacs.org>.
|
||||
* Please see the note at the end of the README file for details.
|
||||
*
|
||||
* (If gnuserv came bundled with your emacs, the README file is probably
|
||||
* ../etc/gnuserv.README relative to the directory containing this file)
|
||||
*/
|
||||
|
||||
#if 0
|
||||
/* Hand-munged RCS header */
|
||||
static char rcsid [] = "!Header: gnuclient.c,v 2.2 95/12/12 01:39:21 wing nene !";
|
||||
#endif
|
||||
|
||||
#include "gnuserv.h"
|
||||
#include "getopt.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif /* HAVE_STRING_H */
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif /* HAVE_UNISTD_H */
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#if !defined(SYSV_IPC) && !defined(UNIX_DOMAIN_SOCKETS) && \
|
||||
!defined(INTERNET_DOMAIN_SOCKETS)
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
fprintf (stderr, "Sorry, the Emacs server is only "
|
||||
"supported on systems that have\n");
|
||||
fprintf (stderr, "Unix Domain sockets, Internet Domain "
|
||||
"sockets or System V IPC.\n");
|
||||
exit (1);
|
||||
} /* main */
|
||||
#else /* SYSV_IPC || UNIX_DOMAIN_SOCKETS || INTERNET_DOMAIN_SOCKETS */
|
||||
|
||||
static char cwd[MAXPATHLEN+2]; /* current working directory when calculated */
|
||||
static char *cp = NULL; /* ptr into valid bit of cwd above */
|
||||
|
||||
static pid_t emacs_pid; /* Process id for emacs process */
|
||||
|
||||
void initialize_signals (void);
|
||||
|
||||
static void
|
||||
tell_emacs_to_resume (int sig)
|
||||
{
|
||||
char buffer[GSERV_BUFSZ+1];
|
||||
int s; /* socket / msqid to server */
|
||||
int connect_type; /* CONN_UNIX, CONN_INTERNET, or
|
||||
ONN_IPC */
|
||||
|
||||
/* Why is SYSV so retarded? */
|
||||
/* We want emacs to realize that we are resuming */
|
||||
signal(SIGCONT, tell_emacs_to_resume);
|
||||
|
||||
connect_type = make_connection (NULL, (u_short) 0, &s);
|
||||
|
||||
sprintf(buffer,"(gnuserv-eval '(resume-pid-console %d))", (int)getpid());
|
||||
send_string(s, buffer);
|
||||
|
||||
#ifdef SYSV_IPC
|
||||
if (connect_type == (int) CONN_IPC)
|
||||
disconnect_from_ipc_server (s, msgp, FALSE);
|
||||
#else /* !SYSV_IPC */
|
||||
if (connect_type != (int) CONN_IPC)
|
||||
disconnect_from_server (s, FALSE);
|
||||
#endif /* !SYSV_IPC */
|
||||
}
|
||||
|
||||
static void
|
||||
pass_signal_to_emacs (int sig)
|
||||
{
|
||||
if (kill (emacs_pid, sig) == -1)
|
||||
{
|
||||
fprintf (stderr, "gnuattach: Could not pass signal to emacs process\n");
|
||||
exit (1);
|
||||
}
|
||||
initialize_signals ();
|
||||
}
|
||||
|
||||
void
|
||||
initialize_signals ()
|
||||
{
|
||||
/* Set up signal handler to pass relevant signals to emacs process.
|
||||
We used to send SIGSEGV, SIGBUS, SIGPIPE, SIGILL and others to
|
||||
Emacs, but I think it's better not to. I can see no reason why
|
||||
Emacs should SIGSEGV whenever gnuclient SIGSEGV-s, etc. */
|
||||
signal (SIGHUP, pass_signal_to_emacs);
|
||||
signal (SIGQUIT, pass_signal_to_emacs);
|
||||
signal (SIGINT, pass_signal_to_emacs);
|
||||
#ifdef SIGWINCH
|
||||
signal (SIGWINCH, pass_signal_to_emacs);
|
||||
#endif
|
||||
|
||||
/* We want emacs to realize that we are resuming */
|
||||
signal (SIGCONT, tell_emacs_to_resume);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
get_current_working_directory -- return the cwd.
|
||||
*/
|
||||
static char *
|
||||
get_current_working_directory (void)
|
||||
{
|
||||
if (cp == NULL)
|
||||
{ /* haven't calculated it yet */
|
||||
#ifdef BSD
|
||||
if (getwd (cwd) == 0)
|
||||
#else /* !BSD */
|
||||
if (getcwd (cwd,MAXPATHLEN) == NULL)
|
||||
#endif /* !BSD */
|
||||
{
|
||||
perror (progname);
|
||||
fprintf (stderr, "%s: unable to get current working directory\n",
|
||||
progname);
|
||||
exit (1);
|
||||
} /* if */
|
||||
|
||||
/* on some systems, cwd can look like '@machine/' ... */
|
||||
/* ignore everything before the first '/' */
|
||||
for (cp = cwd; *cp && *cp != '/'; ++cp)
|
||||
;
|
||||
|
||||
} /* if */
|
||||
|
||||
return cp;
|
||||
|
||||
} /* get_current_working_directory */
|
||||
|
||||
|
||||
/*
|
||||
filename_expand -- try to convert the given filename into a fully-qualified
|
||||
pathname.
|
||||
*/
|
||||
static void
|
||||
filename_expand (char *fullpath, char *filename)
|
||||
/* fullpath - returned full pathname */
|
||||
/* filename - filename to expand */
|
||||
{
|
||||
int len;
|
||||
|
||||
fullpath[0] = '\0';
|
||||
|
||||
if (filename[0] && filename[0] != '/')
|
||||
{ /* relative filename */
|
||||
strcat (fullpath, get_current_working_directory ());
|
||||
len = strlen (fullpath);
|
||||
|
||||
if (len > 0 && fullpath[len-1] == '/') /* trailing slash already? */
|
||||
; /* yep */
|
||||
else
|
||||
strcat (fullpath, "/"); /* nope, append trailing slash */
|
||||
} /* if */
|
||||
|
||||
strcat (fullpath,filename);
|
||||
|
||||
} /* filename_expand */
|
||||
|
||||
/* Encase the string in quotes, escape all the backslashes and quotes
|
||||
in string. */
|
||||
static char *
|
||||
clean_string (const char *s)
|
||||
{
|
||||
int i = 0;
|
||||
char *p, *res;
|
||||
|
||||
for (p = s; *p; p++, i++)
|
||||
{
|
||||
if (*p == '\\' || *p == '\"')
|
||||
++i;
|
||||
else if (*p == '\004')
|
||||
i += 3;
|
||||
}
|
||||
p = res = (char *)malloc (i + 2 + 1);
|
||||
*p++ = '\"';
|
||||
for (; *s; p++, s++)
|
||||
{
|
||||
switch (*s)
|
||||
{
|
||||
case '\\':
|
||||
*p++ = '\\';
|
||||
*p = '\\';
|
||||
break;
|
||||
case '\"':
|
||||
*p++ = '\\';
|
||||
*p = '\"';
|
||||
break;
|
||||
case '\004':
|
||||
*p++ = '\\';
|
||||
*p++ = 'C';
|
||||
*p++ = '-';
|
||||
*p = 'd';
|
||||
break;
|
||||
default:
|
||||
*p = *s;
|
||||
}
|
||||
}
|
||||
*p++ = '\"';
|
||||
*p = '\0';
|
||||
return res;
|
||||
}
|
||||
|
||||
#define GET_ARGUMENT(var, desc) do { \
|
||||
if (*(p + 1)) (var) = p + 1; \
|
||||
else \
|
||||
{ \
|
||||
if (!argv[++i]) \
|
||||
{ \
|
||||
fprintf (stderr, "%s: `%s' must be followed by an argument\n", \
|
||||
progname, desc); \
|
||||
exit (1); \
|
||||
} \
|
||||
(var) = argv[i]; \
|
||||
} \
|
||||
over = 1; \
|
||||
} while (0)
|
||||
|
||||
/* A strdup immitation. */
|
||||
static char *
|
||||
my_strdup (const char *s)
|
||||
{
|
||||
char *new = malloc (strlen (s) + 1);
|
||||
if (new)
|
||||
strcpy (new, s);
|
||||
return new;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
int starting_line = 1; /* line to start editing at */
|
||||
char command[MAXPATHLEN+50]; /* emacs command buffer */
|
||||
char fullpath[MAXPATHLEN+1]; /* full pathname to file */
|
||||
char *eval_form = NULL; /* form to evaluate with `-eval' */
|
||||
char *eval_function = NULL; /* function to evaluate with `-f' */
|
||||
char *load_library = NULL; /* library to load */
|
||||
int quick = 0; /* quick edit, don't wait for user to
|
||||
finish */
|
||||
int batch = 0; /* batch mode */
|
||||
int view = 0; /* view only. */
|
||||
int nofiles = 0;
|
||||
int errflg = 0; /* option error */
|
||||
int s; /* socket / msqid to server */
|
||||
int connect_type; /* CONN_UNIX, CONN_INTERNET, or
|
||||
* CONN_IPC */
|
||||
int suppress_windows_system = 0;
|
||||
char *display = NULL;
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
char *hostarg = NULL; /* remote hostname */
|
||||
char *remotearg;
|
||||
char thishost[HOSTNAMSZ]; /* this hostname */
|
||||
char remotepath[MAXPATHLEN+1]; /* remote pathname */
|
||||
char *path;
|
||||
int rflg = 0; /* pathname given on cmdline */
|
||||
char *portarg;
|
||||
u_short port = 0; /* port to server */
|
||||
#endif /* INTERNET_DOMAIN_SOCKETS */
|
||||
#ifdef SYSV_IPC
|
||||
struct msgbuf *msgp; /* message */
|
||||
#endif /* SYSV_IPC */
|
||||
char *tty = NULL;
|
||||
char buffer[GSERV_BUFSZ + 1]; /* buffer to read pid */
|
||||
char result[GSERV_BUFSZ + 1];
|
||||
int i;
|
||||
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
memset (remotepath, 0, sizeof (remotepath));
|
||||
#endif /* INTERNET_DOMAIN_SOCKETS */
|
||||
|
||||
progname = strrchr (argv[0], '/');
|
||||
if (progname)
|
||||
++progname;
|
||||
else
|
||||
progname = argv[0];
|
||||
|
||||
display = getenv ("DISPLAY");
|
||||
if (!display)
|
||||
suppress_windows_system = 1;
|
||||
else
|
||||
display = my_strdup (display);
|
||||
|
||||
for (i = 1; argv[i] && !errflg; i++)
|
||||
{
|
||||
if (*argv[i] != '-')
|
||||
break;
|
||||
else if (*argv[i] == '-'
|
||||
&& (*(argv[i] + 1) == '\0'
|
||||
|| (*(argv[i] + 1) == '-' && *(argv[i] + 2) == '\0')))
|
||||
{
|
||||
/* `-' or `--' */
|
||||
++i;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!strcmp (argv[i], "-batch") || !strcmp (argv[i], "--batch"))
|
||||
batch = 1;
|
||||
else if (!strcmp (argv[i], "-eval") || !strcmp (argv[i], "--eval"))
|
||||
{
|
||||
if (!argv[++i])
|
||||
{
|
||||
fprintf (stderr, "%s: `-eval' must be followed by an argument\n",
|
||||
progname);
|
||||
exit (1);
|
||||
}
|
||||
eval_form = argv[i];
|
||||
}
|
||||
else if (!strcmp (argv[i], "-display") || !strcmp (argv[i], "--display"))
|
||||
{
|
||||
suppress_windows_system = 0;
|
||||
if (!argv[++i])
|
||||
{
|
||||
fprintf (stderr,
|
||||
"%s: `-display' must be followed by an argument\n",
|
||||
progname);
|
||||
exit (1);
|
||||
}
|
||||
if (display)
|
||||
free (display);
|
||||
/* no need to strdup. */
|
||||
display = argv[i];
|
||||
}
|
||||
else if (!strcmp (argv[i], "-nw"))
|
||||
suppress_windows_system = 1;
|
||||
else
|
||||
{
|
||||
/* Iterate over one-letter options. */
|
||||
char *p;
|
||||
int over = 0;
|
||||
for (p = argv[i] + 1; *p && !over; p++)
|
||||
{
|
||||
switch (*p)
|
||||
{
|
||||
case 'q':
|
||||
quick = 1;
|
||||
break;
|
||||
case 'v':
|
||||
view = 1;
|
||||
break;
|
||||
case 'f':
|
||||
GET_ARGUMENT (eval_function, "-f");
|
||||
break;
|
||||
case 'l':
|
||||
GET_ARGUMENT (load_library, "-l");
|
||||
break;
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
case 'h':
|
||||
GET_ARGUMENT (hostarg, "-h");
|
||||
break;
|
||||
case 'p':
|
||||
GET_ARGUMENT (portarg, "-p");
|
||||
port = atoi (portarg);
|
||||
break;
|
||||
case 'r':
|
||||
GET_ARGUMENT (remotearg, "-r");
|
||||
strcpy (remotepath, remotearg);
|
||||
rflg = 1;
|
||||
break;
|
||||
#endif /* INTERNET_DOMAIN_SOCKETS */
|
||||
default:
|
||||
errflg = 1;
|
||||
}
|
||||
} /* for */
|
||||
} /* else */
|
||||
} /* for */
|
||||
|
||||
if (errflg)
|
||||
{
|
||||
fprintf (stderr,
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
"usage: %s [-nw] [-display display] [-q] [-v] [-l library]\n"
|
||||
" [-batch] [-f function] [-eval form]\n"
|
||||
" [-h host] [-p port] [-r remote-path] [[+line] file] ...\n",
|
||||
#else /* !INTERNET_DOMAIN_SOCKETS */
|
||||
"usage: %s [-nw] [-q] [-v] [-l library] [-f function] [-eval form] "
|
||||
"[[+line] path] ...\n",
|
||||
#endif /* !INTERNET_DOMAIN_SOCKETS */
|
||||
progname);
|
||||
exit (1);
|
||||
}
|
||||
if (batch && argv[i])
|
||||
{
|
||||
fprintf (stderr, "%s: Cannot specify `-batch' with file names\n",
|
||||
progname);
|
||||
exit (1);
|
||||
}
|
||||
if (suppress_windows_system && hostarg)
|
||||
{
|
||||
fprintf (stderr, "%s: Remote editing is available only on X\n",
|
||||
progname);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
*result = '\0';
|
||||
if (eval_function || eval_form || load_library)
|
||||
{
|
||||
#if defined(INTERNET_DOMAIN_SOCKETS)
|
||||
connect_type = make_connection (hostarg, port, &s);
|
||||
#else
|
||||
connect_type = make_connection (NULL, (u_short) 0, &s);
|
||||
#endif
|
||||
sprintf (command, "(gnuserv-eval%s '(progn ", quick ? "-quickly" : "");
|
||||
send_string (s, command);
|
||||
if (load_library)
|
||||
{
|
||||
sprintf (command, " (load-library %s)", clean_string (load_library));
|
||||
send_string (s, command);
|
||||
}
|
||||
if (eval_form)
|
||||
{
|
||||
sprintf (command, " %s", eval_form);
|
||||
send_string (s, command);
|
||||
}
|
||||
if (eval_function)
|
||||
{
|
||||
sprintf (command, " (%s)", eval_function);
|
||||
send_string (s, command);
|
||||
}
|
||||
send_string (s, "))");
|
||||
send_string (s, EOT_STR);
|
||||
if (read_line (s, result) == 0)
|
||||
{
|
||||
fprintf (stderr, "%s: Could not read\n", progname);
|
||||
exit (1);
|
||||
}
|
||||
} /* eval_function || eval_form || load_library */
|
||||
else if (batch)
|
||||
{
|
||||
fprintf (stderr, "%s: `-batch' requires an evaluation\n",
|
||||
progname);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if (!batch)
|
||||
{
|
||||
if (suppress_windows_system)
|
||||
{
|
||||
tty = ttyname (0);
|
||||
if (!tty)
|
||||
{
|
||||
fprintf (stderr, "%s: Not connected to a tty", progname);
|
||||
exit (1);
|
||||
}
|
||||
#if defined(INTERNET_DOMAIN_SOCKETS)
|
||||
connect_type = make_connection (hostarg, port, &s);
|
||||
#else
|
||||
connect_type = make_connection (NULL, (u_short) 0, &s);
|
||||
#endif
|
||||
send_string (s, "(gnuserv-eval '(emacs-pid))");
|
||||
send_string (s, EOT_STR);
|
||||
|
||||
if (read_line (s, buffer) == 0)
|
||||
{
|
||||
fprintf (stderr, "%s: Could not establish Emacs procces id\n",
|
||||
progname);
|
||||
exit (1);
|
||||
}
|
||||
/* Don't do disconnect_from_server becasue we have already read
|
||||
data, and disconnect doesn't do anything else. */
|
||||
#ifndef INTERNET_DOMAIN_SOCKETS
|
||||
if (connect_type == (int) CONN_IPC)
|
||||
disconnect_from_ipc_server (s, msgp, FALSE);
|
||||
#endif /* !SYSV_IPC */
|
||||
|
||||
emacs_pid = (pid_t)atol(buffer);
|
||||
initialize_signals();
|
||||
} /* suppress_windows_system */
|
||||
|
||||
#if defined(INTERNET_DOMAIN_SOCKETS)
|
||||
connect_type = make_connection (hostarg, port, &s);
|
||||
#else
|
||||
connect_type = make_connection (NULL, (u_short) 0, &s);
|
||||
#endif
|
||||
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
if (connect_type == (int) CONN_INTERNET)
|
||||
{
|
||||
char *ptr;
|
||||
gethostname (thishost, HOSTNAMSZ);
|
||||
if (!rflg)
|
||||
{ /* attempt to generate a path
|
||||
* to this machine */
|
||||
if ((ptr = getenv ("GNU_NODE")) != NULL)
|
||||
/* user specified a path */
|
||||
strcpy (remotepath, ptr);
|
||||
}
|
||||
#if 0 /* This is really bogus... re-enable it if you must have it! */
|
||||
#if defined (hp9000s300) || defined (hp9000s800)
|
||||
else if (strcmp (thishost,hostarg))
|
||||
{ /* try /net/thishost */
|
||||
strcpy (remotepath, "/net/"); /* (this fails using internet
|
||||
addresses) */
|
||||
strcat (remotepath, thishost);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{ /* same machines, no need for path */
|
||||
remotepath[0] = '\0'; /* default is the empty path */
|
||||
}
|
||||
#endif /* INTERNET_DOMAIN_SOCKETS */
|
||||
|
||||
#ifdef SYSV_IPC
|
||||
if ((msgp = (struct msgbuf *)
|
||||
malloc (sizeof *msgp + GSERV_BUFSZ)) == NULL)
|
||||
{
|
||||
fprintf (stderr, "%s: not enough memory for message buffer\n", progname);
|
||||
exit (1);
|
||||
} /* if */
|
||||
|
||||
msgp->mtext[0] = '\0'; /* ready for later strcats */
|
||||
#endif /* SYSV_IPC */
|
||||
|
||||
if (suppress_windows_system)
|
||||
{
|
||||
char *term = getenv ("TERM");
|
||||
if (!term)
|
||||
{
|
||||
fprintf (stderr, "%s: unknown terminal type\n", progname);
|
||||
exit (1);
|
||||
}
|
||||
sprintf (command, "(gnuserv-edit-files '(tty %s %s %d) '(",
|
||||
clean_string (tty), clean_string (term), (int)getpid ());
|
||||
}
|
||||
else /* !suppress_windows_system */
|
||||
{
|
||||
sprintf (command, "(gnuserv-edit-files '(x %s) '(",
|
||||
clean_string (display));
|
||||
} /* !suppress_windows_system */
|
||||
send_string (s, command);
|
||||
|
||||
if (!argv[i])
|
||||
nofiles = 1;
|
||||
|
||||
for (; argv[i]; i++)
|
||||
{
|
||||
if (i < argc - 1 && *argv[i] == '+')
|
||||
starting_line = atoi (argv[i++]);
|
||||
else
|
||||
starting_line = 1;
|
||||
/* If the last argument is +something, treat it as a file. */
|
||||
if (i == argc)
|
||||
{
|
||||
starting_line = 1;
|
||||
--i;
|
||||
}
|
||||
filename_expand (fullpath, argv[i]);
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
path = malloc (strlen (remotepath) + strlen (fullpath) + 1);
|
||||
sprintf (path, "%s%s", remotepath, fullpath);
|
||||
#else
|
||||
path = my_strdup (fullpath);
|
||||
#endif
|
||||
sprintf (command, "(%d . %s)", starting_line, clean_string (path));
|
||||
send_string (s, command);
|
||||
free (path);
|
||||
} /* for */
|
||||
|
||||
sprintf (command, ")%s%s",
|
||||
(quick || (nofiles && !suppress_windows_system)) ? " 'quick" : "",
|
||||
view ? " 'view" : "");
|
||||
send_string (s, command);
|
||||
send_string (s, ")");
|
||||
|
||||
#ifdef SYSV_IPC
|
||||
if (connect_type == (int) CONN_IPC)
|
||||
disconnect_from_ipc_server (s, msgp, FALSE);
|
||||
#else /* !SYSV_IPC */
|
||||
if (connect_type != (int) CONN_IPC)
|
||||
disconnect_from_server (s, FALSE);
|
||||
#endif /* !SYSV_IPC */
|
||||
} /* not batch */
|
||||
|
||||
if (batch && !quick)
|
||||
printf ("%s\n", result);
|
||||
|
||||
return 0;
|
||||
|
||||
} /* main */
|
||||
|
||||
#endif /* SYSV_IPC || UNIX_DOMAIN_SOCKETS || INTERNET_DOMAIN_SOCKETS */
|
@@ -33,27 +33,18 @@
|
||||
static char rcsid [] = "!Header: gnuserv.c,v 2.1 95/02/16 11:58:27 arup alpha !";
|
||||
#endif
|
||||
|
||||
#include "gnuserv.h"
|
||||
#define DEBUG
|
||||
|
||||
#include <glibtop/gnuserv.h>
|
||||
#include <glibtop/open.h>
|
||||
|
||||
#ifdef AIX
|
||||
#include <sys/select.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
extern void handle_socket_connection __P((glibtop *, int));
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif /* HAVE_UNISTD_H */
|
||||
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif /* HAVE_STRING_H */
|
||||
|
||||
#if !defined(SYSV_IPC) && !defined(UNIX_DOMAIN_SOCKETS) && \
|
||||
!defined(INTERNET_DOMAIN_SOCKETS)
|
||||
#if !defined(SYSV_IPC) && !defined(UNIX_DOMAIN_SOCKETS) && !defined(INTERNET_DOMAIN_SOCKETS)
|
||||
main ()
|
||||
{
|
||||
fprintf (stderr,"Sorry, the Emacs server is only supported on systems that have\n");
|
||||
@@ -79,7 +70,7 @@ ipc_exit (int stat)
|
||||
|
||||
if (ipc_wpid != 0)
|
||||
kill (ipc_wpid, SIGKILL);
|
||||
|
||||
|
||||
exit (stat);
|
||||
} /* ipc_exit */
|
||||
|
||||
@@ -104,9 +95,9 @@ ipc_spawn_watchdog (void)
|
||||
if ((ipc_wpid = fork ()) == 0)
|
||||
{ /* child process */
|
||||
int ppid = getppid (); /* parent's process id */
|
||||
|
||||
|
||||
setpgrp(); /* gnu kills process group on exit */
|
||||
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (kill (ppid, 0) < 0) /* ppid is no longer valid, parent
|
||||
@@ -114,11 +105,11 @@ ipc_spawn_watchdog (void)
|
||||
{
|
||||
ipc_exit (0);
|
||||
} /* if */
|
||||
|
||||
|
||||
sleep(10); /* have another go later */
|
||||
} /* while */
|
||||
} /* if */
|
||||
|
||||
|
||||
} /* ipc_spawn_watchdog */
|
||||
|
||||
|
||||
@@ -131,16 +122,12 @@ ipc_init (struct msgbuf **msgpp)
|
||||
key_t key; /* messge key */
|
||||
char buf[GSERV_BUFSZ]; /* pathname for key */
|
||||
|
||||
sprintf (buf,"/tmp/gsrv%d",(int)geteuid ());
|
||||
sprintf (buf,"/tmp/lgtd%d",(int)geteuid ());
|
||||
creat (buf,0600);
|
||||
key = ftok (buf,1);
|
||||
|
||||
if ((ipc_qid = msgget (key,0600|IPC_CREAT)) == -1)
|
||||
{
|
||||
perror (progname);
|
||||
fprintf (stderr, "%s: unable to create msg queue\n", progname);
|
||||
ipc_exit (1);
|
||||
} /* if */
|
||||
glibtop_error_io ("unable to create msg queue");
|
||||
|
||||
ipc_spawn_watchdog ();
|
||||
|
||||
@@ -150,8 +137,7 @@ ipc_init (struct msgbuf **msgpp)
|
||||
if ((*msgpp = (struct msgbuf *)
|
||||
malloc (sizeof **msgpp + GSERV_BUFSZ)) == NULL)
|
||||
{
|
||||
fprintf (stderr,
|
||||
"%s: unable to allocate space for message buffer\n", progname);
|
||||
glibtop_warn_io ("unable to allocate space for message buffer");
|
||||
ipc_exit(1);
|
||||
} /* if */
|
||||
} /* ipc_init */
|
||||
@@ -174,8 +160,7 @@ handle_ipc_request (struct msgbuf *msgp)
|
||||
|
||||
if ((len = msgrcv (ipc_qid, msgp, GSERV_BUFSZ - 1, 1, 0)) < 0)
|
||||
{
|
||||
perror (progname);
|
||||
fprintf (stderr, "%s: unable to receive\n", progname);
|
||||
glibtop_warn_io ("msgrcv");
|
||||
ipc_exit (1);
|
||||
} /* if */
|
||||
|
||||
@@ -192,8 +177,7 @@ handle_ipc_request (struct msgbuf *msgp)
|
||||
#if 0
|
||||
if ((len = read(0,buf,GSERV_BUFSZ-1)) < 0)
|
||||
{
|
||||
perror (progname);
|
||||
fprintf (stderr, "%s: unable to read\n", progname);
|
||||
glibtop_warn_io ("read");
|
||||
ipc_exit (1);
|
||||
} /* if */
|
||||
|
||||
@@ -210,11 +194,7 @@ handle_ipc_request (struct msgbuf *msgp)
|
||||
}
|
||||
|
||||
if (len < 0)
|
||||
{
|
||||
perror (progname);
|
||||
fprintf (stderr, "%s: unable to read\n", progname);
|
||||
exit(1);
|
||||
}
|
||||
glibtop_error_io ("read");
|
||||
|
||||
/* parse the response from emacs, getting client fd & result length */
|
||||
buf[offset] = '\0';
|
||||
@@ -223,11 +203,7 @@ handle_ipc_request (struct msgbuf *msgp)
|
||||
while (result_len > 0)
|
||||
{
|
||||
if ((len = read(0, buf, min2 (result_len, GSERV_BUFSZ - 1))) < 0)
|
||||
{
|
||||
perror (progname);
|
||||
fprintf (stderr, "%s: unable to read\n", progname);
|
||||
exit (1);
|
||||
}
|
||||
glibtop_error_io ("read");
|
||||
|
||||
/* Send this string off, but only if we have enough space */
|
||||
|
||||
@@ -249,23 +225,17 @@ handle_ipc_request (struct msgbuf *msgp)
|
||||
while ((len = read (0,buf,1)) == 0)
|
||||
;
|
||||
if (len < 0)
|
||||
{
|
||||
perror(progname);
|
||||
fprintf (stderr,"%s: unable to read\n", progname);
|
||||
exit (1);
|
||||
}
|
||||
glibtop_error_io ("read");
|
||||
|
||||
if (buf[0] != '\n')
|
||||
{
|
||||
fprintf (stderr,"%s: garbage after result [%c]\n", progname, buf[0]);
|
||||
exit (1);
|
||||
}
|
||||
glibtop_error ("garbage after result [%c]", buf[0]);
|
||||
#endif
|
||||
|
||||
/* Send a response back to the client. */
|
||||
|
||||
msgp->mtype = msg_st.msg_lspid;
|
||||
if (msgsnd (ipc_qid,msgp,strlen(msgp->mtext)+1,0) < 0)
|
||||
perror ("msgsend(gnuserv)");
|
||||
glibtop_warn_io ("msgsend(gnuserv)");
|
||||
|
||||
} /* handle_ipc_request */
|
||||
#endif /* SYSV_IPC */
|
||||
@@ -296,11 +266,8 @@ echo_request (int s)
|
||||
|
||||
} /* while */
|
||||
|
||||
if (len < 0) {
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to recv\n",progname);
|
||||
exit(1);
|
||||
} /* if */
|
||||
if (len < 0)
|
||||
glibtop_error_io ("recv");
|
||||
|
||||
} /* echo_request */
|
||||
|
||||
@@ -312,6 +279,7 @@ echo_request (int s)
|
||||
static void
|
||||
handle_response (void)
|
||||
{
|
||||
#if 0
|
||||
char buf[GSERV_BUFSZ+1];
|
||||
int offset=0;
|
||||
int s;
|
||||
@@ -325,22 +293,17 @@ handle_response (void)
|
||||
offset += len;
|
||||
}
|
||||
|
||||
if (len < 0) {
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to read\n",progname);
|
||||
exit(1);
|
||||
}
|
||||
if (len < 0)
|
||||
glibtop_error_io ("read");
|
||||
|
||||
/* parse the response from emacs, getting client fd & result length */
|
||||
buf[offset] = '\0';
|
||||
sscanf(buf,"%d/%d", &s, &result_len);
|
||||
|
||||
while (result_len > 0) {
|
||||
if ((len = read(0,buf,min2(result_len,GSERV_BUFSZ))) < 0) {
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to read\n",progname);
|
||||
exit(1);
|
||||
}
|
||||
if ((len = read(0,buf,min2(result_len,GSERV_BUFSZ))) < 0)
|
||||
glibtop_error_io ("read");
|
||||
|
||||
buf[len] = '\0';
|
||||
send_string(s,buf);
|
||||
result_len -= len;
|
||||
@@ -350,20 +313,18 @@ handle_response (void)
|
||||
while ((len = read(0,buf,1)) == 0)
|
||||
;
|
||||
if (len < 0)
|
||||
{
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to read\n",progname);
|
||||
exit(1);
|
||||
}
|
||||
glibtop_error_io ("read");
|
||||
|
||||
if (buf[0] != '\n')
|
||||
{
|
||||
fprintf(stderr,"%s: garbage after result\n",progname);
|
||||
exit(1);
|
||||
}
|
||||
glibtop_error ("garbage after result");
|
||||
|
||||
/* send the newline */
|
||||
buf[1] = '\0';
|
||||
send_string(s,buf);
|
||||
close(s);
|
||||
#else
|
||||
glibtop_error ("handle_response (): Function not implemented");
|
||||
#endif
|
||||
|
||||
} /* handle_response */
|
||||
#endif /* INTERNET_DOMAIN_SOCKETS || UNIX_DOMAIN_SOCKETS */
|
||||
@@ -412,18 +373,18 @@ timed_read (int fd, char *buf, int max, int timeout, int one_line)
|
||||
}
|
||||
else
|
||||
{
|
||||
printf ("read error on socket\004\n");
|
||||
glibtop_warn_io ("read error on socket");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (r == 0)
|
||||
{
|
||||
printf ("read timed out\004\n");
|
||||
glibtop_warn ("read timed out");
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf ("error in select\004\n");
|
||||
glibtop_warn_io ("error in select");
|
||||
return -1;
|
||||
}
|
||||
} while ((nbytes < max) && !(one_line && (c == '\n')));
|
||||
@@ -461,39 +422,41 @@ permitted (u_long host_addr, int fd)
|
||||
if (timed_read(fd, auth_protocol, AUTH_NAMESZ, AUTH_TIMEOUT, 1) <= 0)
|
||||
return FALSE;
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "Client sent authenticatin protocol '%s'\n", auth_protocol);
|
||||
#endif
|
||||
|
||||
if (strcmp (auth_protocol, DEFAUTH_NAME) &&
|
||||
strcmp (auth_protocol, MCOOKIE_NAME))
|
||||
{
|
||||
printf ("authentication protocol (%s) from client is invalid...\n",
|
||||
auth_protocol);
|
||||
printf ("... Was the client an old version of gnuclient/gnudoit?\004\n");
|
||||
|
||||
glibtop_warn ("Authentication protocol from client is invalid", auth_protocol);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!strcmp(auth_protocol, MCOOKIE_NAME))
|
||||
if (!strcmp (auth_protocol, MCOOKIE_NAME))
|
||||
{
|
||||
|
||||
/*
|
||||
* doing magic cookie auth
|
||||
*/
|
||||
|
||||
if (timed_read(fd, buf, 10, AUTH_TIMEOUT, 1) <= 0)
|
||||
if (timed_read (fd, buf, 10, AUTH_TIMEOUT, 1) <= 0)
|
||||
return FALSE;
|
||||
|
||||
auth_data_len = atoi(buf);
|
||||
auth_data_len = atoi (buf);
|
||||
|
||||
if (timed_read(fd, buf, auth_data_len, AUTH_TIMEOUT, 0) != auth_data_len)
|
||||
if (timed_read (fd, buf, auth_data_len, AUTH_TIMEOUT, 0) != auth_data_len)
|
||||
return FALSE;
|
||||
|
||||
#ifdef AUTH_MAGIC_COOKIE
|
||||
if (server_xauth && server_xauth->data &&
|
||||
!memcmp(buf, server_xauth->data, auth_data_len))
|
||||
!memcmp (buf, server_xauth->data, auth_data_len))
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
#else
|
||||
printf ("client tried Xauth, but server is not compiled with Xauth\n");
|
||||
glibtop_warn ("client tried Xauth, but server is not compiled with Xauth");
|
||||
#endif
|
||||
|
||||
/*
|
||||
@@ -501,8 +464,8 @@ permitted (u_long host_addr, int fd)
|
||||
* protocol....
|
||||
*/
|
||||
|
||||
printf ("Xauth authentication failed, trying GNU_SECURE auth...\004\n");
|
||||
|
||||
glibtop_warn ("Xauth authentication failed, trying GNU_SECURE auth...");
|
||||
|
||||
}
|
||||
|
||||
/* Other auth protocols go here, and should execute only if the
|
||||
@@ -516,11 +479,19 @@ permitted (u_long host_addr, int fd)
|
||||
|
||||
/* First find the hash key */
|
||||
key = HASH(host_addr) % TABLE_SIZE;
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "Doing GNU_SECURE auth ...\n");
|
||||
#endif
|
||||
|
||||
/* Now check the chain for that hash key */
|
||||
for(entry=permitted_hosts[key]; entry != NULL; entry=entry->next)
|
||||
for(entry = permitted_hosts [key]; entry != NULL; entry = entry->next) {
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "Trying %ld\n", entry->host_addr);
|
||||
#endif
|
||||
if (host_addr == entry->host_addr)
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
return(FALSE);
|
||||
|
||||
@@ -537,13 +508,10 @@ add_host (u_long host_addr)
|
||||
int key;
|
||||
struct entry *new_entry;
|
||||
|
||||
if (!permitted(host_addr, -1))
|
||||
if (!permitted (host_addr, -1))
|
||||
{
|
||||
if ((new_entry = (struct entry *) malloc(sizeof(struct entry))) == NULL) {
|
||||
fprintf(stderr,"%s: unable to malloc space for permitted host entry\n",
|
||||
progname);
|
||||
exit(1);
|
||||
} /* if */
|
||||
if ((new_entry = (struct entry *) malloc(sizeof(struct entry))) == NULL)
|
||||
glibtop_error_io ("unable to malloc space for permitted host entry");
|
||||
|
||||
new_entry->host_addr = host_addr;
|
||||
key = HASH(host_addr) % TABLE_SIZE;
|
||||
@@ -572,17 +540,13 @@ setup_table (void)
|
||||
int i, hosts=0;
|
||||
|
||||
/* Make sure every entry is null */
|
||||
for (i=0; i<TABLE_SIZE; i++)
|
||||
permitted_hosts[i] = NULL;
|
||||
for (i = 0; i < TABLE_SIZE; i++)
|
||||
permitted_hosts [i] = NULL;
|
||||
|
||||
gethostname(hostname,HOSTNAMSZ);
|
||||
gethostname (hostname, HOSTNAMSZ);
|
||||
|
||||
if ((host_addr = internet_addr(hostname)) == -1)
|
||||
{
|
||||
fprintf(stderr,"%s: unable to find %s in /etc/hosts or from YP",
|
||||
progname,hostname);
|
||||
exit(1);
|
||||
} /* if */
|
||||
if (((long) host_addr = glibtop_internet_addr (hostname)) == -1)
|
||||
glibtop_error ("unable to find %s in /etc/hosts or from YP", hostname);
|
||||
|
||||
#ifdef AUTH_MAGIC_COOKIE
|
||||
|
||||
@@ -596,19 +560,20 @@ setup_table (void)
|
||||
|
||||
|
||||
#if 0 /* Don't even want to allow access from the local host by default */
|
||||
add_host(host_addr); /* add local host */
|
||||
add_host (host_addr); /* add local host */
|
||||
hosts++;
|
||||
#endif
|
||||
|
||||
if (((file_name = getenv("GNU_SECURE")) != NULL && /* security file */
|
||||
(host_file = fopen(file_name,"r")) != NULL)) /* opened ok */
|
||||
if (((file_name = getenv ("GNU_SECURE")) != NULL && /* security file */
|
||||
(host_file = fopen (file_name, "r")) != NULL)) /* opened ok */
|
||||
{
|
||||
while ((fscanf(host_file,"%s",hostname) != EOF)) /* find a host */
|
||||
if ((host_addr = internet_addr(hostname)) != -1)/* get its addr */
|
||||
while ((fscanf (host_file, "%s", hostname) != EOF)) /* find a host */
|
||||
if (((long) host_addr = glibtop_internet_addr (hostname)) != -1)/* get its addr */
|
||||
{
|
||||
add_host(host_addr); /* add the addr */
|
||||
add_host (host_addr); /* add the addr */
|
||||
hosts++;
|
||||
}
|
||||
fclose(host_file);
|
||||
fclose (host_file);
|
||||
} /* if */
|
||||
|
||||
return hosts;
|
||||
@@ -631,7 +596,7 @@ internet_init (void)
|
||||
return -1;
|
||||
|
||||
/* clear out address structure */
|
||||
memset((char *)&server,0,sizeof(struct sockaddr_in));
|
||||
memset((char *)&server, 0, sizeof (struct sockaddr_in));
|
||||
|
||||
/* Set up address structure for the listen socket. */
|
||||
server.sin_family = AF_INET;
|
||||
@@ -640,38 +605,26 @@ internet_init (void)
|
||||
/* Find the information for the gnu server
|
||||
* in order to get the needed port number.
|
||||
*/
|
||||
if ((ptr=getenv("GNU_PORT")) != NULL)
|
||||
server.sin_port = htons(atoi(ptr));
|
||||
if ((ptr = getenv ("GNU_PORT")) != NULL)
|
||||
server.sin_port = htons (atoi (ptr));
|
||||
else if ((sp = getservbyname ("gnuserv", "tcp")) == NULL)
|
||||
server.sin_port = htons(DEFAULT_PORT+getuid());
|
||||
server.sin_port = htons (DEFAULT_PORT+getuid());
|
||||
else
|
||||
server.sin_port = sp->s_port;
|
||||
|
||||
/* Create the listen socket. */
|
||||
if ((ls = socket (AF_INET,SOCK_STREAM, 0)) == -1)
|
||||
{
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to create socket\n",progname);
|
||||
exit(1);
|
||||
} /* if */
|
||||
glibtop_error_io ("unable to create socket");
|
||||
|
||||
/* Bind the listen address to the socket. */
|
||||
if (bind(ls,(struct sockaddr *) &server,sizeof(struct sockaddr_in)) == -1)
|
||||
{
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to bind socket\n",progname);
|
||||
exit(1);
|
||||
} /* if */
|
||||
glibtop_error_io ("bind");
|
||||
|
||||
/* Initiate the listen on the socket so remote users
|
||||
* can connect.
|
||||
*/
|
||||
if (listen(ls,20) == -1)
|
||||
{
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to listen\n",progname);
|
||||
exit(1);
|
||||
} /* if */
|
||||
glibtop_error_io ("listen");
|
||||
|
||||
return(ls);
|
||||
|
||||
@@ -689,26 +642,34 @@ handle_internet_request (int ls)
|
||||
size_t addrlen = sizeof(struct sockaddr_in);
|
||||
struct sockaddr_in peer; /* for peer socket address */
|
||||
|
||||
memset((char *)&peer,0,sizeof(struct sockaddr_in));
|
||||
memset((char *)&peer, 0, sizeof (struct sockaddr_in));
|
||||
|
||||
if ((s = accept(ls,(struct sockaddr *)&peer, (void *) &addrlen)) == -1)
|
||||
{
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to accept\n",progname);
|
||||
exit(1);
|
||||
} /* if */
|
||||
|
||||
if ((s = accept (ls, (struct sockaddr *)&peer, (void *) &addrlen)) == -1)
|
||||
glibtop_error_io ("accept");
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "Connection was made from %s.\n", inet_ntoa (peer.sin_addr));
|
||||
#endif
|
||||
|
||||
/* Check that access is allowed - if not return crud to the client */
|
||||
if (!permitted(peer.sin_addr.s_addr, s))
|
||||
if (!permitted (peer.sin_addr.s_addr, s))
|
||||
{
|
||||
send_string(s,"gnudoit: Connection refused\ngnudoit: unable to connect to remote");
|
||||
close(s);
|
||||
|
||||
printf("Refused connection from %s\004\n", inet_ntoa(peer.sin_addr));
|
||||
glibtop_warn ("Refused connection from %s.", inet_ntoa (peer.sin_addr));
|
||||
return;
|
||||
} /* if */
|
||||
|
||||
echo_request(s);
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "Accepted connection from %s.\n", inet_ntoa (peer.sin_addr));
|
||||
#endif
|
||||
|
||||
handle_socket_connection (&glibtop_global_server, s);
|
||||
|
||||
close (s);
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "Closed connection to %s.\n", inet_ntoa (peer.sin_addr));
|
||||
#endif
|
||||
|
||||
} /* handle_internet_request */
|
||||
#endif /* INTERNET_DOMAIN_SOCKETS */
|
||||
@@ -726,31 +687,22 @@ unix_init (void)
|
||||
struct sockaddr_un server; /* unix socket address */
|
||||
int bindlen;
|
||||
|
||||
if ((ls = socket(AF_UNIX,SOCK_STREAM, 0)) < 0)
|
||||
{
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to create socket\n",progname);
|
||||
exit(1);
|
||||
} /* if */
|
||||
if ((ls = socket (AF_UNIX,SOCK_STREAM, 0)) < 0)
|
||||
glibtop_error_io ("unable to create socket");
|
||||
|
||||
/* Set up address structure for the listen socket. */
|
||||
#ifdef HIDE_UNIX_SOCKET
|
||||
sprintf(server.sun_path,"/tmp/gsrvdir%d",(int)geteuid());
|
||||
if (mkdir(server.sun_path, 0700) < 0)
|
||||
sprintf (server.sun_path, "/tmp/lgtddir%d", (int)geteuid());
|
||||
if (mkdir (server.sun_path, 0700) < 0)
|
||||
{
|
||||
/* assume it already exists, and try to set perms */
|
||||
if (chmod(server.sun_path, 0700) < 0)
|
||||
{
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: can't set permissions on %s\n",
|
||||
progname, server.sun_path);
|
||||
exit(1);
|
||||
}
|
||||
if (chmod (server.sun_path, 0700) < 0)
|
||||
glibtop_error_io ("Can't set permissions on %s", server.sun_path);
|
||||
}
|
||||
strcat(server.sun_path,"/gsrv");
|
||||
strcat(server.sun_path, "/lgtd");
|
||||
unlink(server.sun_path); /* remove old file if it exists */
|
||||
#else /* HIDE_UNIX_SOCKET */
|
||||
sprintf(server.sun_path,"/tmp/gsrv%d",(int)geteuid());
|
||||
sprintf(server.sun_path, "/tmp/lgtd%d", (int)geteuid());
|
||||
unlink(server.sun_path); /* remove old file if it exists */
|
||||
#endif /* HIDE_UNIX_SOCKET */
|
||||
|
||||
@@ -765,20 +717,13 @@ unix_init (void)
|
||||
bindlen = strlen (server.sun_path) + sizeof (server.sun_family);
|
||||
#endif
|
||||
|
||||
if (bind(ls,(struct sockaddr *)&server,bindlen) < 0)
|
||||
{
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to bind socket\n",progname);
|
||||
exit(1);
|
||||
} /* if */
|
||||
if (bind (ls, (struct sockaddr *)&server, bindlen) < 0)
|
||||
glibtop_error_io ("bind");
|
||||
|
||||
chmod(server.sun_path,0700); /* only this user can send commands */
|
||||
|
||||
if (listen(ls,20) < 0) {
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to listen\n",progname);
|
||||
exit(1);
|
||||
} /* if */
|
||||
if (listen(ls,20) < 0)
|
||||
glibtop_error_io ("listen");
|
||||
|
||||
/* #### there are also better ways of dealing with this when
|
||||
sigvec() is present. */
|
||||
@@ -790,10 +735,10 @@ unix_init (void)
|
||||
sigprocmask (SIG_BLOCK, &_mask, NULL);
|
||||
}
|
||||
#else
|
||||
signal(SIGPIPE,SIG_IGN); /* in case user kills client */
|
||||
signal (SIGPIPE, SIG_IGN); /* in case user kills client */
|
||||
#endif
|
||||
|
||||
return(ls);
|
||||
return (ls);
|
||||
|
||||
} /* unix_init */
|
||||
|
||||
@@ -811,11 +756,8 @@ handle_unix_request (int ls)
|
||||
|
||||
server.sun_family = AF_UNIX;
|
||||
|
||||
if ((s = accept(ls,(struct sockaddr *)&server, (void *)&len)) < 0)
|
||||
{
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to accept\n",progname);
|
||||
} /* if */
|
||||
if ((s = accept (ls, (struct sockaddr *)&server, (void *)&len)) < 0)
|
||||
glibtop_error_io ("accept");
|
||||
|
||||
echo_request(s);
|
||||
|
||||
@@ -829,17 +771,13 @@ main(argc,argv)
|
||||
char *argv[];
|
||||
{
|
||||
int chan; /* temporary channel number */
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
int ils = -1; /* internet domain listen socket */
|
||||
#endif
|
||||
#ifdef UNIX_DOMAIN_SOCKETS
|
||||
int uls = -1; /* unix domain listen socket */
|
||||
#endif
|
||||
#ifdef SYSV_IPC
|
||||
struct msgbuf *msgp; /* message buffer */
|
||||
#endif /* SYSV_IPC */
|
||||
|
||||
progname = argv[0];
|
||||
glibtop_init_r (&glibtop_global_server, 0, GLIBTOP_OPEN_NO_OVERRIDE);
|
||||
|
||||
for(chan=3; chan < _NFILE; close(chan++)) /* close unwanted channels */
|
||||
;
|
||||
@@ -867,14 +805,14 @@ main(argc,argv)
|
||||
FD_SET(uls, &rmask);
|
||||
if (ils >= 0)
|
||||
FD_SET(ils, &rmask);
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "Server ready and waiting for connections.\n");
|
||||
#endif
|
||||
|
||||
if (select(max2(fileno(stdin),max2(uls,ils)) + 1, &rmask,
|
||||
(fd_set *)NULL, (fd_set *)NULL, (struct timeval *)NULL) < 0)
|
||||
{
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to select\n",progname);
|
||||
exit(1);
|
||||
} /* if */
|
||||
glibtop_error_io ("select");
|
||||
|
||||
#ifdef UNIX_DOMAIN_SOCKETS
|
||||
if (uls > 0 && FD_ISSET(uls, &rmask))
|
||||
|
@@ -1,190 +0,0 @@
|
||||
/* -*-C-*-
|
||||
|
||||
Header file for the GNU Emacs server and client C code.
|
||||
|
||||
This file is part of GNU Emacs.
|
||||
|
||||
Copying is permitted under those conditions described by the GNU
|
||||
General Public License.
|
||||
|
||||
Copyright (C) 1989 Free Software Foundation, Inc.
|
||||
|
||||
Author: Andy Norman (ange@hplb.hpl.hp.com), based on
|
||||
'etc/server.c' and 'etc/emacsclient.c' from the 18.52 GNU
|
||||
Emacs distribution.
|
||||
|
||||
Please mail bugs and suggestions to the author at the above address.
|
||||
*/
|
||||
|
||||
/* HISTORY
|
||||
* 11-Nov-1990 bristor@simba
|
||||
* Added EOT stuff.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file incorporates new features added by Bob Weiner <weiner@mot.com>,
|
||||
* Darrell Kindred <dkindred@cmu.edu> and Arup Mukherjee <arup@cmu.edu>.
|
||||
* Please see the note at the end of the README file for details.
|
||||
*
|
||||
* (If gnuserv came bundled with your emacs, the README file is probably
|
||||
* ../etc/gnuserv.README relative to the directory containing this file)
|
||||
*/
|
||||
|
||||
#if 0
|
||||
static char header_rcsid [] = "!Header: gnuserv.h,v 2.4 95/02/16 11:58:11 arup alpha !";
|
||||
#endif
|
||||
|
||||
#define NO_SHORTNAMES
|
||||
|
||||
#define PATCHLEVEL 2
|
||||
|
||||
#define NO_SHORTNAMES
|
||||
/* gnuserv should not be compiled using SOCKS */
|
||||
#define DO_NOT_SOCKSIFY
|
||||
#include <glibtop/global.h>
|
||||
#undef read
|
||||
#undef write
|
||||
#undef open
|
||||
#undef close
|
||||
#undef signal
|
||||
|
||||
/* Define the communication method between server and clients:
|
||||
* You can have either or both kinds of sockets, but you can't mix
|
||||
* sockets with sysv ipc
|
||||
*/
|
||||
|
||||
|
||||
#define INTERNET_DOMAIN_SOCKETS
|
||||
#define UNIX_DOMAIN_SOCKETS
|
||||
/* #define SYSV_IPC */
|
||||
|
||||
/*
|
||||
* Define additional authentication protocols to be used. These methods will
|
||||
* be tried before falling back to the default gnuserv protocol (based on
|
||||
* the GNU_SECURE environment variable). Currently, only MIT-MAGIC-COOKIE-1
|
||||
* is also supported.
|
||||
*
|
||||
* Comment out the next line(s) if you don't want to enable the
|
||||
* appropriate authentication protocol.
|
||||
*/
|
||||
|
||||
#if defined (HAVE_XAUTH)
|
||||
#define AUTH_MAGIC_COOKIE
|
||||
#endif /* HAVE_XAUTH */
|
||||
|
||||
/*
|
||||
* stuff related to supporting MIT-MAGIC-COOKIE-1
|
||||
*/
|
||||
|
||||
#define MCOOKIE_SCREEN "999" /* screen # to use as the gnuserv cookie */
|
||||
#define MCOOKIE_NAME "MAGIC-1" /* authentication protocol name */
|
||||
#define MCOOKIE_X_NAME "MIT-MAGIC-COOKIE-1" /* as needed by X */
|
||||
|
||||
|
||||
#define DEFAUTH_NAME "GNU-SECURE" /* name of default auth protocol */
|
||||
#define AUTH_TIMEOUT 15 /* # seconds to wait for auth data */
|
||||
#define AUTH_NAMESZ 15 /* max allows auth protocol name size */
|
||||
|
||||
|
||||
/*
|
||||
* Pick a default communication scheme, if none was specified.
|
||||
*/
|
||||
|
||||
#if !defined(SYSV_IPC) && !defined(UNIX_DOMAIN_SOCKETS) && !defined(INTERNET_DOMAIN_SOCKETS)
|
||||
|
||||
#ifdef HAVE_SYSVIPC
|
||||
#define SYSV_IPC /* SYSV systems use SYSV IPC by default */
|
||||
#endif /* HAVE_SYSVIPC */
|
||||
|
||||
#ifdef BSD
|
||||
#define UNIX_DOMAIN_SOCKETS /* BSD systems use Unix Domain sockets by default */
|
||||
#endif /* BSD */
|
||||
|
||||
#endif /* No communication method pre-defined */
|
||||
|
||||
/*
|
||||
* If you are using SYSV_IPC, you might want to make the buffer size bigger
|
||||
* since it limits the size of requests and responses. Don't make it bigger
|
||||
* than your system's max message size though (usually a couple of k) or else
|
||||
* msgsend will start failing. For sockets, using the system BUFSIZ is usually
|
||||
* what you want.
|
||||
*/
|
||||
|
||||
# define GSERV_BUFSZ BUFSIZ
|
||||
|
||||
|
||||
#ifdef SYSV_IPC
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/msg.h>
|
||||
|
||||
#define send_string(s,str) \
|
||||
if (strlen(msgp->mtext) + strlen(str) < GSERV_BUFSZ) \
|
||||
strcat(msgp->mtext,str); \
|
||||
else \
|
||||
{ \
|
||||
fprintf(stderr,"%s: not enough message buffer space\n",progname); \
|
||||
exit(1); \
|
||||
} \
|
||||
|
||||
#endif /* SYSV_IPC */
|
||||
|
||||
#if defined(INTERNET_DOMAIN_SOCKETS) || defined(UNIX_DOMAIN_SOCKETS)
|
||||
#include <sys/socket.h>
|
||||
#endif /* INTERNET_DOMAIN_SOCKETS || UNIX_DOMAIN_SOCKETS */
|
||||
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#define TABLE_SIZE 101 /* The number of entries in the hash table */
|
||||
#define HASH(host) host /* Rather simplistic hash function */
|
||||
#define DEFAULT_PORT 21490 /* default port number to use is
|
||||
* DEFAULT_PORT + uid */
|
||||
#endif /* INTERNET_DOMAIN_SOCKETS */
|
||||
|
||||
#ifdef UNIX_DOMAIN_SOCKETS
|
||||
#include <sys/un.h>
|
||||
#define HIDE_UNIX_SOCKET /* put the unix socket in a protected dir */
|
||||
#endif /* UNIX_DOMAIN_SOCKETS */
|
||||
|
||||
#define HOSTNAMSZ 255 /* max size of a hostname */
|
||||
#define REPLYSIZ 300 /* max size of reply from server to client */
|
||||
#undef FALSE
|
||||
#define FALSE 0
|
||||
#undef TRUE
|
||||
#define TRUE 1
|
||||
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
extern char *progname;
|
||||
|
||||
/* The casts shut Sun's compiler up and are safe in the context these
|
||||
are actually used. */
|
||||
#define max2(x,y) (((int) (x) > (int) (y)) ? (x) : (y))
|
||||
#define min2(x,y) (((int) (x) < (int) (y)) ? (x) : (y))
|
||||
|
||||
#ifndef _NFILE /* rough guess at maximum number of open files */
|
||||
#define _NFILE 20
|
||||
#endif
|
||||
|
||||
#define EOT_STR "\004"
|
||||
#define EOT_CHR '\004'
|
||||
|
||||
/* connection types */
|
||||
#define CONN_UNIX 0
|
||||
#define CONN_INTERNET 1
|
||||
#define CONN_IPC 2
|
||||
|
||||
/* function declarations */
|
||||
int make_connection (char *hostarg, int portarg, int *s);
|
||||
#ifdef SYSV_IPC
|
||||
void disconnect_from_ipc_server();
|
||||
#endif
|
||||
#if defined(INTERNET_DOMAIN_SOCKETS) || defined(UNIX_DOMAIN_SOCKETS)
|
||||
void send_string (int s, const char *msg);
|
||||
void disconnect_from_server (int s, int echo);
|
||||
int read_line (int s, char *dest);
|
||||
#endif
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
int internet_addr (char *host);
|
||||
#endif
|
@@ -1,454 +0,0 @@
|
||||
/* -*-C-*-
|
||||
Common library code for the GNU Emacs server and client.
|
||||
|
||||
This file is part of GNU Emacs.
|
||||
|
||||
Copying is permitted under those conditions described by the GNU
|
||||
General Public License.
|
||||
|
||||
Copyright (C) 1989 Free Software Foundation, Inc.
|
||||
|
||||
Author: Andy Norman (ange@hplb.hpl.hp.com), based on
|
||||
'etc/server.c' and 'etc/emacsclient.c' from the 18.52 GNU
|
||||
Emacs distribution.
|
||||
|
||||
Please mail bugs and suggestions to the author at the above address.
|
||||
*/
|
||||
|
||||
/* HISTORY
|
||||
* 11-Nov-1990 bristor@simba
|
||||
* Added EOT stuff.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file incorporates new features added by Bob Weiner <weiner@mot.com>,
|
||||
* Darrell Kindred <dkindred@cmu.edu> and Arup Mukherjee <arup@cmu.edu>.
|
||||
* Please see the note at the end of the README file for details.
|
||||
*
|
||||
* (If gnuserv came bundled with your emacs, the README file is probably
|
||||
* ../etc/gnuserv.README relative to the directory containing this file)
|
||||
*/
|
||||
|
||||
#if 0
|
||||
static char rcsid [] = "!Header: gnuslib.c,v 2.4 95/02/16 11:57:37 arup alpha !";
|
||||
#endif
|
||||
|
||||
#include "gnuserv.h"
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef SYSV_IPC
|
||||
static int connect_to_ipc_server (void);
|
||||
#endif
|
||||
#ifdef UNIX_DOMAIN_SOCKETS
|
||||
static int connect_to_unix_server (void);
|
||||
#endif
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
static int connect_to_internet_server (char *serverhost, u_short port);
|
||||
#endif
|
||||
|
||||
/* On some systems, e.g. DGUX, inet_addr returns a 'struct in_addr'. */
|
||||
#ifdef HAVE_BROKEN_INET_ADDR
|
||||
# define IN_ADDR struct in_addr
|
||||
# define NUMERIC_ADDR_ERROR (numeric_addr.s_addr == -1)
|
||||
#else
|
||||
# if (LONGBITS > 32)
|
||||
# define IN_ADDR unsigned int
|
||||
# else
|
||||
# define IN_ADDR unsigned long
|
||||
# endif
|
||||
# define NUMERIC_ADDR_ERROR (numeric_addr == (IN_ADDR) -1)
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif /* HAVE_UNISTD_H */
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif /* HAVE_STRING_H */
|
||||
|
||||
#include <arpa/inet.h>
|
||||
|
||||
char *progname = NULL;
|
||||
|
||||
int make_connection(hostarg, portarg, s)
|
||||
char *hostarg;
|
||||
int portarg;
|
||||
int *s;
|
||||
{
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
char *ptr;
|
||||
if (hostarg == NULL)
|
||||
hostarg = getenv("GNU_HOST");
|
||||
if (portarg == 0 && (ptr=getenv("GNU_PORT")) != NULL)
|
||||
portarg = atoi(ptr);
|
||||
#endif
|
||||
|
||||
if (hostarg != NULL) {
|
||||
/* hostname was given explicitly, via cmd line arg or GNU_HOST,
|
||||
* so obey it. */
|
||||
#ifdef UNIX_DOMAIN_SOCKETS
|
||||
if (!strcmp(hostarg, "unix")) {
|
||||
*s = connect_to_unix_server();
|
||||
return (int) CONN_UNIX;
|
||||
}
|
||||
#endif /* UNIX_DOMAIN_SOCKETS */
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
*s = connect_to_internet_server(hostarg, portarg);
|
||||
return (int) CONN_INTERNET;
|
||||
#endif
|
||||
#ifdef SYSV_IPC
|
||||
return -1; /* hostarg should always be NULL for SYSV_IPC */
|
||||
#endif
|
||||
} else {
|
||||
/* no hostname given. Use unix-domain/sysv-ipc, or
|
||||
* internet-domain connection to local host if they're not available. */
|
||||
#if defined(UNIX_DOMAIN_SOCKETS)
|
||||
*s = connect_to_unix_server();
|
||||
return (int) CONN_UNIX;
|
||||
#elif defined(SYSV_IPC)
|
||||
*s = connect_to_ipc_server();
|
||||
return (int) CONN_IPC;
|
||||
#elif defined(INTERNET_DOMAIN_SOCKETS)
|
||||
{
|
||||
char localhost[HOSTNAMSZ];
|
||||
gethostname(localhost,HOSTNAMSZ); /* use this host by default */
|
||||
*s = connect_to_internet_server(localhost, portarg);
|
||||
return (int) CONN_INTERNET;
|
||||
}
|
||||
#endif /* IPC type */
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SYSV_IPC
|
||||
/*
|
||||
connect_to_ipc_server -- establish connection with server process via SYSV IPC
|
||||
Returns msqid for server if successful.
|
||||
*/
|
||||
static int connect_to_ipc_server (void)
|
||||
{
|
||||
int s; /* connected msqid */
|
||||
key_t key; /* message key */
|
||||
char buf[GSERV_BUFSZ+1]; /* buffer for filename */
|
||||
|
||||
sprintf(buf,"/tmp/gsrv%d",(int)geteuid());
|
||||
creat(buf,0600);
|
||||
if ((key = ftok(buf,1)) == -1) {
|
||||
perror(progname);
|
||||
fprintf(stderr, "%s: unable to get ipc key from %s\n",
|
||||
progname, buf);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ((s = msgget(key,0600)) == -1) {
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to access msg queue\n",progname);
|
||||
exit(1);
|
||||
}; /* if */
|
||||
|
||||
return(s);
|
||||
|
||||
} /* connect_to_ipc_server */
|
||||
|
||||
|
||||
/*
|
||||
disconnect_from_ipc_server -- inform the server that sending has finished,
|
||||
and wait for its reply.
|
||||
*/
|
||||
void disconnect_from_ipc_server(s,msgp,echo)
|
||||
int s;
|
||||
struct msgbuf *msgp;
|
||||
int echo;
|
||||
{
|
||||
int len; /* length of received message */
|
||||
|
||||
send_string(s,EOT_STR); /* EOT terminates this message */
|
||||
msgp->mtype = 1;
|
||||
|
||||
if(msgsnd(s,msgp,strlen(msgp->mtext)+1,0) < 0) {
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to send message to server\n",progname);
|
||||
exit(1);
|
||||
}; /* if */
|
||||
|
||||
if((len = msgrcv(s,msgp,GSERV_BUFSZ,getpid(),0)) < 0) {
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to receive message from server\n",progname);
|
||||
exit(1);
|
||||
}; /* if */
|
||||
|
||||
if (echo) {
|
||||
msgp->mtext[len] = '\0'; /* string terminate message */
|
||||
fputs(msgp->mtext, stdout);
|
||||
if (msgp->mtext[len-1] != '\n') putchar ('\n');
|
||||
}; /* if */
|
||||
|
||||
} /* disconnect_from_ipc_server */
|
||||
#endif /* SYSV_IPC */
|
||||
|
||||
|
||||
#if defined(INTERNET_DOMAIN_SOCKETS) || defined(UNIX_DOMAIN_SOCKETS)
|
||||
/*
|
||||
send_string -- send string to socket.
|
||||
*/
|
||||
void send_string(s,msg)
|
||||
int s;
|
||||
const char *msg;
|
||||
{
|
||||
#if 0
|
||||
if (send(s,msg,strlen(msg),0) < 0) {
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to send\n",progname);
|
||||
exit(1);
|
||||
}; /* if */
|
||||
#else
|
||||
int len, left=strlen(msg);
|
||||
while (left > 0) {
|
||||
if ((len=write(s,msg,min2(left,GSERV_BUFSZ))) < 0) {
|
||||
/* XEmacs addition: robertl@arnet.com */
|
||||
if (errno == EPIPE) {
|
||||
return ;
|
||||
}
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to send\n",progname);
|
||||
exit(1);
|
||||
}; /* if */
|
||||
left -= len;
|
||||
msg += len;
|
||||
}; /* while */
|
||||
#endif
|
||||
} /* send_string */
|
||||
|
||||
/*
|
||||
read_line -- read a \n terminated line from a socket
|
||||
*/
|
||||
int read_line(int s, char *dest)
|
||||
{
|
||||
int length;
|
||||
int offset=0;
|
||||
char buffer[GSERV_BUFSZ+1];
|
||||
|
||||
while ((length=read(s,buffer+offset,1)>0) && buffer[offset]!='\n'
|
||||
&& buffer[offset] != EOT_CHR) {
|
||||
offset += length;
|
||||
if (offset >= GSERV_BUFSZ)
|
||||
break;
|
||||
}
|
||||
buffer[offset] = '\0';
|
||||
strcpy(dest,buffer);
|
||||
return 1;
|
||||
} /* read_line */
|
||||
#endif /* INTERNET_DOMAIN_SOCKETS || UNIX_DOMAIN_SOCKETS */
|
||||
|
||||
|
||||
#ifdef UNIX_DOMAIN_SOCKETS
|
||||
/*
|
||||
connect_to_unix_server -- establish connection with server process via a unix-
|
||||
domain socket. Returns socket descriptor for server
|
||||
if successful.
|
||||
*/
|
||||
static int connect_to_unix_server (void)
|
||||
{
|
||||
int s; /* connected socket descriptor */
|
||||
struct sockaddr_un server; /* for unix connections */
|
||||
|
||||
if ((s = socket(AF_UNIX,SOCK_STREAM,0)) < 0) {
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to create socket\n",progname);
|
||||
exit(1);
|
||||
}; /* if */
|
||||
|
||||
server.sun_family = AF_UNIX;
|
||||
#ifdef HIDE_UNIX_SOCKET
|
||||
sprintf(server.sun_path,"/tmp/gsrvdir%d/gsrv",(int)geteuid());
|
||||
#else /* HIDE_UNIX_SOCKET */
|
||||
sprintf(server.sun_path,"/tmp/gsrv%d",(int)geteuid());
|
||||
#endif /* HIDE_UNIX_SOCKET */
|
||||
if (connect(s,(struct sockaddr *)&server,strlen(server.sun_path)+2) < 0) {
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to connect to local\n",progname);
|
||||
exit(1);
|
||||
}; /* if */
|
||||
|
||||
return(s);
|
||||
|
||||
} /* connect_to_unix_server */
|
||||
#endif /* UNIX_DOMAIN_SOCKETS */
|
||||
|
||||
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
/*
|
||||
internet_addr -- return the internet addr of the hostname or
|
||||
internet address passed. Return -1 on error.
|
||||
*/
|
||||
int internet_addr(host)
|
||||
char *host;
|
||||
{
|
||||
struct hostent *hp; /* pointer to host info for remote host */
|
||||
IN_ADDR numeric_addr; /* host address */
|
||||
|
||||
numeric_addr = inet_addr(host);
|
||||
if (!NUMERIC_ADDR_ERROR)
|
||||
return numeric_addr;
|
||||
else if ((hp = gethostbyname(host)) != NULL)
|
||||
return ((struct in_addr *)(hp->h_addr))->s_addr;
|
||||
else
|
||||
return -1;
|
||||
|
||||
} /* internet_addr */
|
||||
|
||||
#ifdef AUTH_MAGIC_COOKIE
|
||||
# include <X11/X.h>
|
||||
# include <X11/Xauth.h>
|
||||
|
||||
static Xauth *server_xauth = NULL;
|
||||
#endif
|
||||
|
||||
/*
|
||||
connect_to_internet_server -- establish connection with server process via
|
||||
an internet domain socket. Returns socket
|
||||
descriptor for server if successful.
|
||||
*/
|
||||
static int connect_to_internet_server (char *serverhost, u_short port)
|
||||
{
|
||||
int s; /* connected socket descriptor */
|
||||
struct servent *sp; /* pointer to service information */
|
||||
struct sockaddr_in peeraddr_in; /* for peer socket address */
|
||||
char buf[512]; /* temporary buffer */
|
||||
|
||||
/* clear out address structures */
|
||||
memset((char *)&peeraddr_in,0,sizeof(struct sockaddr_in));
|
||||
|
||||
/* Set up the peer address to which we will connect. */
|
||||
peeraddr_in.sin_family = AF_INET;
|
||||
|
||||
/* look up the server host's internet address */
|
||||
if ((peeraddr_in.sin_addr.s_addr = internet_addr(serverhost)) == -1) {
|
||||
fprintf(stderr,"%s: unable to find %s in /etc/hosts or from YP\n",
|
||||
progname,serverhost);
|
||||
exit(1);
|
||||
}; /* if */
|
||||
|
||||
if (port == 0) {
|
||||
if ((sp = getservbyname ("gnuserv","tcp")) == NULL)
|
||||
peeraddr_in.sin_port = htons(DEFAULT_PORT+getuid());
|
||||
else
|
||||
peeraddr_in.sin_port = sp->s_port;
|
||||
} /* if */
|
||||
else
|
||||
peeraddr_in.sin_port = htons(port);
|
||||
|
||||
/* Create the socket. */
|
||||
if ((s = socket (AF_INET,SOCK_STREAM, 0))== -1) {
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to create socket\n",progname);
|
||||
exit(1);
|
||||
}; /* if */
|
||||
|
||||
/* Try to connect to the remote server at the address
|
||||
* which was just built into peeraddr.
|
||||
*/
|
||||
if (connect(s, (struct sockaddr *)&peeraddr_in,
|
||||
sizeof(struct sockaddr_in)) == -1) {
|
||||
perror(progname);
|
||||
fprintf(stderr, "%s: unable to connect to remote\n",progname);
|
||||
exit(1);
|
||||
}; /* if */
|
||||
|
||||
#ifdef AUTH_MAGIC_COOKIE
|
||||
|
||||
/* send credentials using MIT-MAGIC-COOKIE-1 protocol */
|
||||
|
||||
server_xauth =
|
||||
XauGetAuthByAddr(FamilyInternet,
|
||||
sizeof(peeraddr_in.sin_addr.s_addr),
|
||||
(char *) &peeraddr_in.sin_addr.s_addr,
|
||||
strlen(MCOOKIE_SCREEN), MCOOKIE_SCREEN,
|
||||
strlen(MCOOKIE_X_NAME), MCOOKIE_X_NAME);
|
||||
|
||||
if (server_xauth && server_xauth->data) {
|
||||
sprintf(buf, "%s\n%d\n", MCOOKIE_NAME, server_xauth->data_length);
|
||||
write (s, buf, strlen(buf));
|
||||
write (s, server_xauth->data, server_xauth->data_length);
|
||||
|
||||
return (s);
|
||||
}
|
||||
|
||||
#endif /* AUTH_MAGIC_COOKIE */
|
||||
|
||||
sprintf (buf, "%s\n", DEFAUTH_NAME);
|
||||
write (s, buf, strlen(buf));
|
||||
|
||||
return(s);
|
||||
|
||||
} /* connect_to_internet_server */
|
||||
#endif /* INTERNET_DOMAIN_SOCKETS */
|
||||
|
||||
|
||||
#if defined(INTERNET_DOMAIN_SOCKETS) || defined(UNIX_DOMAIN_SOCKETS)
|
||||
/*
|
||||
disconnect_from_server -- inform the server that sending has finished, and wait for
|
||||
its reply.
|
||||
*/
|
||||
void disconnect_from_server(s,echo)
|
||||
int s;
|
||||
int echo;
|
||||
{
|
||||
#if 0
|
||||
char buffer[REPLYSIZ+1];
|
||||
#else
|
||||
char buffer[GSERV_BUFSZ+1];
|
||||
#endif
|
||||
int add_newline = 1;
|
||||
int length;
|
||||
|
||||
send_string(s,EOT_STR); /* make sure server gets string */
|
||||
|
||||
#if !defined (linux) && !defined (_SCO_DS)
|
||||
/*
|
||||
* shutdown is completely hozed under linux. If s is a unix domain socket,
|
||||
* you'll get EOPNOTSUPP back from it. If s is an internet socket, you get
|
||||
* a broken pipe when you try to read a bit later. The latter
|
||||
* problem is fixed for linux versions >= 1.1.46, but the problem
|
||||
* with unix sockets persists. Sigh.
|
||||
*/
|
||||
|
||||
if (shutdown(s,1) == -1) {
|
||||
perror(progname);
|
||||
fprintf(stderr, "%s: unable to shutdown socket\n",progname);
|
||||
exit(1);
|
||||
}; /* if */
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
while((length = recv(s,buffer,REPLYSIZ,0)) > 0) {
|
||||
buffer[length] = '\0';
|
||||
if (echo) fputs(buffer,stdout);
|
||||
add_newline = (buffer[length-1] != '\n');
|
||||
}; /* while */
|
||||
#else
|
||||
while ((length = read(s,buffer,GSERV_BUFSZ)) > 0 ||
|
||||
(length == -1 && errno == EINTR)) {
|
||||
if (length) {
|
||||
buffer[length] = '\0';
|
||||
if (echo) {
|
||||
fputs(buffer,stdout);
|
||||
add_newline = (buffer[length-1] != '\n');
|
||||
}; /* if */
|
||||
}; /* if */
|
||||
}; /* while */
|
||||
#endif
|
||||
|
||||
if (echo && add_newline) putchar('\n');
|
||||
|
||||
if(length < 0) {
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to read the reply from the server\n",progname);
|
||||
exit(1);
|
||||
}; /* if */
|
||||
|
||||
} /* disconnect_from_server */
|
||||
#endif /* INTERNET_DOMAIN_SOCKETS || UNIX_DOMAIN_SOCKETS */
|
218
src/daemon/main.c
Normal file
218
src/daemon/main.c
Normal file
@@ -0,0 +1,218 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the Gnome Top Library.
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
The Gnome Top Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The Gnome Top Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <glibtop/gnuserv.h>
|
||||
|
||||
#include <glibtop/command.h>
|
||||
#include <glibtop/version.h>
|
||||
#include <glibtop/xmalloc.h>
|
||||
#include <glibtop/union.h>
|
||||
#include <glibtop/open.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <locale.h>
|
||||
|
||||
#if defined(HAVE_GETDTABLESIZE)
|
||||
#define GET_MAX_FDS() getdtablesize()
|
||||
#else
|
||||
/* Fallthrough case - please add other #elif cases above
|
||||
for different OS's as necessary */
|
||||
#define GET_MAX_FDS() 256
|
||||
#endif
|
||||
|
||||
#define _offset_union(p) ((char *) &response.u.p - (char *) &response)
|
||||
#define _offset_data(p) _offset_union (data.p)
|
||||
|
||||
static void
|
||||
do_output (int s, glibtop_response *response, off_t offset,
|
||||
size_t data_size, const void *data)
|
||||
{
|
||||
#ifdef REAL_DEBUG
|
||||
fprintf (stderr, "Really writing %d bytes at offset %d.\n",
|
||||
sizeof (glibtop_response), offset);
|
||||
#endif
|
||||
|
||||
response->offset = offset;
|
||||
response->data_size = data_size;
|
||||
|
||||
if (send (s, response, sizeof (glibtop_response), 0) < 0)
|
||||
glibtop_warn_io ("send");
|
||||
|
||||
if (response->data_size) {
|
||||
#ifdef REAL_DEBUG
|
||||
fprintf (stderr, "Writing %d bytes of data.\n", response->data_size);
|
||||
#endif
|
||||
|
||||
if (send (s, data, response->data_size, 0) , 0)
|
||||
glibtop_warn_io ("send");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
do_read (int s, void *ptr, size_t total_size)
|
||||
{
|
||||
int nread;
|
||||
size_t already_read = 0, remaining = total_size;
|
||||
|
||||
while (already_read < total_size) {
|
||||
nread = recv (s, ptr, remaining, 0);
|
||||
|
||||
if (nread <= 0) {
|
||||
glibtop_error_io ("recv");
|
||||
return;
|
||||
}
|
||||
|
||||
already_read += nread;
|
||||
remaining -= nread;
|
||||
(char *) ptr += nread;
|
||||
|
||||
fprintf (stderr, "READ (%d): %d - %d - %d\n",
|
||||
nread, already_read, remaining, total_size);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
handle_socket_connection (glibtop *server, int s)
|
||||
{
|
||||
pid_t pid;
|
||||
char parameter [BUFSIZ];
|
||||
struct timeval tv;
|
||||
glibtop_response response;
|
||||
glibtop_command cmnd;
|
||||
void *ptr;
|
||||
|
||||
tv.tv_sec = 5;
|
||||
tv.tv_usec = 0;
|
||||
|
||||
while(1) {
|
||||
do_read (s, &cmnd, sizeof (glibtop_command));
|
||||
|
||||
#ifdef REAL_DEBUG
|
||||
fprintf (stderr, "Received command %d from client.\n", cmnd.command);
|
||||
#endif
|
||||
|
||||
if (cmnd.data_size >= BUFSIZ) {
|
||||
glibtop_warn ("Client sent %d bytes, but buffer is %d", cmnd.size, BUFSIZ);
|
||||
return;
|
||||
}
|
||||
|
||||
memset (parameter, 0, sizeof (parameter));
|
||||
|
||||
if (cmnd.data_size) {
|
||||
#ifdef REAL_DEBUG
|
||||
fprintf (stderr, "Client has %d bytes of data.\n", cmnd.data_size);
|
||||
#endif
|
||||
|
||||
do_read (s, parameter, cmnd.data_size);
|
||||
|
||||
} else if (cmnd.size) {
|
||||
memcpy (parameter, cmnd.parameter, cmnd.size);
|
||||
}
|
||||
|
||||
switch (cmnd.command) {
|
||||
case GLIBTOP_CMND_SYSDEPS:
|
||||
response.u.sysdeps.features = GLIBTOP_SYSDEPS_ALL;
|
||||
do_output (s, &response, _offset_union (sysdeps), 0, NULL);
|
||||
break;
|
||||
case GLIBTOP_CMND_CPU:
|
||||
glibtop_get_cpu_l (server, &response.u.data.cpu);
|
||||
do_output (s, &response, _offset_data (cpu), 0, NULL);
|
||||
break;
|
||||
case GLIBTOP_CMND_MEM:
|
||||
glibtop_get_mem_l (server, &response.u.data.mem);
|
||||
do_output (s, &response, _offset_data (mem), 0, NULL);
|
||||
break;
|
||||
case GLIBTOP_CMND_SWAP:
|
||||
glibtop_get_swap_l (server, &response.u.data.swap);
|
||||
do_output (s, &response, _offset_data (swap), 0, NULL);
|
||||
break;
|
||||
case GLIBTOP_CMND_UPTIME:
|
||||
glibtop_get_uptime_l (server, &response.u.data.uptime);
|
||||
do_output (s, &response, _offset_data (uptime), 0, NULL);
|
||||
break;
|
||||
case GLIBTOP_CMND_LOADAVG:
|
||||
glibtop_get_loadavg_l (server, &response.u.data.loadavg);
|
||||
do_output (s, &response, _offset_data (loadavg), 0, NULL);
|
||||
break;
|
||||
case GLIBTOP_CMND_SHM_LIMITS:
|
||||
glibtop_get_shm_limits_l (server, &response.u.data.shm_limits);
|
||||
do_output (s, &response, _offset_data (shm_limits), 0, NULL);
|
||||
break;
|
||||
case GLIBTOP_CMND_MSG_LIMITS:
|
||||
glibtop_get_msg_limits_l (server, &response.u.data.msg_limits);
|
||||
do_output (s, &response, _offset_data (msg_limits), 0, NULL);
|
||||
break;
|
||||
case GLIBTOP_CMND_SEM_LIMITS:
|
||||
glibtop_get_sem_limits_l (server, &response.u.data.sem_limits);
|
||||
do_output (s, &response, _offset_data (sem_limits), 0, NULL);
|
||||
break;
|
||||
case GLIBTOP_CMND_PROCLIST:
|
||||
ptr = glibtop_get_proclist_l (server, &response.u.data.proclist);
|
||||
do_output (s, &response, _offset_data (proclist),
|
||||
response.u.data.proclist.total, ptr);
|
||||
glibtop_free_r (server, ptr);
|
||||
break;
|
||||
case GLIBTOP_CMND_PROC_STATE:
|
||||
memcpy (&pid, parameter, sizeof (pid_t));
|
||||
glibtop_get_proc_state_l
|
||||
(server, &response.u.data.proc_state, pid);
|
||||
do_output (s, &response, _offset_data (proc_state), 0, NULL);
|
||||
break;
|
||||
case GLIBTOP_CMND_PROC_UID:
|
||||
pid = 1;
|
||||
memcpy (&pid, parameter, sizeof (pid_t));
|
||||
glibtop_get_proc_uid_l
|
||||
(server, &response.u.data.proc_uid, pid);
|
||||
do_output (s, &response, _offset_data (proc_uid), 0, NULL);
|
||||
break;
|
||||
case GLIBTOP_CMND_PROC_MEM:
|
||||
memcpy (&pid, parameter, sizeof (pid_t));
|
||||
glibtop_get_proc_mem_l
|
||||
(server, &response.u.data.proc_mem, pid);
|
||||
do_output (s, &response, _offset_data (proc_mem), 0, NULL);
|
||||
break;
|
||||
case GLIBTOP_CMND_PROC_TIME:
|
||||
memcpy (&pid, parameter, sizeof (pid_t));
|
||||
glibtop_get_proc_time_l
|
||||
(server, &response.u.data.proc_time, pid);
|
||||
do_output (s, &response, _offset_data (proc_time), 0, NULL);
|
||||
break;
|
||||
case GLIBTOP_CMND_PROC_SIGNAL:
|
||||
memcpy (&pid, parameter, sizeof (pid_t));
|
||||
glibtop_get_proc_signal_l
|
||||
(server, &response.u.data.proc_signal, pid);
|
||||
do_output (s, &response, _offset_data (proc_signal), 0, NULL);
|
||||
break;
|
||||
case GLIBTOP_CMND_PROC_KERNEL:
|
||||
memcpy (&pid, parameter, sizeof (pid_t));
|
||||
glibtop_get_proc_kernel_l
|
||||
(server, &response.u.data.proc_kernel, pid);
|
||||
do_output (s, &response, _offset_data (proc_kernel), 0, NULL);
|
||||
break;
|
||||
case GLIBTOP_CMND_PROC_SEGMENT:
|
||||
memcpy (&pid, parameter, sizeof (pid_t));
|
||||
glibtop_get_proc_segment_l
|
||||
(server, &response.u.data.proc_segment, pid);
|
||||
do_output (s, &response, _offset_data (proc_segment), 0, NULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
@@ -12,5 +12,5 @@ gtop_proxy_SOURCES = main.c output.c version.c
|
||||
gtop_proxy_LDADD = $(top_builddir)/lib/libgtop.la \
|
||||
$(top_builddir)/sysdeps/common/libgtop_common.la \
|
||||
$(top_builddir)/sysdeps/@sysdeps_dir@/libgtop_sysdeps.la \
|
||||
@INTLLIBS@ @LIBSUPPORT@
|
||||
@INTLLIBS@ @LIBSUPPORT@ @libs_xauth@
|
||||
gtop_proxy_LDFLAGS = -static
|
||||
|
@@ -8,5 +8,4 @@ CFLAGS = -Wall -W @CFLAGS@
|
||||
|
||||
lib_LTLIBRARIES = libgtop_common.la
|
||||
|
||||
libgtop_common_la_SOURCES = sysdeps.c xmalloc.c error.c
|
||||
|
||||
libgtop_common_la_SOURCES = sysdeps.c xmalloc.c error.c gnuslib.c
|
||||
|
274
sysdeps/common/fsusage.c
Normal file
274
sysdeps/common/fsusage.c
Normal file
@@ -0,0 +1,274 @@
|
||||
/* fsusage.c -- return space usage of mounted filesystems
|
||||
Copyright (C) 1991, 1992, 1996 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include "fsusage.h"
|
||||
|
||||
int statfs ();
|
||||
|
||||
#if HAVE_SYS_PARAM_H
|
||||
# include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_SYS_MOUNT_H
|
||||
# include <sys/mount.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_SYS_VFS_H
|
||||
# include <sys/vfs.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_SYS_FS_S5PARAM_H /* Fujitsu UXP/V */
|
||||
# include <sys/fs/s5param.h>
|
||||
#endif
|
||||
|
||||
#if defined (HAVE_SYS_FILSYS_H) && !defined (_CRAY)
|
||||
# include <sys/filsys.h> /* SVR2 */
|
||||
#endif
|
||||
|
||||
#if HAVE_FCNTL_H
|
||||
# include <fcntl.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_SYS_STATFS_H
|
||||
# include <sys/statfs.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_DUSTAT_H /* AIX PS/2 */
|
||||
# include <sys/dustat.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_SYS_STATVFS_H /* SVR4 */
|
||||
# include <sys/statvfs.h>
|
||||
int statvfs ();
|
||||
#endif
|
||||
|
||||
int safe_read ();
|
||||
|
||||
/* Return the number of TOSIZE-byte blocks used by
|
||||
BLOCKS FROMSIZE-byte blocks, rounding away from zero.
|
||||
TOSIZE must be positive. Return -1 if FROMSIZE is not positive. */
|
||||
|
||||
static long
|
||||
adjust_blocks (blocks, fromsize, tosize)
|
||||
long blocks;
|
||||
int fromsize, tosize;
|
||||
{
|
||||
if (tosize <= 0)
|
||||
abort ();
|
||||
if (fromsize <= 0)
|
||||
return -1;
|
||||
|
||||
if (fromsize == tosize) /* e.g., from 512 to 512 */
|
||||
return blocks;
|
||||
else if (fromsize > tosize) /* e.g., from 2048 to 512 */
|
||||
return blocks * (fromsize / tosize);
|
||||
else /* e.g., from 256 to 512 */
|
||||
return (blocks + (blocks < 0 ? -1 : 1)) / (tosize / fromsize);
|
||||
}
|
||||
|
||||
/* Fill in the fields of FSP with information about space usage for
|
||||
the filesystem on which PATH resides.
|
||||
DISK is the device on which PATH is mounted, for space-getting
|
||||
methods that need to know it.
|
||||
Return 0 if successful, -1 if not. When returning -1, ensure that
|
||||
ERRNO is either a system error value, or zero if DISK is NULL
|
||||
on a system that requires a non-NULL value. */
|
||||
int
|
||||
get_fs_usage (path, disk, fsp)
|
||||
const char *path;
|
||||
const char *disk;
|
||||
struct fs_usage *fsp;
|
||||
{
|
||||
#ifdef STAT_STATFS3_OSF1
|
||||
# define CONVERT_BLOCKS(B) adjust_blocks ((B), fsd.f_fsize, 512)
|
||||
|
||||
struct statfs fsd;
|
||||
|
||||
if (statfs (path, &fsd, sizeof (struct statfs)) != 0)
|
||||
return -1;
|
||||
|
||||
#endif /* STAT_STATFS3_OSF1 */
|
||||
|
||||
#ifdef STAT_STATFS2_FS_DATA /* Ultrix */
|
||||
# define CONVERT_BLOCKS(B) adjust_blocks ((B), 1024, 512)
|
||||
|
||||
struct fs_data fsd;
|
||||
|
||||
if (statfs (path, &fsd) != 1)
|
||||
return -1;
|
||||
fsp->fsu_blocks = CONVERT_BLOCKS (fsd.fd_req.btot);
|
||||
fsp->fsu_bfree = CONVERT_BLOCKS (fsd.fd_req.bfree);
|
||||
fsp->fsu_bavail = CONVERT_BLOCKS (fsd.fd_req.bfreen);
|
||||
fsp->fsu_files = fsd.fd_req.gtot;
|
||||
fsp->fsu_ffree = fsd.fd_req.gfree;
|
||||
|
||||
#endif /* STAT_STATFS2_FS_DATA */
|
||||
|
||||
#ifdef STAT_READ_FILSYS /* SVR2 */
|
||||
# ifndef SUPERBOFF
|
||||
# define SUPERBOFF (SUPERB * 512)
|
||||
# endif
|
||||
# define CONVERT_BLOCKS(B) \
|
||||
adjust_blocks ((B), (fsd.s_type == Fs2b ? 1024 : 512), 512)
|
||||
|
||||
struct filsys fsd;
|
||||
int fd;
|
||||
|
||||
if (! disk)
|
||||
{
|
||||
errno = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
fd = open (disk, O_RDONLY);
|
||||
if (fd < 0)
|
||||
return -1;
|
||||
lseek (fd, (long) SUPERBOFF, 0);
|
||||
if (safe_read (fd, (char *) &fsd, sizeof fsd) != sizeof fsd)
|
||||
{
|
||||
close (fd);
|
||||
return -1;
|
||||
}
|
||||
close (fd);
|
||||
fsp->fsu_blocks = CONVERT_BLOCKS (fsd.s_fsize);
|
||||
fsp->fsu_bfree = CONVERT_BLOCKS (fsd.s_tfree);
|
||||
fsp->fsu_bavail = CONVERT_BLOCKS (fsd.s_tfree);
|
||||
fsp->fsu_files = (fsd.s_isize - 2) * INOPB * (fsd.s_type == Fs2b ? 2 : 1);
|
||||
fsp->fsu_ffree = fsd.s_tinode;
|
||||
|
||||
#endif /* STAT_READ_FILSYS */
|
||||
|
||||
#ifdef STAT_STATFS2_BSIZE /* 4.3BSD, SunOS 4, HP-UX, AIX */
|
||||
# define CONVERT_BLOCKS(B) adjust_blocks ((B), fsd.f_bsize, 512)
|
||||
|
||||
struct statfs fsd;
|
||||
|
||||
if (statfs (path, &fsd) < 0)
|
||||
return -1;
|
||||
|
||||
# ifdef STATFS_TRUNCATES_BLOCK_COUNTS
|
||||
|
||||
/* In SunOS 4.1.2, 4.1.3, and 4.1.3_U1, the block counts in the
|
||||
struct statfs are truncated to 2GB. These conditions detect that
|
||||
truncation, presumably without botching the 4.1.1 case, in which
|
||||
the values are not truncated. The correct counts are stored in
|
||||
undocumented spare fields. */
|
||||
if (fsd.f_blocks == 0x1fffff && fsd.f_spare[0] > 0)
|
||||
{
|
||||
fsd.f_blocks = fsd.f_spare[0];
|
||||
fsd.f_bfree = fsd.f_spare[1];
|
||||
fsd.f_bavail = fsd.f_spare[2];
|
||||
}
|
||||
# endif /* STATFS_TRUNCATES_BLOCK_COUNTS */
|
||||
|
||||
#endif /* STAT_STATFS2_BSIZE */
|
||||
|
||||
#ifdef STAT_STATFS2_FSIZE /* 4.4BSD */
|
||||
# define CONVERT_BLOCKS(B) adjust_blocks ((B), fsd.f_fsize, 512)
|
||||
|
||||
struct statfs fsd;
|
||||
|
||||
if (statfs (path, &fsd) < 0)
|
||||
return -1;
|
||||
|
||||
#endif /* STAT_STATFS2_FSIZE */
|
||||
|
||||
#ifdef STAT_STATFS4 /* SVR3, Dynix, Irix, AIX */
|
||||
# if _AIX || defined(_CRAY)
|
||||
# define CONVERT_BLOCKS(B) adjust_blocks ((B), fsd.f_bsize, 512)
|
||||
# ifdef _CRAY
|
||||
# define f_bavail f_bfree
|
||||
# endif
|
||||
# else
|
||||
# define CONVERT_BLOCKS(B) (B)
|
||||
# ifndef _SEQUENT_ /* _SEQUENT_ is DYNIX/ptx */
|
||||
# ifndef DOLPHIN /* DOLPHIN 3.8.alfa/7.18 has f_bavail */
|
||||
# define f_bavail f_bfree
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
|
||||
struct statfs fsd;
|
||||
|
||||
if (statfs (path, &fsd, sizeof fsd, 0) < 0)
|
||||
return -1;
|
||||
/* Empirically, the block counts on most SVR3 and SVR3-derived
|
||||
systems seem to always be in terms of 512-byte blocks,
|
||||
no matter what value f_bsize has. */
|
||||
|
||||
#endif /* STAT_STATFS4 */
|
||||
|
||||
#ifdef STAT_STATVFS /* SVR4 */
|
||||
# define CONVERT_BLOCKS(B) \
|
||||
adjust_blocks ((B), fsd.f_frsize ? fsd.f_frsize : fsd.f_bsize, 512)
|
||||
|
||||
struct statvfs fsd;
|
||||
|
||||
if (statvfs (path, &fsd) < 0)
|
||||
return -1;
|
||||
/* f_frsize isn't guaranteed to be supported. */
|
||||
|
||||
#endif /* STAT_STATVFS */
|
||||
|
||||
#if !defined(STAT_STATFS2_FS_DATA) && !defined(STAT_READ_FILSYS)
|
||||
/* !Ultrix && !SVR2 */
|
||||
|
||||
fsp->fsu_blocks = CONVERT_BLOCKS (fsd.f_blocks);
|
||||
fsp->fsu_bfree = CONVERT_BLOCKS (fsd.f_bfree);
|
||||
fsp->fsu_bavail = CONVERT_BLOCKS (fsd.f_bavail);
|
||||
fsp->fsu_files = fsd.f_files;
|
||||
fsp->fsu_ffree = fsd.f_ffree;
|
||||
|
||||
#endif /* not STAT_STATFS2_FS_DATA && not STAT_READ_FILSYS */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(_AIX) && defined(_I386)
|
||||
/* AIX PS/2 does not supply statfs. */
|
||||
|
||||
int
|
||||
statfs (path, fsb)
|
||||
char *path;
|
||||
struct statfs *fsb;
|
||||
{
|
||||
struct stat stats;
|
||||
struct dustat fsd;
|
||||
|
||||
if (stat (path, &stats))
|
||||
return -1;
|
||||
if (dustat (stats.st_dev, 0, &fsd, sizeof (fsd)))
|
||||
return -1;
|
||||
fsb->f_type = 0;
|
||||
fsb->f_bsize = fsd.du_bsize;
|
||||
fsb->f_blocks = fsd.du_fsize - fsd.du_isize;
|
||||
fsb->f_bfree = fsd.du_tfree;
|
||||
fsb->f_bavail = fsd.du_tfree;
|
||||
fsb->f_files = (fsd.du_isize - 2) * fsd.du_inopb;
|
||||
fsb->f_ffree = fsd.du_tinode;
|
||||
fsb->f_fsid.val[0] = fsd.du_site;
|
||||
fsb->f_fsid.val[1] = fsd.du_pckno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* _AIX && _I386 */
|
37
sysdeps/common/fsusage.h
Normal file
37
sysdeps/common/fsusage.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/* fsusage.h -- declarations for filesystem space usage info
|
||||
Copyright (C) 1991, 1992 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Space usage statistics for a filesystem. Blocks are 512-byte. */
|
||||
struct fs_usage
|
||||
{
|
||||
long fsu_blocks; /* Total blocks. */
|
||||
long fsu_bfree; /* Free blocks available to superuser. */
|
||||
long fsu_bavail; /* Free blocks available to non-superuser. */
|
||||
long fsu_files; /* Total file nodes. */
|
||||
long fsu_ffree; /* Free file nodes. */
|
||||
};
|
||||
|
||||
#ifndef __P
|
||||
#if defined (__GNUC__) || (defined (__STDC__) && __STDC__)
|
||||
#define __P(args) args
|
||||
#else
|
||||
#define __P(args) ()
|
||||
#endif /* GCC. */
|
||||
#endif /* Not __P. */
|
||||
|
||||
int get_fs_usage __P ((const char *path, const char *disk,
|
||||
struct fs_usage *fsp));
|
@@ -33,8 +33,9 @@
|
||||
static char rcsid [] = "!Header: gnuslib.c,v 2.4 95/02/16 11:57:37 arup alpha !";
|
||||
#endif
|
||||
|
||||
#include "gnuserv.h"
|
||||
#include <errno.h>
|
||||
#include <glibtop/gnuserv.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifdef SYSV_IPC
|
||||
static int connect_to_ipc_server (void);
|
||||
@@ -43,7 +44,7 @@ static int connect_to_ipc_server (void);
|
||||
static int connect_to_unix_server (void);
|
||||
#endif
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
static int connect_to_internet_server (char *serverhost, u_short port);
|
||||
static int connect_to_internet_server (const char *serverhost, u_short port);
|
||||
#endif
|
||||
|
||||
/* On some systems, e.g. DGUX, inet_addr returns a 'struct in_addr'. */
|
||||
@@ -59,45 +60,33 @@ static int connect_to_internet_server (char *serverhost, u_short port);
|
||||
# define NUMERIC_ADDR_ERROR (numeric_addr == (IN_ADDR) -1)
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif /* HAVE_UNISTD_H */
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif /* HAVE_STRING_H */
|
||||
|
||||
#include <arpa/inet.h>
|
||||
|
||||
char *progname = NULL;
|
||||
|
||||
int make_connection(hostarg, portarg, s)
|
||||
char *hostarg;
|
||||
int
|
||||
glibtop_make_connection (hostarg, portarg, s)
|
||||
const char *hostarg;
|
||||
int portarg;
|
||||
int *s;
|
||||
{
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
char *ptr;
|
||||
if (hostarg == NULL)
|
||||
hostarg = getenv("GNU_HOST");
|
||||
if (portarg == 0 && (ptr=getenv("GNU_PORT")) != NULL)
|
||||
portarg = atoi(ptr);
|
||||
hostarg = getenv ("LIBGTOP_HOST");
|
||||
if (portarg == 0 && (ptr = getenv("LIBGTOP_PORT")) != NULL)
|
||||
portarg = atoi (ptr);
|
||||
#endif
|
||||
|
||||
if (hostarg != NULL) {
|
||||
/* hostname was given explicitly, via cmd line arg or GNU_HOST,
|
||||
/* hostname was given explicitly, via cmd line arg or LIBGTOP_HOST,
|
||||
* so obey it. */
|
||||
#ifdef UNIX_DOMAIN_SOCKETS
|
||||
if (!strcmp(hostarg, "unix")) {
|
||||
*s = connect_to_unix_server();
|
||||
if (!strcmp (hostarg, "unix")) {
|
||||
*s = connect_to_unix_server ();
|
||||
return (int) CONN_UNIX;
|
||||
}
|
||||
#endif /* UNIX_DOMAIN_SOCKETS */
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
*s = connect_to_internet_server(hostarg, portarg);
|
||||
*s = connect_to_internet_server (hostarg, portarg);
|
||||
return (int) CONN_INTERNET;
|
||||
#endif
|
||||
#ifdef SYSV_IPC
|
||||
@@ -107,16 +96,16 @@ int make_connection(hostarg, portarg, s)
|
||||
/* no hostname given. Use unix-domain/sysv-ipc, or
|
||||
* internet-domain connection to local host if they're not available. */
|
||||
#if defined(UNIX_DOMAIN_SOCKETS)
|
||||
*s = connect_to_unix_server();
|
||||
*s = connect_to_unix_server ();
|
||||
return (int) CONN_UNIX;
|
||||
#elif defined(SYSV_IPC)
|
||||
*s = connect_to_ipc_server();
|
||||
*s = connect_to_ipc_server ();
|
||||
return (int) CONN_IPC;
|
||||
#elif defined(INTERNET_DOMAIN_SOCKETS)
|
||||
{
|
||||
char localhost[HOSTNAMSZ];
|
||||
gethostname(localhost,HOSTNAMSZ); /* use this host by default */
|
||||
*s = connect_to_internet_server(localhost, portarg);
|
||||
char localhost [HOSTNAMSZ];
|
||||
gethostname (localhost, HOSTNAMSZ); /* use this host by default */
|
||||
*s = connect_to_internet_server (localhost, portarg);
|
||||
return (int) CONN_INTERNET;
|
||||
}
|
||||
#endif /* IPC type */
|
||||
@@ -128,26 +117,20 @@ int make_connection(hostarg, portarg, s)
|
||||
connect_to_ipc_server -- establish connection with server process via SYSV IPC
|
||||
Returns msqid for server if successful.
|
||||
*/
|
||||
static int connect_to_ipc_server (void)
|
||||
static int
|
||||
connect_to_ipc_server (void)
|
||||
{
|
||||
int s; /* connected msqid */
|
||||
key_t key; /* message key */
|
||||
char buf[GSERV_BUFSZ+1]; /* buffer for filename */
|
||||
char buf [GSERV_BUFSZ+1]; /* buffer for filename */
|
||||
|
||||
sprintf(buf,"/tmp/gsrv%d",(int)geteuid());
|
||||
creat(buf,0600);
|
||||
if ((key = ftok(buf,1)) == -1) {
|
||||
perror(progname);
|
||||
fprintf(stderr, "%s: unable to get ipc key from %s\n",
|
||||
progname, buf);
|
||||
exit(1);
|
||||
}
|
||||
sprintf (buf, "/tmp/lgtd%d", (int)geteuid());
|
||||
creat (buf, 0600);
|
||||
if ((key = ftok (buf, 1)) == -1)
|
||||
glibtop_error_io ("unable to get ipc key from %s", buf);
|
||||
|
||||
if ((s = msgget(key,0600)) == -1) {
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to access msg queue\n",progname);
|
||||
exit(1);
|
||||
}; /* if */
|
||||
if ((s = msgget (key, 0600)) == -1)
|
||||
glibtop_error_io ("unable to access msg queue");
|
||||
|
||||
return(s);
|
||||
|
||||
@@ -194,7 +177,9 @@ void disconnect_from_ipc_server(s,msgp,echo)
|
||||
/*
|
||||
send_string -- send string to socket.
|
||||
*/
|
||||
void send_string(s,msg)
|
||||
#if 0
|
||||
static void
|
||||
send_string(s,msg)
|
||||
int s;
|
||||
const char *msg;
|
||||
{
|
||||
@@ -225,7 +210,8 @@ void send_string(s,msg)
|
||||
/*
|
||||
read_line -- read a \n terminated line from a socket
|
||||
*/
|
||||
int read_line(int s, char *dest)
|
||||
static int
|
||||
read_line(int s, char *dest)
|
||||
{
|
||||
int length;
|
||||
int offset=0;
|
||||
@@ -241,6 +227,7 @@ int read_line(int s, char *dest)
|
||||
strcpy(dest,buffer);
|
||||
return 1;
|
||||
} /* read_line */
|
||||
#endif
|
||||
#endif /* INTERNET_DOMAIN_SOCKETS || UNIX_DOMAIN_SOCKETS */
|
||||
|
||||
|
||||
@@ -250,28 +237,23 @@ int read_line(int s, char *dest)
|
||||
domain socket. Returns socket descriptor for server
|
||||
if successful.
|
||||
*/
|
||||
static int connect_to_unix_server (void)
|
||||
static int
|
||||
connect_to_unix_server (void)
|
||||
{
|
||||
int s; /* connected socket descriptor */
|
||||
struct sockaddr_un server; /* for unix connections */
|
||||
|
||||
if ((s = socket(AF_UNIX,SOCK_STREAM,0)) < 0) {
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to create socket\n",progname);
|
||||
exit(1);
|
||||
}; /* if */
|
||||
if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) < 0)
|
||||
glibtop_error_io ("unable to create socket");
|
||||
|
||||
server.sun_family = AF_UNIX;
|
||||
#ifdef HIDE_UNIX_SOCKET
|
||||
sprintf(server.sun_path,"/tmp/gsrvdir%d/gsrv",(int)geteuid());
|
||||
sprintf(server.sun_path, "/tmp/lgtddir%d/lgtd", (int)geteuid());
|
||||
#else /* HIDE_UNIX_SOCKET */
|
||||
sprintf(server.sun_path,"/tmp/gsrv%d",(int)geteuid());
|
||||
sprintf(server.sun_path, "/tmp/lgtd%d", (int)geteuid());
|
||||
#endif /* HIDE_UNIX_SOCKET */
|
||||
if (connect(s,(struct sockaddr *)&server,strlen(server.sun_path)+2) < 0) {
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to connect to local\n",progname);
|
||||
exit(1);
|
||||
}; /* if */
|
||||
if (connect (s, (struct sockaddr *)&server, strlen(server.sun_path)+2) < 0)
|
||||
glibtop_error_io ("unable to connect to local");
|
||||
|
||||
return(s);
|
||||
|
||||
@@ -284,8 +266,8 @@ static int connect_to_unix_server (void)
|
||||
internet_addr -- return the internet addr of the hostname or
|
||||
internet address passed. Return -1 on error.
|
||||
*/
|
||||
int internet_addr(host)
|
||||
char *host;
|
||||
long glibtop_internet_addr (host)
|
||||
const char *host;
|
||||
{
|
||||
struct hostent *hp; /* pointer to host info for remote host */
|
||||
IN_ADDR numeric_addr; /* host address */
|
||||
@@ -300,7 +282,7 @@ int internet_addr(host)
|
||||
return -1;
|
||||
}
|
||||
|
||||
} /* internet_addr */
|
||||
} /* glibtop_internet_addr */
|
||||
|
||||
#ifdef AUTH_MAGIC_COOKIE
|
||||
# include <X11/X.h>
|
||||
@@ -314,7 +296,8 @@ static Xauth *server_xauth = NULL;
|
||||
an internet domain socket. Returns socket
|
||||
descriptor for server if successful.
|
||||
*/
|
||||
static int connect_to_internet_server (char *serverhost, u_short port)
|
||||
static int
|
||||
connect_to_internet_server (const char *serverhost, u_short port)
|
||||
{
|
||||
int s; /* connected socket descriptor */
|
||||
struct servent *sp; /* pointer to service information */
|
||||
@@ -322,43 +305,34 @@ static int connect_to_internet_server (char *serverhost, u_short port)
|
||||
char buf[512]; /* temporary buffer */
|
||||
|
||||
/* clear out address structures */
|
||||
memset((char *)&peeraddr_in,0,sizeof(struct sockaddr_in));
|
||||
memset((char *)&peeraddr_in, 0, sizeof(struct sockaddr_in));
|
||||
|
||||
/* Set up the peer address to which we will connect. */
|
||||
peeraddr_in.sin_family = AF_INET;
|
||||
|
||||
/* look up the server host's internet address */
|
||||
if ((peeraddr_in.sin_addr.s_addr = internet_addr(serverhost)) == -1) {
|
||||
fprintf(stderr,"%s: unable to find %s in /etc/hosts or from YP\n",
|
||||
progname,serverhost);
|
||||
exit(1);
|
||||
}; /* if */
|
||||
if (((long) peeraddr_in.sin_addr.s_addr = glibtop_internet_addr (serverhost)) == -1)
|
||||
glibtop_error ("unable to find %s in /etc/hosts or from YP", serverhost);
|
||||
|
||||
if (port == 0) {
|
||||
if ((sp = getservbyname ("gnuserv","tcp")) == NULL)
|
||||
peeraddr_in.sin_port = htons(DEFAULT_PORT+getuid());
|
||||
if ((sp = getservbyname ("gtopd","tcp")) == NULL)
|
||||
peeraddr_in.sin_port = htons (DEFAULT_PORT+getuid());
|
||||
else
|
||||
peeraddr_in.sin_port = sp->s_port;
|
||||
} /* if */
|
||||
else
|
||||
peeraddr_in.sin_port = htons(port);
|
||||
peeraddr_in.sin_port = htons (port);
|
||||
|
||||
/* Create the socket. */
|
||||
if ((s = socket (AF_INET,SOCK_STREAM, 0))== -1) {
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to create socket\n",progname);
|
||||
exit(1);
|
||||
}; /* if */
|
||||
if ((s = socket (AF_INET, SOCK_STREAM, 0))== -1)
|
||||
glibtop_error_io ("unable to create socket");
|
||||
|
||||
/* Try to connect to the remote server at the address
|
||||
* which was just built into peeraddr.
|
||||
*/
|
||||
if (connect(s, (struct sockaddr *)&peeraddr_in,
|
||||
sizeof(struct sockaddr_in)) == -1) {
|
||||
perror(progname);
|
||||
fprintf(stderr, "%s: unable to connect to remote\n",progname);
|
||||
exit(1);
|
||||
}; /* if */
|
||||
sizeof(struct sockaddr_in)) == -1)
|
||||
glibtop_error_io ("unable to connect to remote");
|
||||
|
||||
#ifdef AUTH_MAGIC_COOKIE
|
||||
|
||||
@@ -375,7 +349,7 @@ static int connect_to_internet_server (char *serverhost, u_short port)
|
||||
sprintf(buf, "%s\n%d\n", MCOOKIE_NAME, server_xauth->data_length);
|
||||
write (s, buf, strlen(buf));
|
||||
write (s, server_xauth->data, server_xauth->data_length);
|
||||
|
||||
|
||||
return (s);
|
||||
}
|
||||
|
||||
@@ -395,7 +369,9 @@ static int connect_to_internet_server (char *serverhost, u_short port)
|
||||
disconnect_from_server -- inform the server that sending has finished, and wait for
|
||||
its reply.
|
||||
*/
|
||||
void disconnect_from_server(s,echo)
|
||||
#if 0
|
||||
static void
|
||||
disconnect_from_server(s,echo)
|
||||
int s;
|
||||
int echo;
|
||||
{
|
||||
@@ -453,4 +429,5 @@ void disconnect_from_server(s,echo)
|
||||
}; /* if */
|
||||
|
||||
} /* disconnect_from_server */
|
||||
#endif
|
||||
#endif /* INTERNET_DOMAIN_SOCKETS || UNIX_DOMAIN_SOCKETS */
|
||||
|
577
sysdeps/common/mountlist.c
Normal file
577
sysdeps/common/mountlist.c
Normal file
@@ -0,0 +1,577 @@
|
||||
/* mountlist.c -- return a list of mounted filesystems
|
||||
Copyright (C) 1991, 1992 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include "mountlist.h"
|
||||
|
||||
#ifdef STDC_HEADERS
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
void free ();
|
||||
#endif
|
||||
#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
|
||||
#include <string.h>
|
||||
#else
|
||||
#include <strings.h>
|
||||
#endif
|
||||
|
||||
char *strstr ();
|
||||
char *xmalloc ();
|
||||
char *xrealloc ();
|
||||
char *xstrdup ();
|
||||
void error ();
|
||||
|
||||
#ifdef HAVE_SYS_PARAM_H
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#if defined (MOUNTED_GETFSSTAT) /* __alpha running OSF_1 */
|
||||
# include <sys/mount.h>
|
||||
# include <sys/fs_types.h>
|
||||
#endif /* MOUNTED_GETFSSTAT */
|
||||
|
||||
#ifdef MOUNTED_GETMNTENT1 /* 4.3BSD, SunOS, HP-UX, Dynix, Irix. */
|
||||
#include <mntent.h>
|
||||
#if !defined(MOUNTED)
|
||||
# if defined(MNT_MNTTAB) /* HP-UX. */
|
||||
# define MOUNTED MNT_MNTTAB
|
||||
# endif
|
||||
# if defined(MNTTABNAME) /* Dynix. */
|
||||
# define MOUNTED MNTTABNAME
|
||||
# endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef MOUNTED_GETMNTINFO /* 4.4BSD. */
|
||||
#include <sys/mount.h>
|
||||
#endif
|
||||
|
||||
#ifdef MOUNTED_GETMNT /* Ultrix. */
|
||||
#include <sys/mount.h>
|
||||
#include <sys/fs_types.h>
|
||||
#endif
|
||||
|
||||
#ifdef MOUNTED_FREAD /* SVR2. */
|
||||
#include <mnttab.h>
|
||||
#endif
|
||||
|
||||
#ifdef MOUNTED_FREAD_FSTYP /* SVR3. */
|
||||
#include <mnttab.h>
|
||||
#include <sys/fstyp.h>
|
||||
#include <sys/statfs.h>
|
||||
#endif
|
||||
|
||||
#ifdef MOUNTED_LISTMNTENT
|
||||
#include <mntent.h>
|
||||
#endif
|
||||
|
||||
#ifdef MOUNTED_GETMNTENT2 /* SVR4. */
|
||||
#include <sys/mnttab.h>
|
||||
#endif
|
||||
|
||||
#ifdef MOUNTED_VMOUNT /* AIX. */
|
||||
#include <fshelp.h>
|
||||
#include <sys/vfs.h>
|
||||
#endif
|
||||
|
||||
#ifdef DOLPHIN
|
||||
/* So special that it's not worth putting this in autoconf. */
|
||||
#undef MOUNTED_FREAD_FSTYP
|
||||
#define MOUNTED_GETMNTTBL
|
||||
#endif
|
||||
|
||||
#ifdef MOUNTED_GETMNTENT1 /* 4.3BSD, SunOS, HP-UX, Dynix, Irix. */
|
||||
/* Return the value of the hexadecimal number represented by CP.
|
||||
No prefix (like '0x') or suffix (like 'h') is expected to be
|
||||
part of CP. */
|
||||
|
||||
static int
|
||||
xatoi (cp)
|
||||
char *cp;
|
||||
{
|
||||
int val;
|
||||
|
||||
val = 0;
|
||||
while (*cp)
|
||||
{
|
||||
if (*cp >= 'a' && *cp <= 'f')
|
||||
val = val * 16 + *cp - 'a' + 10;
|
||||
else if (*cp >= 'A' && *cp <= 'F')
|
||||
val = val * 16 + *cp - 'A' + 10;
|
||||
else if (*cp >= '0' && *cp <= '9')
|
||||
val = val * 16 + *cp - '0';
|
||||
else
|
||||
break;
|
||||
cp++;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
#endif /* MOUNTED_GETMNTENT1. */
|
||||
|
||||
#if defined (MOUNTED_GETMNTINFO) && !defined (__NetBSD__)
|
||||
static char *
|
||||
fstype_to_string (t)
|
||||
short t;
|
||||
{
|
||||
switch (t)
|
||||
{
|
||||
#ifdef MOUNT_PC
|
||||
case MOUNT_PC:
|
||||
return "pc";
|
||||
#endif
|
||||
#ifdef MOUNT_MFS
|
||||
case MOUNT_MFS:
|
||||
return "mfs";
|
||||
#endif
|
||||
#ifdef MOUNT_LO
|
||||
case MOUNT_LO:
|
||||
return "lo";
|
||||
#endif
|
||||
#ifdef MOUNT_TFS
|
||||
case MOUNT_TFS:
|
||||
return "tfs";
|
||||
#endif
|
||||
#ifdef MOUNT_TMP
|
||||
case MOUNT_TMP:
|
||||
return "tmp";
|
||||
#endif
|
||||
#ifdef MOUNT_UFS
|
||||
case MOUNT_UFS:
|
||||
return "ufs" ;
|
||||
#endif
|
||||
#ifdef MOUNT_NFS
|
||||
case MOUNT_NFS:
|
||||
return "nfs" ;
|
||||
#endif
|
||||
#ifdef MOUNT_MSDOS
|
||||
case MOUNT_MSDOS:
|
||||
return "msdos" ;
|
||||
#endif
|
||||
#ifdef MOUNT_LFS
|
||||
case MOUNT_LFS:
|
||||
return "lfs" ;
|
||||
#endif
|
||||
#ifdef MOUNT_LOFS
|
||||
case MOUNT_LOFS:
|
||||
return "lofs" ;
|
||||
#endif
|
||||
#ifdef MOUNT_FDESC
|
||||
case MOUNT_FDESC:
|
||||
return "fdesc" ;
|
||||
#endif
|
||||
#ifdef MOUNT_PORTAL
|
||||
case MOUNT_PORTAL:
|
||||
return "portal" ;
|
||||
#endif
|
||||
#ifdef MOUNT_NULL
|
||||
case MOUNT_NULL:
|
||||
return "null" ;
|
||||
#endif
|
||||
#ifdef MOUNT_UMAP
|
||||
case MOUNT_UMAP:
|
||||
return "umap" ;
|
||||
#endif
|
||||
#ifdef MOUNT_KERNFS
|
||||
case MOUNT_KERNFS:
|
||||
return "kernfs" ;
|
||||
#endif
|
||||
#ifdef MOUNT_PROCFS
|
||||
case MOUNT_PROCFS:
|
||||
return "procfs" ;
|
||||
#endif
|
||||
#ifdef MOUNT_AFS
|
||||
case MOUNT_AFS:
|
||||
return "afs" ;
|
||||
#endif
|
||||
#ifdef MOUNT_CD9660
|
||||
case MOUNT_CD9660:
|
||||
return "cd9660" ;
|
||||
#endif
|
||||
#ifdef MOUNT_UNION
|
||||
case MOUNT_UNION:
|
||||
return "union" ;
|
||||
#endif
|
||||
#ifdef MOUNT_DEVFS
|
||||
case MOUNT_DEVFS:
|
||||
return "devfs" ;
|
||||
#endif
|
||||
#ifdef MOUNT_EXT2FS
|
||||
case MOUNT_EXT2FS:
|
||||
return "ext2fs" ;
|
||||
#endif
|
||||
default:
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
#endif /* MOUNTED_GETMNTINFO */
|
||||
|
||||
#ifdef MOUNTED_VMOUNT /* AIX. */
|
||||
static char *
|
||||
fstype_to_string (t)
|
||||
int t;
|
||||
{
|
||||
struct vfs_ent *e;
|
||||
|
||||
e = getvfsbytype (t);
|
||||
if (!e || !e->vfsent_name)
|
||||
return "none";
|
||||
else
|
||||
return e->vfsent_name;
|
||||
}
|
||||
#endif /* MOUNTED_VMOUNT */
|
||||
|
||||
/* Return a list of the currently mounted filesystems, or NULL on error.
|
||||
Add each entry to the tail of the list so that they stay in order.
|
||||
If NEED_FS_TYPE is nonzero, ensure that the filesystem type fields in
|
||||
the returned list are valid. Otherwise, they might not be.
|
||||
If ALL_FS is zero, do not return entries for filesystems that
|
||||
are automounter (dummy) entries. */
|
||||
|
||||
struct mount_entry *
|
||||
read_filesystem_list (need_fs_type, all_fs)
|
||||
int need_fs_type, all_fs;
|
||||
{
|
||||
struct mount_entry *mount_list;
|
||||
struct mount_entry *me;
|
||||
struct mount_entry *mtail;
|
||||
|
||||
/* Start the list off with a dummy entry. */
|
||||
me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
|
||||
me->me_next = NULL;
|
||||
mount_list = mtail = me;
|
||||
|
||||
#ifdef MOUNTED_LISTMNTENT
|
||||
{
|
||||
struct tabmntent *mntlist, *p;
|
||||
struct mntent *mnt;
|
||||
struct mount_entry *me;
|
||||
|
||||
/* the third and fourth arguments could be used to filter mounts,
|
||||
but Crays doesn't seem to have any mounts that we want to
|
||||
remove. Specifically, automount create normal NFS mounts.
|
||||
*/
|
||||
|
||||
if(listmntent(&mntlist, KMTAB, NULL, NULL) < 0)
|
||||
return NULL;
|
||||
p = mntlist;
|
||||
while(p){
|
||||
mnt = p->ment;
|
||||
me = (struct mount_entry*) xmalloc(sizeof (struct mount_entry));
|
||||
me->me_devname = xstrdup(mnt->mnt_fsname);
|
||||
me->me_mountdir = xstrdup(mnt->mnt_dir);
|
||||
me->me_type = xstrdup(mnt->mnt_type);
|
||||
me->me_dev = -1;
|
||||
me->me_next = NULL;
|
||||
mtail->me_next = me;
|
||||
mtail = me;
|
||||
p = p->next;
|
||||
}
|
||||
freemntlist(mntlist);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef MOUNTED_GETMNTENT1 /* 4.3BSD, SunOS, HP-UX, Dynix, Irix. */
|
||||
{
|
||||
struct mntent *mnt;
|
||||
char *table = MOUNTED;
|
||||
FILE *fp;
|
||||
char *devopt;
|
||||
|
||||
fp = setmntent (table, "r");
|
||||
if (fp == NULL)
|
||||
return NULL;
|
||||
|
||||
while ((mnt = getmntent (fp)))
|
||||
{
|
||||
if (!all_fs && (!strcmp (mnt->mnt_type, "ignore")
|
||||
|| !strcmp (mnt->mnt_type, "auto")))
|
||||
continue;
|
||||
|
||||
me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
|
||||
me->me_devname = xstrdup (mnt->mnt_fsname);
|
||||
me->me_mountdir = xstrdup (mnt->mnt_dir);
|
||||
me->me_type = xstrdup (mnt->mnt_type);
|
||||
devopt = strstr (mnt->mnt_opts, "dev=");
|
||||
if (devopt)
|
||||
{
|
||||
if (devopt[4] == '0' && (devopt[5] == 'x' || devopt[5] == 'X'))
|
||||
me->me_dev = xatoi (devopt + 6);
|
||||
else
|
||||
me->me_dev = xatoi (devopt + 4);
|
||||
}
|
||||
else
|
||||
me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
|
||||
me->me_next = NULL;
|
||||
|
||||
/* Add to the linked list. */
|
||||
mtail->me_next = me;
|
||||
mtail = me;
|
||||
}
|
||||
|
||||
if (endmntent (fp) == 0)
|
||||
return NULL;
|
||||
}
|
||||
#endif /* MOUNTED_GETMNTENT1. */
|
||||
|
||||
#ifdef MOUNTED_GETMNTINFO /* 4.4BSD. */
|
||||
{
|
||||
struct statfs *fsp;
|
||||
int entries;
|
||||
|
||||
entries = getmntinfo (&fsp, MNT_NOWAIT);
|
||||
if (entries < 0)
|
||||
return NULL;
|
||||
while (entries-- > 0)
|
||||
{
|
||||
me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
|
||||
me->me_devname = xstrdup (fsp->f_mntfromname);
|
||||
me->me_mountdir = xstrdup (fsp->f_mntonname);
|
||||
#ifdef __NetBSD__
|
||||
me->me_type = xstrdup (fsp->f_fstypename);
|
||||
#else
|
||||
me->me_type = fstype_to_string (fsp->f_type);
|
||||
#endif
|
||||
me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
|
||||
me->me_next = NULL;
|
||||
|
||||
/* Add to the linked list. */
|
||||
mtail->me_next = me;
|
||||
mtail = me;
|
||||
fsp++;
|
||||
}
|
||||
}
|
||||
#endif /* MOUNTED_GETMNTINFO */
|
||||
|
||||
#ifdef MOUNTED_GETMNT /* Ultrix. */
|
||||
{
|
||||
int offset = 0;
|
||||
int val;
|
||||
struct fs_data fsd;
|
||||
|
||||
while ((val = getmnt (&offset, &fsd, sizeof (fsd), NOSTAT_MANY,
|
||||
(char *) 0)) > 0)
|
||||
{
|
||||
me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
|
||||
me->me_devname = xstrdup (fsd.fd_req.devname);
|
||||
me->me_mountdir = xstrdup (fsd.fd_req.path);
|
||||
me->me_type = gt_names[fsd.fd_req.fstype];
|
||||
me->me_dev = fsd.fd_req.dev;
|
||||
me->me_next = NULL;
|
||||
|
||||
/* Add to the linked list. */
|
||||
mtail->me_next = me;
|
||||
mtail = me;
|
||||
}
|
||||
if (val < 0)
|
||||
return NULL;
|
||||
}
|
||||
#endif /* MOUNTED_GETMNT. */
|
||||
|
||||
#if defined (MOUNTED_GETFSSTAT) /* __alpha running OSF_1 */
|
||||
{
|
||||
int numsys, counter, bufsize;
|
||||
struct statfs *stats;
|
||||
|
||||
numsys = getfsstat ((struct statfs *)0, 0L, MNT_WAIT);
|
||||
if (numsys < 0)
|
||||
return (NULL);
|
||||
|
||||
bufsize = (1 + numsys) * sizeof (struct statfs);
|
||||
stats = (struct statfs *)xmalloc (bufsize);
|
||||
numsys = getfsstat (stats, bufsize, MNT_WAIT);
|
||||
|
||||
if (numsys < 0)
|
||||
{
|
||||
free (stats);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
for (counter = 0; counter < numsys; counter++)
|
||||
{
|
||||
me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
|
||||
me->me_devname = xstrdup (stats[counter].f_mntfromname);
|
||||
me->me_mountdir = xstrdup (stats[counter].f_mntonname);
|
||||
me->me_type = mnt_names[stats[counter].f_type];
|
||||
me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
|
||||
me->me_next = NULL;
|
||||
|
||||
/* Add to the linked list. */
|
||||
mtail->me_next = me;
|
||||
mtail = me;
|
||||
}
|
||||
|
||||
free (stats);
|
||||
}
|
||||
#endif /* MOUNTED_GETFSSTAT */
|
||||
|
||||
#if defined (MOUNTED_FREAD) || defined (MOUNTED_FREAD_FSTYP) /* SVR[23]. */
|
||||
{
|
||||
struct mnttab mnt;
|
||||
char *table = "/etc/mnttab";
|
||||
FILE *fp;
|
||||
|
||||
fp = fopen (table, "r");
|
||||
if (fp == NULL)
|
||||
return NULL;
|
||||
|
||||
while (fread (&mnt, sizeof mnt, 1, fp) > 0)
|
||||
{
|
||||
me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
|
||||
#ifdef GETFSTYP /* SVR3. */
|
||||
me->me_devname = xstrdup (mnt.mt_dev);
|
||||
#else
|
||||
me->me_devname = xmalloc (strlen (mnt.mt_dev) + 6);
|
||||
strcpy (me->me_devname, "/dev/");
|
||||
strcpy (me->me_devname + 5, mnt.mt_dev);
|
||||
#endif
|
||||
me->me_mountdir = xstrdup (mnt.mt_filsys);
|
||||
me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
|
||||
me->me_type = "";
|
||||
#ifdef GETFSTYP /* SVR3. */
|
||||
if (need_fs_type)
|
||||
{
|
||||
struct statfs fsd;
|
||||
char typebuf[FSTYPSZ];
|
||||
|
||||
if (statfs (me->me_mountdir, &fsd, sizeof fsd, 0) != -1
|
||||
&& sysfs (GETFSTYP, fsd.f_fstyp, typebuf) != -1)
|
||||
me->me_type = xstrdup (typebuf);
|
||||
}
|
||||
#endif
|
||||
me->me_next = NULL;
|
||||
|
||||
/* Add to the linked list. */
|
||||
mtail->me_next = me;
|
||||
mtail = me;
|
||||
}
|
||||
|
||||
if (fclose (fp) == EOF)
|
||||
return NULL;
|
||||
}
|
||||
#endif /* MOUNTED_FREAD || MOUNTED_FREAD_FSTYP. */
|
||||
|
||||
#ifdef MOUNTED_GETMNTTBL /* DolphinOS goes it's own way */
|
||||
{
|
||||
struct mntent **mnttbl=getmnttbl(),**ent;
|
||||
for (ent=mnttbl;*ent;ent++)
|
||||
{
|
||||
me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
|
||||
me->me_devname = xstrdup ( (*ent)->mt_resource);
|
||||
me->me_mountdir = xstrdup( (*ent)->mt_directory);
|
||||
me->me_type = xstrdup ((*ent)->mt_fstype);
|
||||
me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
|
||||
me->me_next = NULL;
|
||||
|
||||
/* Add to the linked list. */
|
||||
mtail->me_next = me;
|
||||
mtail = me;
|
||||
}
|
||||
endmnttbl();
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef MOUNTED_GETMNTENT2 /* SVR4. */
|
||||
{
|
||||
struct mnttab mnt;
|
||||
char *table = MNTTAB;
|
||||
FILE *fp;
|
||||
int ret;
|
||||
|
||||
fp = fopen (table, "r");
|
||||
if (fp == NULL)
|
||||
return NULL;
|
||||
|
||||
while ((ret = getmntent (fp, &mnt)) == 0)
|
||||
{
|
||||
me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
|
||||
me->me_devname = xstrdup (mnt.mnt_special);
|
||||
me->me_mountdir = xstrdup (mnt.mnt_mountp);
|
||||
me->me_type = xstrdup (mnt.mnt_fstype);
|
||||
me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
|
||||
me->me_next = NULL;
|
||||
|
||||
/* Add to the linked list. */
|
||||
mtail->me_next = me;
|
||||
mtail = me;
|
||||
}
|
||||
|
||||
if (ret > 0)
|
||||
return NULL;
|
||||
if (fclose (fp) == EOF)
|
||||
return NULL;
|
||||
}
|
||||
#endif /* MOUNTED_GETMNTENT2. */
|
||||
|
||||
#ifdef MOUNTED_VMOUNT /* AIX. */
|
||||
{
|
||||
int bufsize;
|
||||
char *entries, *thisent;
|
||||
struct vmount *vmp;
|
||||
|
||||
/* Ask how many bytes to allocate for the mounted filesystem info. */
|
||||
mntctl (MCTL_QUERY, sizeof bufsize, (struct vmount *) &bufsize);
|
||||
entries = xmalloc (bufsize);
|
||||
|
||||
/* Get the list of mounted filesystems. */
|
||||
mntctl (MCTL_QUERY, bufsize, (struct vmount *) entries);
|
||||
|
||||
for (thisent = entries; thisent < entries + bufsize;
|
||||
thisent += vmp->vmt_length)
|
||||
{
|
||||
vmp = (struct vmount *) thisent;
|
||||
me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
|
||||
if (vmp->vmt_flags & MNT_REMOTE)
|
||||
{
|
||||
char *host, *path;
|
||||
|
||||
/* Prepend the remote pathname. */
|
||||
host = thisent + vmp->vmt_data[VMT_HOSTNAME].vmt_off;
|
||||
path = thisent + vmp->vmt_data[VMT_OBJECT].vmt_off;
|
||||
me->me_devname = xmalloc (strlen (host) + strlen (path) + 2);
|
||||
strcpy (me->me_devname, host);
|
||||
strcat (me->me_devname, ":");
|
||||
strcat (me->me_devname, path);
|
||||
}
|
||||
else
|
||||
{
|
||||
me->me_devname = xstrdup (thisent +
|
||||
vmp->vmt_data[VMT_OBJECT].vmt_off);
|
||||
}
|
||||
me->me_mountdir = xstrdup (thisent + vmp->vmt_data[VMT_STUB].vmt_off);
|
||||
me->me_type = xstrdup (fstype_to_string (vmp->vmt_gfstype));
|
||||
me->me_dev = (dev_t) -1; /* vmt_fsid might be the info we want. */
|
||||
me->me_next = NULL;
|
||||
|
||||
/* Add to the linked list. */
|
||||
mtail->me_next = me;
|
||||
mtail = me;
|
||||
}
|
||||
free (entries);
|
||||
}
|
||||
#endif /* MOUNTED_VMOUNT. */
|
||||
|
||||
/* Free the dummy head. */
|
||||
me = mount_list;
|
||||
mount_list = mount_list->me_next;
|
||||
free (me);
|
||||
return mount_list;
|
||||
}
|
32
sysdeps/common/mountlist.h
Normal file
32
sysdeps/common/mountlist.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/* mountlist.h -- declarations for list of mounted filesystems
|
||||
Copyright (C) 1991, 1992 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* A mount table entry. */
|
||||
struct mount_entry
|
||||
{
|
||||
char *me_devname; /* Device node pathname, including "/dev/". */
|
||||
char *me_mountdir; /* Mount point directory pathname. */
|
||||
char *me_type; /* "nfs", "4.2", etc. */
|
||||
dev_t me_dev; /* Device number of me_mountdir. */
|
||||
struct mount_entry *me_next;
|
||||
};
|
||||
|
||||
#if __STDC__
|
||||
struct mount_entry *read_filesystem_list (int need_fs_type, int all_fs);
|
||||
#else
|
||||
struct mount_entry *read_filesystem_list ();
|
||||
#endif
|
@@ -59,6 +59,12 @@ glibtop_realloc_r (glibtop *server, void *ptr, size_t size)
|
||||
return buf;
|
||||
}
|
||||
|
||||
char *
|
||||
glibtop_strdup_r (glibtop *server, const char *string)
|
||||
{
|
||||
return strcpy (glibtop_malloc_r (server, strlen (string) + 1), string);
|
||||
}
|
||||
|
||||
void
|
||||
glibtop_free_r (glibtop *server, void *ptr)
|
||||
{
|
||||
|
@@ -55,7 +55,7 @@ BEGIN {
|
||||
print "";
|
||||
print "\tif (ptr) {";
|
||||
print "\t\tfor (i = 0; i < proclist.number; i++)";
|
||||
print "\t\t\tlist = gh_append";
|
||||
print "\t\t\tlist = scm_append";
|
||||
print "\t\t\t\t(gh_list (list,";
|
||||
print "\t\t\t\t\t gh_list (gh_ulong2scm ((unsigned long) ptr [i])),";
|
||||
print "\t\t\t\t\t SCM_UNDEFINED));";
|
||||
|
@@ -22,7 +22,7 @@ function output(feature) {
|
||||
print "\tlist = gh_list (SCM_UNDEFINED);";
|
||||
print "";
|
||||
print "\tfor (i = 0; i < GLIBTOP_MAX_"toupper(feature)"; i++)";
|
||||
print "\t\tlist = gh_append";
|
||||
print "\t\tlist = scm_append";
|
||||
print "\t\t\t(gh_list (list,";
|
||||
print "\t\t\t\t gh_list (gh_str02scm ((char *) glibtop_names_"feature" [i])),";
|
||||
print "\t\t\t\t SCM_UNDEFINED));";
|
||||
@@ -41,7 +41,7 @@ function output(feature) {
|
||||
print "\tlist = gh_list (SCM_UNDEFINED);";
|
||||
print "";
|
||||
print "\tfor (i = 0; i < GLIBTOP_MAX_"toupper(feature)"; i++)";
|
||||
print "\t\tlist = gh_append";
|
||||
print "\t\tlist = scm_append";
|
||||
print "\t\t\t(gh_list (list,";
|
||||
print "\t\t\t\t gh_list (gh_ulong2scm (glibtop_types_"feature" [i])),";
|
||||
print "\t\t\t\t SCM_UNDEFINED));";
|
||||
@@ -60,7 +60,7 @@ function output(feature) {
|
||||
print "\tlist = gh_list (SCM_UNDEFINED);";
|
||||
print "";
|
||||
print "\tfor (i = 0; i < GLIBTOP_MAX_"toupper(feature)"; i++)";
|
||||
print "\t\tlist = gh_append";
|
||||
print "\t\tlist = scm_append";
|
||||
print "\t\t\t(gh_list (list,";
|
||||
print "\t\t\t\t gh_list (gh_str02scm (gettext";
|
||||
print "\t\t\t\t\t\t\t(glibtop_labels_"feature" [i]))),";
|
||||
@@ -80,7 +80,7 @@ function output(feature) {
|
||||
print "\tlist = gh_list (SCM_UNDEFINED);";
|
||||
print "";
|
||||
print "\tfor (i = 0; i < GLIBTOP_MAX_"toupper(feature)"; i++)";
|
||||
print "\t\tlist = gh_append";
|
||||
print "\t\tlist = scm_append";
|
||||
print "\t\t\t(gh_list (list,";
|
||||
print "\t\t\t\t gh_list (gh_str02scm (gettext";
|
||||
print "\t\t\t\t\t\t\t(glibtop_descriptions_"feature" [i]))),";
|
||||
|
@@ -14,4 +14,4 @@ libgtop_sysdeps_la_SOURCES = init.c open.c close.c cpu.c mem.c swap.c \
|
||||
proctime.c procmem.c procsignal.c prockernel.c \
|
||||
procsegment.c
|
||||
|
||||
include_HEADERS = glibtop_server.h
|
||||
include_HEADERS = glibtop_server.h glibtop_machine.h
|
||||
|
@@ -35,8 +35,7 @@ static const unsigned long _glibtop_sysdeps_cpu =
|
||||
void
|
||||
glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
|
||||
{
|
||||
char buffer [BUFSIZ], *tmp;
|
||||
int fd = 0, ret;
|
||||
FILE *f;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
@@ -44,37 +43,15 @@ glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
|
||||
|
||||
buf->flags = _glibtop_sysdeps_cpu;
|
||||
|
||||
#ifdef GLIBTOP_CACHE_OPEN
|
||||
fd = server->machine.fd_stat;
|
||||
#endif
|
||||
if (fd == 0) {
|
||||
fd = open (FILENAME, O_RDONLY);
|
||||
if (fd == -1)
|
||||
glibtop_error_r (server, "open (%s): %s",
|
||||
FILENAME, strerror (errno));
|
||||
} else {
|
||||
lseek (fd, 0, SEEK_SET);
|
||||
}
|
||||
f = fopen ("/proc/stat", "r");
|
||||
if (!f) return;
|
||||
|
||||
ret = read (fd, buffer, BUFSIZ);
|
||||
if (ret == -1)
|
||||
glibtop_error_r (server, "read (%s): %s",
|
||||
FILENAME, strerror (errno));
|
||||
|
||||
tmp = strchr (buffer, '\n');
|
||||
tmp = skip_token (tmp); /* "cpu" */
|
||||
buf->user = strtoul (tmp, &tmp, 10);
|
||||
buf->nice = strtoul (tmp, &tmp, 10);
|
||||
buf->sys = strtoul (tmp, &tmp, 10);
|
||||
buf->idle = strtoul (tmp, &tmp, 10);
|
||||
fscanf (f, "cpu %lu %lu %lu %lu\n",
|
||||
&buf->user, &buf->nice, &buf->sys, &buf->idle);
|
||||
|
||||
buf->total = buf->user + buf->nice + buf->sys + buf->idle;
|
||||
|
||||
buf->frequency = 100;
|
||||
|
||||
#ifdef GLIBTOP_CACHE_OPEN
|
||||
server->machine.fd_stat = fd;
|
||||
#else
|
||||
close (fd);
|
||||
#endif
|
||||
fclose (f);
|
||||
}
|
||||
|
@@ -33,8 +33,7 @@ static const unsigned long _glibtop_sysdeps_loadavg =
|
||||
void
|
||||
glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
|
||||
{
|
||||
char buffer [BUFSIZ], *tmp;
|
||||
int fd = 0, ret;
|
||||
FILE *f;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
@@ -42,30 +41,11 @@ glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
|
||||
|
||||
buf->flags = _glibtop_sysdeps_loadavg;
|
||||
|
||||
#ifdef GLIBTOP_CACHE_OPEN
|
||||
fd = server->machine.fd_loadavg;
|
||||
#endif
|
||||
if (fd == 0) {
|
||||
fd = open (FILENAME, O_RDONLY);
|
||||
if (fd == -1)
|
||||
glibtop_error_r (server, "open (%s): %s",
|
||||
FILENAME, strerror (errno));
|
||||
} else {
|
||||
lseek (fd, 0, SEEK_SET);
|
||||
}
|
||||
f = fopen ("/proc/loadavg", "r");
|
||||
if (!f) return;
|
||||
|
||||
ret = read (fd, buffer, BUFSIZ);
|
||||
if (ret == -1)
|
||||
glibtop_error_r (server, "read (%s): %s",
|
||||
FILENAME, strerror (errno));
|
||||
|
||||
buf->loadavg [0] = strtod (buffer, &tmp);
|
||||
buf->loadavg [1] = strtod (tmp, &tmp);
|
||||
buf->loadavg [2] = strtod (tmp, &tmp);
|
||||
|
||||
#ifdef GLIBTOP_CACHE_OPEN
|
||||
server->machine.fd_loadavg = fd;
|
||||
#else
|
||||
close (fd);
|
||||
#endif
|
||||
fscanf (f, "%lf %lf %lf\n",
|
||||
&buf->loadavg [0], &buf->loadavg [1], &buf->loadavg [2]);
|
||||
|
||||
fclose (f);
|
||||
}
|
||||
|
@@ -36,8 +36,7 @@ static const unsigned long _glibtop_sysdeps_mem =
|
||||
void
|
||||
glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
|
||||
{
|
||||
char buffer [BUFSIZ], *tmp;
|
||||
int fd = 0, ret;
|
||||
FILE *f;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
@@ -45,39 +44,13 @@ glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
|
||||
|
||||
buf->flags = _glibtop_sysdeps_mem;
|
||||
|
||||
#ifdef GLIBTOP_CACHE_OPEN
|
||||
fd = server->machine.fd_meminfo;
|
||||
#endif
|
||||
if (fd == 0) {
|
||||
fd = open (FILENAME, O_RDONLY);
|
||||
if (fd == -1)
|
||||
glibtop_error_r (server, "open (%s): %s",
|
||||
FILENAME, strerror (errno));
|
||||
} else {
|
||||
lseek (fd, 0, SEEK_SET);
|
||||
}
|
||||
f = fopen ("/proc/meminfo", "r");
|
||||
if (!f) return;
|
||||
|
||||
ret = read (fd, buffer, BUFSIZ);
|
||||
if (ret == -1)
|
||||
glibtop_error_r (server, "read (%s): %s",
|
||||
FILENAME, strerror (errno));
|
||||
|
||||
tmp = strchr (buffer, '\n');
|
||||
tmp = skip_token (tmp); /* "Mem:" */
|
||||
tmp = skip_token (tmp); /* total memory */
|
||||
|
||||
buf->total = strtoul (tmp, &tmp, 10);
|
||||
buf->used = strtoul (tmp, &tmp, 10);
|
||||
buf->free = strtoul (tmp, &tmp, 10);
|
||||
buf->shared = strtoul (tmp, &tmp, 10);
|
||||
buf->buffer = strtoul (tmp, &tmp, 10);
|
||||
buf->cached = strtoul (tmp, &tmp, 10);
|
||||
fscanf (f, "%*[^\n]\nMem: %lu %lu %lu %lu %lu %lu\n",
|
||||
&buf->total, &buf->used, &buf->free, &buf->shared, &buf->buffer, &buf->cached);
|
||||
|
||||
buf->user = buf->total - buf->free - buf->shared - buf->buffer;
|
||||
|
||||
#ifdef GLIBTOP_CACHE_OPEN
|
||||
server->machine.fd_meminfo = fd;
|
||||
#else
|
||||
close (fd);
|
||||
#endif
|
||||
fclose (f);
|
||||
}
|
||||
|
@@ -34,8 +34,9 @@ static const unsigned long _glibtop_sysdeps_proc_kernel =
|
||||
void
|
||||
glibtop_get_proc_kernel_s (glibtop *server, glibtop_proc_kernel *buf, pid_t pid)
|
||||
{
|
||||
char buffer [BUFSIZ], input [BUFSIZ], *tmp;
|
||||
int fd = 0, nread;
|
||||
char input [BUFSIZ], *tmp;
|
||||
int nread;
|
||||
FILE *f;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
@@ -47,41 +48,24 @@ glibtop_get_proc_kernel_s (glibtop *server, glibtop_proc_kernel *buf, pid_t pid)
|
||||
return;
|
||||
}
|
||||
|
||||
if (pid != server->machine.last_pid) {
|
||||
server->machine.last_pid = pid;
|
||||
server->machine.no_update = 0;
|
||||
}
|
||||
sprintf (input, "/proc/%d/stat", pid);
|
||||
|
||||
if (!server->machine.no_update) {
|
||||
server->machine.proc_status [0] = 0;
|
||||
server->machine.proc_statm [0] = 0;
|
||||
server->machine.proc_stat [0] = 0;
|
||||
f = fopen (input, "r");
|
||||
if (!f) return;
|
||||
|
||||
nread = fread (input, 1, BUFSIZ, f);
|
||||
|
||||
if (nread < 0) {
|
||||
fclose (f);
|
||||
return;
|
||||
}
|
||||
|
||||
if (server->machine.proc_stat [0]) {
|
||||
strcpy (buffer, server->machine.proc_stat);
|
||||
} else {
|
||||
sprintf (input, "/proc/%d/stat", pid);
|
||||
|
||||
fd = open (input, O_RDONLY);
|
||||
if (fd == -1)
|
||||
glibtop_error_r (server, "open (%s): %s",
|
||||
input, strerror (errno));
|
||||
|
||||
nread = read (fd, buffer, BUFSIZ);
|
||||
if (nread == -1)
|
||||
glibtop_error_r (server, "read (%s): %s",
|
||||
input, strerror (errno));
|
||||
|
||||
buffer [nread] = 0;
|
||||
strcpy (server->machine.proc_stat, buffer);
|
||||
close (fd);
|
||||
}
|
||||
|
||||
|
||||
input [nread] = 0;
|
||||
|
||||
/* This is from guile-utils/gtop/proc/readproc.c */
|
||||
|
||||
/* split into "PID (cmd" and "<rest>" */
|
||||
tmp = strrchr (buffer, ')');
|
||||
tmp = strrchr (input, ')');
|
||||
*tmp = '\0'; /* replace trailing ')' with NUL */
|
||||
/* parse these two strings separately, skipping the leading "(". */
|
||||
|
||||
@@ -92,6 +76,8 @@ glibtop_get_proc_kernel_s (glibtop *server, glibtop_proc_kernel *buf, pid_t pid)
|
||||
&buf->k_flags, &buf->min_flt, &buf->cmin_flt,
|
||||
&buf->maj_flt, &buf->cmaj_flt, &buf->kstk_esp,
|
||||
&buf->kstk_eip, &buf->wchan);
|
||||
|
||||
fclose (f);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_kernel;
|
||||
}
|
||||
|
@@ -33,8 +33,9 @@ static const unsigned long _glibtop_sysdeps_proc_mem =
|
||||
void
|
||||
glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid)
|
||||
{
|
||||
char buffer [BUFSIZ], input [BUFSIZ], *tmp;
|
||||
int fd = 0, nread;
|
||||
char input [BUFSIZ], *tmp;
|
||||
int nread;
|
||||
FILE *f;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
@@ -46,41 +47,24 @@ glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid)
|
||||
return;
|
||||
}
|
||||
|
||||
if (pid != server->machine.last_pid) {
|
||||
server->machine.last_pid = pid;
|
||||
server->machine.no_update = 0;
|
||||
}
|
||||
sprintf (input, "/proc/%d/stat", pid);
|
||||
|
||||
if (!server->machine.no_update) {
|
||||
server->machine.proc_status [0] = 0;
|
||||
server->machine.proc_statm [0] = 0;
|
||||
server->machine.proc_stat [0] = 0;
|
||||
}
|
||||
|
||||
if (server->machine.proc_stat [0]) {
|
||||
strcpy (buffer, server->machine.proc_stat);
|
||||
} else {
|
||||
sprintf (input, "/proc/%d/stat", pid);
|
||||
|
||||
fd = open (input, O_RDONLY);
|
||||
if (fd == -1)
|
||||
glibtop_error_r (server, "open (%s): %s",
|
||||
input, strerror (errno));
|
||||
|
||||
nread = read (fd, buffer, BUFSIZ);
|
||||
if (nread == -1)
|
||||
glibtop_error_r (server, "read (%s): %s",
|
||||
input, strerror (errno));
|
||||
|
||||
buffer [nread] = 0;
|
||||
strcpy (server->machine.proc_stat, buffer);
|
||||
close (fd);
|
||||
f = fopen (input, "r");
|
||||
if (!f) return;
|
||||
|
||||
nread = fread (input, 1, BUFSIZ, f);
|
||||
|
||||
if (nread < 0) {
|
||||
fclose (f);
|
||||
return;
|
||||
}
|
||||
|
||||
input [nread] = 0;
|
||||
|
||||
/* This is from guile-utils/gtop/proc/readproc.c */
|
||||
|
||||
/* split into "PID (cmd" and "<rest>" */
|
||||
tmp = strrchr (buffer, ')');
|
||||
tmp = strrchr (input, ')');
|
||||
*tmp = '\0'; /* replace trailing ')' with NUL */
|
||||
/* parse these two strings separately, skipping the leading "(". */
|
||||
sscanf(tmp + 2, /* skip space after ')' too */
|
||||
@@ -88,28 +72,26 @@ glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid)
|
||||
"%*d %*d %*d %*d %*d %*d %*u %*u %*d %lu "
|
||||
"%lu %lu", &buf->vsize, &buf->rss, &buf->rss_rlim);
|
||||
|
||||
if (server->machine.proc_statm [0]) {
|
||||
strcpy (buffer, server->machine.proc_statm);
|
||||
} else {
|
||||
sprintf (input, "/proc/%d/statm", pid);
|
||||
|
||||
fd = open (input, O_RDONLY);
|
||||
if (fd == -1)
|
||||
glibtop_error_r (server, "open (%s): %s",
|
||||
input, strerror (errno));
|
||||
|
||||
nread = read (fd, buffer, BUFSIZ);
|
||||
if (nread == -1)
|
||||
glibtop_error_r (server, "read (%s): %s",
|
||||
input, strerror (errno));
|
||||
fclose (f);
|
||||
|
||||
buffer [nread] = 0;
|
||||
strcpy (server->machine.proc_statm, buffer);
|
||||
close (fd);
|
||||
sprintf (input, "/proc/%d/statm", pid);
|
||||
|
||||
f = fopen (input, "r");
|
||||
if (!f) return;
|
||||
|
||||
nread = fread (input, 1, BUFSIZ, f);
|
||||
|
||||
if (nread < 0) {
|
||||
fclose (f);
|
||||
return;
|
||||
}
|
||||
|
||||
sscanf (buffer, "%ld %ld %ld",
|
||||
|
||||
input [nread] = 0;
|
||||
|
||||
sscanf (input, "%ld %ld %ld",
|
||||
&buf->size, &buf->resident, &buf->share);
|
||||
|
||||
fclose (f);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_mem;
|
||||
}
|
||||
|
@@ -35,8 +35,9 @@ void
|
||||
glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf,
|
||||
pid_t pid)
|
||||
{
|
||||
char buffer [BUFSIZ], input [BUFSIZ], *tmp;
|
||||
int fd = 0, nread;
|
||||
char input [BUFSIZ], *tmp;
|
||||
int nread;
|
||||
FILE *f;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
@@ -48,41 +49,24 @@ glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf,
|
||||
return;
|
||||
}
|
||||
|
||||
if (pid != server->machine.last_pid) {
|
||||
server->machine.last_pid = pid;
|
||||
server->machine.no_update = 0;
|
||||
}
|
||||
sprintf (input, "/proc/%d/stat", pid);
|
||||
|
||||
if (!server->machine.no_update) {
|
||||
server->machine.proc_status [0] = 0;
|
||||
server->machine.proc_statm [0] = 0;
|
||||
server->machine.proc_stat [0] = 0;
|
||||
f = fopen (input, "r");
|
||||
if (!f) return;
|
||||
|
||||
nread = fread (input, 1, BUFSIZ, f);
|
||||
|
||||
if (nread < 0) {
|
||||
fclose (f);
|
||||
return;
|
||||
}
|
||||
|
||||
if (server->machine.proc_stat [0]) {
|
||||
strcpy (buffer, server->machine.proc_stat);
|
||||
} else {
|
||||
sprintf (input, "/proc/%d/stat", pid);
|
||||
|
||||
fd = open (input, O_RDONLY);
|
||||
if (fd == -1)
|
||||
glibtop_error_r (server, "open (%s): %s",
|
||||
input, strerror (errno));
|
||||
|
||||
nread = read (fd, buffer, BUFSIZ);
|
||||
if (nread == -1)
|
||||
glibtop_error_r (server, "read (%s): %s",
|
||||
input, strerror (errno));
|
||||
|
||||
buffer [nread] = 0;
|
||||
strcpy (server->machine.proc_stat, buffer);
|
||||
close (fd);
|
||||
}
|
||||
|
||||
|
||||
input [nread] = 0;
|
||||
|
||||
/* This is from guile-utils/gtop/proc/readproc.c */
|
||||
|
||||
/* split into "PID (cmd" and "<rest>" */
|
||||
tmp = strrchr (buffer, ')');
|
||||
tmp = strrchr (input, ')');
|
||||
*tmp = '\0'; /* replace trailing ')' with NUL */
|
||||
/* parse these two strings separately, skipping the leading "(". */
|
||||
sscanf(tmp + 2, /* skip space after ')' too */
|
||||
@@ -91,28 +75,26 @@ glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf,
|
||||
"%*u %*u %lu %lu %lu", &buf->start_code,
|
||||
&buf->end_code, &buf->start_stack);
|
||||
|
||||
if (server->machine.proc_statm [0]) {
|
||||
strcpy (buffer, server->machine.proc_statm);
|
||||
} else {
|
||||
sprintf (input, "/proc/%d/statm", pid);
|
||||
|
||||
fd = open (input, O_RDONLY);
|
||||
if (fd == -1)
|
||||
glibtop_error_r (server, "open (%s): %s",
|
||||
input, strerror (errno));
|
||||
|
||||
nread = read (fd, buffer, BUFSIZ);
|
||||
if (nread == -1)
|
||||
glibtop_error_r (server, "read (%s): %s",
|
||||
input, strerror (errno));
|
||||
|
||||
buffer [nread] = 0;
|
||||
strcpy (server->machine.proc_statm, buffer);
|
||||
close (fd);
|
||||
fclose (f);
|
||||
|
||||
sprintf (input, "/proc/%d/statm", pid);
|
||||
|
||||
f = fopen (input, "r");
|
||||
if (!f) return;
|
||||
|
||||
nread = fread (input, 1, BUFSIZ, f);
|
||||
|
||||
if (nread < 0) {
|
||||
fclose (f);
|
||||
return;
|
||||
}
|
||||
|
||||
sscanf (buffer, "%*d %*d %*d %ld %ld %ld %ld",
|
||||
input [nread] = 0;
|
||||
|
||||
sscanf (input, "%*d %*d %*d %ld %ld %ld %ld",
|
||||
&buf->trs, &buf->lrs, &buf->drs, &buf->dt);
|
||||
|
||||
fclose (f);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_segment;
|
||||
}
|
||||
|
@@ -32,8 +32,9 @@ static const unsigned long _glibtop_sysdeps_proc_signal =
|
||||
void
|
||||
glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf, pid_t pid)
|
||||
{
|
||||
char buffer [BUFSIZ], input [BUFSIZ], *tmp;
|
||||
int fd = 0, nread;
|
||||
char input [BUFSIZ], *tmp;
|
||||
int nread;
|
||||
FILE *f;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
@@ -45,41 +46,24 @@ glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf, pid_t pid)
|
||||
return;
|
||||
}
|
||||
|
||||
if (pid != server->machine.last_pid) {
|
||||
server->machine.last_pid = pid;
|
||||
server->machine.no_update = 0;
|
||||
}
|
||||
sprintf (input, "/proc/%d/stat", pid);
|
||||
|
||||
if (!server->machine.no_update) {
|
||||
server->machine.proc_status [0] = 0;
|
||||
server->machine.proc_statm [0] = 0;
|
||||
server->machine.proc_stat [0] = 0;
|
||||
f = fopen (input, "r");
|
||||
if (!f) return;
|
||||
|
||||
nread = fread (input, 1, BUFSIZ, f);
|
||||
|
||||
if (nread < 0) {
|
||||
fclose (f);
|
||||
return;
|
||||
}
|
||||
|
||||
if (server->machine.proc_stat [0]) {
|
||||
strcpy (buffer, server->machine.proc_stat);
|
||||
} else {
|
||||
sprintf (input, "/proc/%d/stat", pid);
|
||||
|
||||
fd = open (input, O_RDONLY);
|
||||
if (fd == -1)
|
||||
glibtop_error_r (server, "open (%s): %s",
|
||||
input, strerror (errno));
|
||||
|
||||
nread = read (fd, buffer, BUFSIZ);
|
||||
if (nread == -1)
|
||||
glibtop_error_r (server, "read (%s): %s",
|
||||
input, strerror (errno));
|
||||
|
||||
buffer [nread] = 0;
|
||||
strcpy (server->machine.proc_stat, buffer);
|
||||
close (fd);
|
||||
}
|
||||
|
||||
|
||||
input [nread] = 0;
|
||||
|
||||
/* This is from guile-utils/gtop/proc/readproc.c */
|
||||
|
||||
/* split into "PID (cmd" and "<rest>" */
|
||||
tmp = strrchr (buffer, ')');
|
||||
tmp = strrchr (input, ')');
|
||||
*tmp = '\0'; /* replace trailing ')' with NUL */
|
||||
/* parse these two strings separately, skipping the leading "(". */
|
||||
sscanf(tmp + 2, /* skip space after ')' too */
|
||||
@@ -89,5 +73,7 @@ glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf, pid_t pid)
|
||||
&buf->signal, &buf->blocked, &buf->sigignore,
|
||||
&buf->sigcatch);
|
||||
|
||||
fclose (f);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_signal;
|
||||
}
|
||||
|
@@ -34,9 +34,10 @@ static const unsigned long _glibtop_sysdeps_proc_state =
|
||||
void
|
||||
glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, pid_t pid)
|
||||
{
|
||||
char buffer [BUFSIZ], input [BUFSIZ], *tmp;
|
||||
char input [BUFSIZ], *tmp;
|
||||
struct stat statb;
|
||||
int fd, nread;
|
||||
int nread;
|
||||
FILE *f;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
@@ -48,12 +49,6 @@ glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, pid_t pid)
|
||||
return;
|
||||
}
|
||||
|
||||
server->machine.last_pid = pid;
|
||||
server->machine.no_update = 0;
|
||||
server->machine.proc_status [0] = 0;
|
||||
server->machine.proc_statm [0] = 0;
|
||||
server->machine.proc_stat [0] = 0;
|
||||
|
||||
sprintf (input, "/proc/%d/stat", pid);
|
||||
|
||||
/* IMPORTANT NOTICE: For security reasons it is extremely important
|
||||
@@ -67,33 +62,28 @@ glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, pid_t pid)
|
||||
|
||||
buf->uid = statb.st_uid;
|
||||
buf->gid = statb.st_gid;
|
||||
|
||||
fd = open (input, O_RDONLY);
|
||||
if (fd == -1)
|
||||
glibtop_error_r (server, "open (%s): %s",
|
||||
input, strerror (errno));
|
||||
|
||||
nread = read (fd, buffer, BUFSIZ);
|
||||
if (nread == -1)
|
||||
glibtop_error_r (server, "read (%s): %s",
|
||||
input, strerror (errno));
|
||||
|
||||
buffer [nread] = 0;
|
||||
|
||||
server->machine.last_pid = pid;
|
||||
strcpy (server->machine.proc_stat, buffer);
|
||||
f = fopen (input, "r");
|
||||
if (!f) return;
|
||||
|
||||
nread = fread (input, 1, BUFSIZ, f);
|
||||
|
||||
if (nread < 0) {
|
||||
fclose (f);
|
||||
return;
|
||||
}
|
||||
|
||||
input [nread] = 0;
|
||||
|
||||
/* This is from guile-utils/gtop/proc/readproc.c */
|
||||
|
||||
/* split into "PID (cmd" and "<rest>" */
|
||||
tmp = strrchr (buffer, ')');
|
||||
tmp = strrchr (input, ')');
|
||||
*tmp = '\0'; /* replace trailing ')' with NUL */
|
||||
/* parse these two strings separately, skipping the leading "(". */
|
||||
memset (buf->cmd, 0, sizeof (buf->cmd));
|
||||
sscanf (buffer, "%d (%39c", &pid, buf->cmd);
|
||||
sscanf (input, "%d (%39c", &pid, buf->cmd);
|
||||
sscanf(tmp + 2, "%c", &buf->state); /* skip space after ')' too */
|
||||
|
||||
close (fd);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_state;
|
||||
}
|
||||
|
@@ -34,8 +34,9 @@ static const unsigned long _glibtop_sysdeps_proc_time =
|
||||
void
|
||||
glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf, pid_t pid)
|
||||
{
|
||||
char buffer [BUFSIZ], input [BUFSIZ], *tmp;
|
||||
int fd = 0, nread;
|
||||
char input [BUFSIZ], *tmp;
|
||||
int nread;
|
||||
FILE *f;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
@@ -47,41 +48,24 @@ glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf, pid_t pid)
|
||||
return;
|
||||
}
|
||||
|
||||
if (pid != server->machine.last_pid) {
|
||||
server->machine.last_pid = pid;
|
||||
server->machine.no_update = 0;
|
||||
}
|
||||
sprintf (input, "/proc/%d/stat", pid);
|
||||
|
||||
if (!server->machine.no_update) {
|
||||
server->machine.proc_status [0] = 0;
|
||||
server->machine.proc_statm [0] = 0;
|
||||
server->machine.proc_stat [0] = 0;
|
||||
f = fopen (input, "r");
|
||||
if (!f) return;
|
||||
|
||||
nread = fread (input, 1, BUFSIZ, f);
|
||||
|
||||
if (nread < 0) {
|
||||
fclose (f);
|
||||
return;
|
||||
}
|
||||
|
||||
if (server->machine.proc_stat [0]) {
|
||||
strcpy (buffer, server->machine.proc_stat);
|
||||
} else {
|
||||
sprintf (input, "/proc/%d/stat", pid);
|
||||
|
||||
fd = open (input, O_RDONLY);
|
||||
if (fd == -1)
|
||||
glibtop_error_r (server, "open (%s): %s",
|
||||
input, strerror (errno));
|
||||
|
||||
nread = read (fd, buffer, BUFSIZ);
|
||||
if (nread == -1)
|
||||
glibtop_error_r (server, "read (%s): %s",
|
||||
input, strerror (errno));
|
||||
|
||||
buffer [nread] = 0;
|
||||
strcpy (server->machine.proc_stat, buffer);
|
||||
close (fd);
|
||||
}
|
||||
|
||||
|
||||
input [nread] = 0;
|
||||
|
||||
/* This is from guile-utils/gtop/proc/readproc.c */
|
||||
|
||||
/* split into "PID (cmd" and "<rest>" */
|
||||
tmp = strrchr (buffer, ')');
|
||||
tmp = strrchr (input, ')');
|
||||
*tmp = '\0'; /* replace trailing ')' with NUL */
|
||||
/* parse these two strings separately, skipping the leading "(". */
|
||||
sscanf(tmp + 2, /* skip space after ')' too */
|
||||
@@ -90,5 +74,7 @@ glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf, pid_t pid)
|
||||
&buf->utime, &buf->stime, &buf->cutime, &buf->cstime,
|
||||
&buf->timeout, &buf->it_real_value, &buf->start_time);
|
||||
|
||||
fclose (f);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_time;
|
||||
}
|
||||
|
@@ -38,8 +38,9 @@ static const unsigned long _glibtop_sysdeps_proc_uid =
|
||||
void
|
||||
glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid)
|
||||
{
|
||||
char buffer [BUFSIZ], input [BUFSIZ], *tmp;
|
||||
int fd = 0, nread;
|
||||
char input [BUFSIZ], *tmp;
|
||||
int nread;
|
||||
FILE *f;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
@@ -51,40 +52,23 @@ glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid)
|
||||
return;
|
||||
}
|
||||
|
||||
if (pid != server->machine.last_pid) {
|
||||
server->machine.last_pid = pid;
|
||||
server->machine.no_update = 0;
|
||||
}
|
||||
|
||||
if (!server->machine.no_update) {
|
||||
server->machine.proc_status [0] = 0;
|
||||
server->machine.proc_statm [0] = 0;
|
||||
server->machine.proc_stat [0] = 0;
|
||||
}
|
||||
|
||||
if (server->machine.proc_status [0]) {
|
||||
strcpy (buffer, server->machine.proc_status);
|
||||
} else {
|
||||
sprintf (input, "/proc/%d/status", pid);
|
||||
|
||||
fd = open (input, O_RDONLY);
|
||||
if (fd == -1)
|
||||
glibtop_error_r (server, "open (%s): %s",
|
||||
input, strerror (errno));
|
||||
|
||||
nread = read (fd, buffer, BUFSIZ);
|
||||
if (nread == -1)
|
||||
glibtop_error_r (server, "read (%s): %s",
|
||||
input, strerror (errno));
|
||||
sprintf (input, "/proc/%d/status", pid);
|
||||
|
||||
buffer [nread] = 0;
|
||||
strcpy (server->machine.proc_status, buffer);
|
||||
close (fd);
|
||||
f = fopen (input, "r");
|
||||
if (!f) return;
|
||||
|
||||
nread = fread (input, 1, BUFSIZ, f);
|
||||
|
||||
if (nread < 0) {
|
||||
fclose (f);
|
||||
return;
|
||||
}
|
||||
|
||||
input [nread] = 0;
|
||||
|
||||
/* Search substring 'Pid:' */
|
||||
|
||||
tmp = strstr (buffer, "Pid:");
|
||||
tmp = strstr (input, "Pid:");
|
||||
|
||||
if (tmp == NULL) return;
|
||||
|
||||
@@ -92,30 +76,26 @@ glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid)
|
||||
"Gid: %u %u %*u %*u\n", &buf->pid, &buf->ppid,
|
||||
&buf->uid, &buf->euid, &buf->gid, &buf->egid);
|
||||
|
||||
if (server->machine.proc_stat [0]) {
|
||||
strcpy (buffer, server->machine.proc_stat);
|
||||
} else {
|
||||
sprintf (input, "/proc/%d/stat", pid);
|
||||
|
||||
fd = open (input, O_RDONLY);
|
||||
if (fd == -1)
|
||||
glibtop_error_r (server, "open (%s): %s",
|
||||
input, strerror (errno));
|
||||
|
||||
nread = read (fd, buffer, BUFSIZ);
|
||||
if (nread == -1)
|
||||
glibtop_error_r (server, "read (%s): %s",
|
||||
input, strerror (errno));
|
||||
|
||||
buffer [nread] = 0;
|
||||
strcpy (server->machine.proc_stat, buffer);
|
||||
close (fd);
|
||||
fclose (f);
|
||||
|
||||
sprintf (input, "/proc/%d/stat", pid);
|
||||
|
||||
f = fopen (input, "r");
|
||||
if (!f) return;
|
||||
|
||||
nread = fread (input, 1, BUFSIZ, f);
|
||||
|
||||
if (nread < 0) {
|
||||
fclose (f);
|
||||
return;
|
||||
}
|
||||
|
||||
input [nread] = 0;
|
||||
|
||||
/* This is from guile-utils/gtop/proc/readproc.c */
|
||||
|
||||
/* split into "PID (cmd" and "<rest>" */
|
||||
tmp = strrchr (buffer, ')');
|
||||
tmp = strrchr (input, ')');
|
||||
*tmp = '\0'; /* replace trailing ')' with NUL */
|
||||
/* parse these two strings separately, skipping the leading "(". */
|
||||
sscanf(tmp + 2, /* skip space after ')' too */
|
||||
@@ -137,5 +117,7 @@ glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid)
|
||||
/* when tty wasn't full devno */
|
||||
buf->tty = 4*0x100 + buf->tty;
|
||||
|
||||
fclose (f);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_uid;
|
||||
}
|
||||
|
@@ -34,8 +34,7 @@ static unsigned long _glibtop_sysdeps_swap =
|
||||
void
|
||||
glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
|
||||
{
|
||||
char buffer [BUFSIZ], *tmp;
|
||||
int fd = 0, ret;
|
||||
FILE *f;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
@@ -43,34 +42,11 @@ glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
|
||||
|
||||
buf->flags = _glibtop_sysdeps_swap;
|
||||
|
||||
#ifdef GLIBTOP_CACHE_OPEN
|
||||
fd = server->machine.fd_meminfo;
|
||||
#endif
|
||||
if (fd == 0) {
|
||||
fd = open (FILENAME, O_RDONLY);
|
||||
if (fd == -1)
|
||||
glibtop_error_r (server, "open (%s): %s",
|
||||
FILENAME, strerror (errno));
|
||||
} else {
|
||||
lseek (fd, 0, SEEK_SET);
|
||||
}
|
||||
f = fopen ("/proc/meminfo", "r");
|
||||
if (!f) return;
|
||||
|
||||
ret = read (fd, buffer, BUFSIZ);
|
||||
if (ret == -1)
|
||||
glibtop_error_r (server, "read (%s): %s",
|
||||
FILENAME, strerror (errno));
|
||||
fscanf (f, "%*[^\n]\n%*[^\n]\nSwap: %lu %lu %lu\n",
|
||||
&buf->total, &buf->used, &buf->free);
|
||||
|
||||
tmp = strchr (buffer, '\n');
|
||||
tmp = strchr (tmp+1, '\n');
|
||||
|
||||
tmp = skip_token (tmp); /* "Swap:" */
|
||||
buf->total = strtoul (tmp, &tmp, 10);
|
||||
buf->used = strtoul (tmp, &tmp, 10);
|
||||
buf->free = strtoul (tmp, &tmp, 10);
|
||||
|
||||
#ifdef GLIBTOP_CACHE_OPEN
|
||||
server->machine.fd_meminfo = fd;
|
||||
#else
|
||||
close (fd);
|
||||
#endif
|
||||
fclose (f);
|
||||
}
|
||||
|
@@ -33,8 +33,7 @@ static unsigned long _glibtop_sysdeps_uptime =
|
||||
void
|
||||
glibtop_get_uptime_s (glibtop *server, glibtop_uptime *buf)
|
||||
{
|
||||
int fd, ret;
|
||||
char buffer [BUFSIZ];
|
||||
FILE *f;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
@@ -42,17 +41,10 @@ glibtop_get_uptime_s (glibtop *server, glibtop_uptime *buf)
|
||||
|
||||
buf->flags = _glibtop_sysdeps_uptime;
|
||||
|
||||
fd = open (FILENAME, O_RDONLY);
|
||||
if (fd == -1)
|
||||
glibtop_error_r (server, "open (%s): %s",
|
||||
FILENAME, strerror (errno));
|
||||
f = fopen ("/proc/uptime", "r");
|
||||
if (!f) return;
|
||||
|
||||
ret = read (fd, buffer, BUFSIZ);
|
||||
if (ret == -1)
|
||||
glibtop_error_r (server, "read (%s): %s",
|
||||
FILENAME, strerror (errno));
|
||||
fscanf (f, "%lf %lf\n", &buf->uptime, &buf->idletime);
|
||||
|
||||
sscanf (buffer, "%lf %lf\n", &buf->uptime, &buf->idletime);
|
||||
|
||||
close (fd);
|
||||
fclose (f);
|
||||
}
|
||||
|
Reference in New Issue
Block a user