Compare commits

...

25 Commits

Author SHA1 Message Date
Martin Baulig
f77eba3d57 Importing from top-3.4. 1998-07-14 22:57:20 +00:00
Martin Baulig
f18952a9d8 Initial revision 1998-07-14 22:57:20 +00:00
Martin Baulig
16cb163bb0 Importing from top 3.4 1998-07-14 22:42:16 +00:00
Martin Baulig
f8bdfa9a43 Fixed wrong type which caused a core dump. 1998-07-14 20:24:55 +00:00
Martin Baulig
61f887fc67 Added some comments.
1998-07-14  Martin Baulig  <baulig@Stud.Informatik.uni-trier.de>

	* src/daemon/server_config.h.in: Added some comments.

	* src/daemon/server_config.pl: New file. This is a script you can use
	to create `server_config.h'. It will query you for some configuration
	options.
1998-07-14 20:06:37 +00:00
Martin Baulig
9fd8936e93 Replaced this test with explicit test for gawk' and awk' since `mawk'
1998-07-14  Martin Baulig  <baulig@Stud.Informatik.uni-trier.de>

	* configure.in (AC_PROG_AWK): Replaced this test with explicit test
	for `gawk' and `awk' since `mawk' doesn't work.
1998-07-14 10:31:17 +00:00
Martin Baulig
ef693a93bc Doing correct server initialization using `glibtop_set_parameter_l' and
1998-07-14  Martin Baulig  <martin@home-of-linux.org>

	* src/daemon/gnuserv.c: Doing correct server initialization
	using `glibtop_set_parameter_l' and `glibtop_init_r'.

	* src/daemon/main.c: Removed call to `glibtop_init_r'.

	* lib/open.c (glibtop_open_l): We now call the open function
	of the sysdeps directory (glibtop_open_r) for server method
	`GLIBTOP_METHOD_DIRECT'.

	* sysdeps/{linux, sun4, stub}/open.c: No longer `memset'
	server to zero.
1998-07-14 08:36:23 +00:00
Martin Baulig
aa04293fc3 Forgot to commit this file yesterday. 1998-07-13 23:29:31 +00:00
Martin Baulig
345a657d2c New file.
1998-07-14  Martin Baulig  <martin@home-of-linux.org>

	* src/daemon/slave.c: New file.

	* src/daemon/*.c: Done some more work on the daemon.

	* sysdeps/common/gnuslib.c: Removed IPC stuff.

	* include/glibtop/gnuserv.h: Removed IPC stuff.

	* include/glibtop/command.h (glibtop_response_unit): Added
	typedef for `struct _glibtop_response_unit'.

	* lib/Makefile.am: Using `$(top_srcdir)/features.def'
	instead of `$(top_builddir)/features.def'.

	* sysdeps/guile/Makefile.am: Using `$(top_srcdir)/features.def'
	instead of `$(top_builddir)/features.def'.

	* sysdeps/guile/names/Makefile.am: Dito.

	* sysdeps/stub/*.c: changed suffix of all functions
	from '_s' to '_r'; see also ChangeLog entry from Jun 6.
1998-07-13 23:27:10 +00:00
Martin Baulig
da7d7ff116 Fixed type in debugging statement. 1998-07-13 23:21:40 +00:00
Martin Baulig
c5263a881e Using `$(top_srcdir)/features.def' instead of
1998-07-14  Martin Baulig  <martin@home-of-linux.org>

	* sysdeps/guile/Makefile.am: Using `$(top_srcdir)/features.def'
	instead of `$(top_builddir)/features.def'.

	* sysdeps/guile/names/Makefile.am: Dito.
1998-07-13 22:37:05 +00:00
Martin Baulig
49adb94af0 Only changed indentation. 1998-07-13 22:34:23 +00:00
Martin Baulig
b991ecaf9a changed suffix of all functions from '_s' to '_r'; see also ChangeLog
1998-07-14  Martin Baulig  <martin@home-of-linux.org>

	* sysdeps/stub/*.c: changed suffix of all functions
	from '_s' to '_r'; see also ChangeLog entry from Jun 6.
1998-07-13 22:32:00 +00:00
Martin Baulig
2c8ae09776 Added `server_config.h'. 1998-07-13 15:04:40 +00:00
Martin Baulig
8ecb7f296e Removed from CVS. This is a config file which needs to be edited.
1998-07-13  Martin Baulig  <baulig@merkur.uni-trier.de>

	* src/daemon/server_config.h: Removed from CVS.
	This is a config file which needs to be edited.

	* src/daemon/server_config.h.in: Added. This is just
	an example for `server_config.h'.
1998-07-13 15:02:20 +00:00
Martin Baulig
3477d30dc5 Basically did some work on the new daemon. Things are still unstable.
1998-07-13  Martin Baulig  <martin@home-of-linux.org>

	* glibtop.h: Fixed invocation of `glibtop_close_r'.

	* sysdeps/linux/procstate.c: Added missing `fclose'.

	* include/glibtop/gnuserv.h (UNIX_DOMAIN_SOCKETS): Defining.

	* include/glibtop/open.h (GLIBTOP_METHOD_UNIX): Added.

	* lib/init.c: Added new method `GLIBTOP_METHOD_UNIX'.

	* lib/open.c: Added support for Unix Domain Sockets.

	* lib/close.c: Now closing inet and unix connections.

	* lib/parameter.c (glibtop_set_parameter_l): You can now
	set the `method' and `features' fields.

	* src/daemon/server_config.h: New file.

	* src/daemon/{gnuserv.c, main.c}: More work on the server.
1998-07-13 00:39:46 +00:00
Martin Baulig
f30dfecaf7 Changed indentation, removed some lines already commented out.
Enclosed debugging statement in '#ifdef DEBUG'.
1998-07-13 00:18:44 +00:00
Martin Baulig
8a666eb5a4 Fixed unbalanced '#endif'. 1998-07-12 14:29:30 +00:00
Martin Baulig
61071132bf Changed indentation using
'indent -br -ce -sc -pcs -cs -bs -i8 -bad -bap -fca '
1998-07-12 14:24:49 +00:00
Martin Baulig
b177c3930d Changed indentation using
'indent -br -ce -sc -pcs -cs -bs -i8 -bad -bap -fca'
1998-07-12 14:22:45 +00:00
Martin Baulig
eb8d28b694 Removed `proxy'. This directory is considered obsolete and will be removed
1998-07-10  Martin Baulig  <martin@home-of-linux.org>

	* src/Makefile.am (SUBDIRS): Removed `proxy'. This directory
	is considered obsolete and will be removed soon.
1998-07-09 23:03:27 +00:00
Martin Baulig
0b4f757b2b using functions from `xmalloc.c'.
1998-07-06  Martin Baulig  <martin@home-of-linux.org>

	* sysdeps/common/mountlist.c: using functions from `xmalloc.c'.

	* sysdeps/common/error.c: all functions now accept NULL as
	`server' argument.
1998-07-07 00:10:49 +00:00
Martin Baulig
2aa20e2060 New macros.
1998-07-06  Martin Baulig  <martin@home-of-linux.org>

	* acconfig.h (AFS, MOUNTED_FREAD, MOUNTED_FREAD_FSTYP,
	MOUNTED_GETFSSTAT, MOUNTED_GETMNT, MOUNTED_GETMNTENT1,
	MOUNTED_GETMNTENT2, MOUNTED_GETMNTINFO, MOUNTED_LISTMNTENT,
        MOUNTED_VMOUNT, STAT_STATFS3_OSF1, STAT_READ_FILSYS,
        STAT_STATFS2_BSIZE, STAT_STATFS2_FSIZE, STAT_STATFS2_FS_DATA,
        STAT_STATFS4, STAT_STATVFS, STATFS_TRUNCATES_BLOCK_COUNTS):
        New macros.

	* configure.in: added GNOME_FILEUTILS_CHECKS.
1998-07-06 23:00:48 +00:00
Martin Baulig
7d8ff8f72e *** empty log message *** 1998-07-06 22:51:12 +00:00
Martin Baulig
576dde394a using g_malloc, g_realloc and g_strdup.
* mountlist.c: using g_malloc, g_realloc and g_strdup.
1998-07-06 22:48:25 +00:00
56 changed files with 1759 additions and 1225 deletions

View File

@@ -24,3 +24,4 @@ stamp-h
sun4
sun4sol2
support
i386-freebsd

105
ChangeLog
View File

@@ -1,3 +1,108 @@
1998-07-14 Martin Baulig <baulig@Stud.Informatik.uni-trier.de>
* src/daemon/server_config.h.in: Added some comments.
* src/daemon/server_config.pl: New file. This is a script you can use
to create `server_config.h'. It will query you for some configuration
options.
* configure.in (AC_PROG_AWK): Replaced this test with explicit test
for `gawk' and `awk' since `mawk' doesn't work.
1998-07-14 Martin Baulig <martin@home-of-linux.org>
* src/daemon/gnuserv.c: Doing correct server initialization
using `glibtop_set_parameter_l' and `glibtop_init_r'.
* src/daemon/main.c: Removed call to `glibtop_init_r'.
* lib/open.c (glibtop_open_l): We now call the open function
of the sysdeps directory (glibtop_open_r) for server method
`GLIBTOP_METHOD_DIRECT'.
* sysdeps/{linux, sun4, stub}/open.c: No longer `memset'
server to zero.
* src/daemon/slave.c: New file.
* src/daemon/*.c: Done some more work on the daemon.
* sysdeps/common/gnuslib.c: Removed IPC stuff.
* include/glibtop/gnuserv.h: Removed IPC stuff.
* include/glibtop/command.h (glibtop_response_unit): Added
typedef for `struct _glibtop_response_unit'.
* lib/Makefile.am: Using `$(top_srcdir)/features.def'
instead of `$(top_builddir)/features.def'.
* sysdeps/guile/Makefile.am: Using `$(top_srcdir)/features.def'
instead of `$(top_builddir)/features.def'.
* sysdeps/guile/names/Makefile.am: Dito.
* sysdeps/stub/*.c: changed suffix of all functions
from '_s' to '_r'; see also ChangeLog entry from Jun 6.
1998-07-13 Martin Baulig <baulig@merkur.uni-trier.de>
* src/daemon/server_config.h: Removed from CVS.
This is a config file which needs to be edited.
* src/daemon/server_config.h.in: Added. This is just
an example for `server_config.h'.
1998-07-13 Martin Baulig <martin@home-of-linux.org>
* glibtop.h: Fixed invocation of `glibtop_close_r'.
* sysdeps/linux/procstate.c: Added missing `fclose'.
* include/glibtop/gnuserv.h (UNIX_DOMAIN_SOCKETS): Defining.
* include/glibtop/open.h (GLIBTOP_METHOD_UNIX): Added.
* lib/init.c: Added new method `GLIBTOP_METHOD_UNIX'.
* lib/open.c: Added support for Unix Domain Sockets.
* lib/close.c: Now closing inet and unix connections.
* lib/parameter.c (glibtop_set_parameter_l): You can now
set the `method' and `features' fields.
* src/daemon/server_config.h: New file.
* src/daemon/{gnuserv.c, main.c}: More work on the server.
1998-07-10 Martin Baulig <martin@home-of-linux.org>
* src/Makefile.am (SUBDIRS): Removed `proxy'. This directory
is considered obsolete and will be removed soon.
1998-07-06 Martin Baulig <martin@home-of-linux.org>
* sysdeps/common/mountlist.c: using functions from `xmalloc.c'.
* sysdeps/common/error.c: all functions now accept NULL as
`server' argument.
* acconfig.h (AFS, MOUNTED_FREAD, MOUNTED_FREAD_FSTYP,
MOUNTED_GETFSSTAT, MOUNTED_GETMNT, MOUNTED_GETMNTENT1,
MOUNTED_GETMNTENT2, MOUNTED_GETMNTINFO, MOUNTED_LISTMNTENT,
MOUNTED_VMOUNT, STAT_STATFS3_OSF1, STAT_READ_FILSYS,
STAT_STATFS2_BSIZE, STAT_STATFS2_FSIZE, STAT_STATFS2_FS_DATA,
STAT_STATFS4, STAT_STATVFS, STATFS_TRUNCATES_BLOCK_COUNTS):
New macros.
* configure.in: added GNOME_FILEUTILS_CHECKS.
* sysdeps/common/{fsusage, mountlist}.[ch]:
Imported from GNU Fileutils 3.16.
* sysdeps/common/mountlist.c: using g_malloc, g_realloc and g_strdup.
1998-07-03 Martin baulig <martin@home-of-linux.org>
* macros/gnome-libgtop-sysdeps.m4: No longer use

View File

@@ -12,6 +12,85 @@
/* Do not remove this comments and the empty lines; they are needed */
#undef HAVE_PROGRAM_INVOCATION_SHORT_NAME
/* Define if you have the Andrew File System. */
#undef AFS
/* Define one of the following to indicate how a program can
get a list of mounted filesystems. */
/* Define if there is no specific function for reading the list of
mounted filesystems. fread will be used to read /etc/mnttab. [SVR2] */
#undef MOUNTED_FREAD
/* Define if (like SVR2) there is no specific function for reading the
list of mounted filesystems, and your system has these header files:
<sys/fstyp.h> and <sys/statfs.h>. [SVR3] */
#undef MOUNTED_FREAD_FSTYP
/* Define if there is a function named getfsstat for reading the list
of mounted filesystems. [DEC Alpha running OSF/1] */
#undef MOUNTED_GETFSSTAT
/* Define if there is a function named getmnt for reading the list of
mounted filesystems. [Ultrix] */
#undef MOUNTED_GETMNT
/* Define if there is a function named getmntent for reading the list
of mounted filesystems, and that function takes a single argument.
[4.3BSD, SunOS, HP-UX, Dynix, Irix] */
#undef MOUNTED_GETMNTENT1
/* Define if there is a function named getmntent for reading the list of
mounted filesystems, and that function takes two arguments. [SVR4] */
#undef MOUNTED_GETMNTENT2
/* Define if there is a function named getmntinfo for reading the list
of mounted filesystems. [4.4BSD] */
#undef MOUNTED_GETMNTINFO
/* Define if there is a function named listmntent that can be used to
list all mounted filesystems. [UNICOS] */
#undef MOUNTED_LISTMNTENT
/* Define if there is a function named mntctl that can be used to read
the list of mounted filesystems, and there is a system header file
that declares `struct vmount.' [AIX] */
#undef MOUNTED_VMOUNT
/* Define one of the following to indicate how a program can obtain
filesystems usage information. */
/* Define if statfs takes 3 args. [DEC Alpha running OSF/1] */
#undef STAT_STATFS3_OSF1
/* Define if there is no specific function for reading filesystems usage
information and you have the <sys/filsys.h> header file. [SVR2] */
#undef STAT_READ_FILSYS
/* Define if statfs takes 2 args and struct statfs has a field named f_bsize.
[4.3BSD, SunOS 4, HP-UX, AIX PS/2] */
#undef STAT_STATFS2_BSIZE
/* Define if statfs takes 2 args and struct statfs has a field named f_fsize.
[4.4BSD, NetBSD] */
#undef STAT_STATFS2_FSIZE
/* Define if statfs takes 2 args and the second argument has
type struct fs_data. [Ultrix] */
#undef STAT_STATFS2_FS_DATA
/* Define if statfs takes 4 args. [SVR3, Dynix, Irix, Dolphin] */
#undef STAT_STATFS4
/* Define if there is a function named statvfs. [SVR4] */
#undef STAT_STATVFS
/* Define if the block counts reported by statfs may be truncated to 2GB
and the correct values may be stored in the f_spare array.
[SunOS 4.1.2, 4.1.3, and 4.1.3_U1 are reported to have this problem.
SunOS 4.1.1 seems not to be affected.] */
#undef STATFS_TRUNCATES_BLOCK_COUNTS
/* to fix a bug in autoheader on DEC OSF1. */
#undef HAVE_PROGRAM_INVOCATION_NAME

View File

@@ -15,7 +15,10 @@ AC_PROG_CC
AC_STDC_HEADERS
AC_ARG_PROGRAM
AC_PROG_AWK
dnl We don't use `AC_PROG_AWK' since it checks for mawk first which
dnl does not work for libgtop.
AC_CHECK_PROGS(AWK, gawk awk, )
test -z "$AWK" && AC_MSG_ERROR([Sorry, you need a working awk interpreter.])
AC_CHECK_TOOL(CC,gcc)
AC_CHECK_TOOL(RANLIB,ranlib)
@@ -125,6 +128,8 @@ if test "$with_xauth" = "yes"; then
fi
AC_SUBST(libs_xauth)
dnl For diskusage stuff
GNOME_FILEUTILS_CHECKS
CFLAGS="$CFLAGS -D_IN_LIBGTOP"

View File

@@ -32,7 +32,7 @@
#include <glibtop/sysdeps.h>
#ifndef PROFILE_COUNT
#define PROFILE_COUNT 1
#define PROFILE_COUNT 1000
#endif
int
@@ -68,14 +68,14 @@ main (int argc, char *argv [])
printf ("Host = '%s' - %u\n\n", buffer, port);
for (c = 0; c < count; c++)
for (c = 0; c < PROFILE_COUNT; c++)
glibtop_get_cpu (&data.cpu);
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++)
for (c = 0; c < PROFILE_COUNT; c++)
glibtop_get_mem (&data.mem);
printf ("Memory (0x%08lx): %lu, %lu, %lu, %lu, %lu, %lu, %lu, %lu\n",
@@ -83,26 +83,26 @@ main (int argc, char *argv [])
data.mem.shared, data.mem.buffer, data.mem.cached,
data.mem.user, data.mem.locked);
for (c = 0; c < count; c++)
for (c = 0; c < PROFILE_COUNT; c++)
glibtop_get_swap (&data.swap);
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++)
for (c = 0; c < PROFILE_COUNT; c++)
glibtop_get_uptime (&data.uptime);
printf ("Uptime (0x%08lx): %f, %f\n", data.uptime.flags,
data.uptime.uptime, data.uptime.idletime);
for (c = 0; c < count; c++)
for (c = 0; c < PROFILE_COUNT; c++)
glibtop_get_loadavg (&data.loadavg);
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++)
for (c = 0; c < PROFILE_COUNT; c++)
glibtop_get_shm_limits (&data.shm_limits);
printf ("Shm Limits (0x%08lx): %ld, %ld, %ld, %ld, %ld\n",
@@ -110,7 +110,7 @@ main (int argc, char *argv [])
data.shm_limits.shmmin, data.shm_limits.shmmni,
data.shm_limits.shmseg, data.shm_limits.shmall);
for (c = 0; c < count; c++)
for (c = 0; c < PROFILE_COUNT; c++)
glibtop_get_msg_limits (&data.msg_limits);
printf ("Msg Limits (0x%08lx): %ld, %ld, %ld, %ld, %ld, %ld, %ld\n",
@@ -119,7 +119,7 @@ main (int argc, char *argv [])
data.msg_limits.msgmnb, data.msg_limits.msgmni,
data.msg_limits.msgssz, data.msg_limits.msgtql);
for (c = 0; c < count; c++)
for (c = 0; c < PROFILE_COUNT; c++)
glibtop_get_sem_limits (&data.sem_limits);
printf ("Sem Limits (0x%08lx): "
@@ -167,7 +167,7 @@ main (int argc, char *argv [])
printf ("\n");
for (c = 0; c < count; c++)
for (c = 0; c < PROFILE_COUNT; c++)
glibtop_get_proc_state (&data.proc_state, pid);
printf ("Proc_State PID %5u (0x%08lx): '%s', %c, %u, %u\n",
@@ -175,7 +175,7 @@ main (int argc, char *argv [])
data.proc_state.state, data.proc_state.uid,
data.proc_state.gid);
for (c = 0; c < count; c++)
for (c = 0; c < PROFILE_COUNT; c++)
glibtop_get_proc_uid (&data.proc_uid, pid);
printf ("Proc_Uid PID %5u (0x%08lx): "
@@ -188,7 +188,7 @@ main (int argc, char *argv [])
data.proc_uid.tpgid, data.proc_uid.priority,
data.proc_uid.nice);
for (c = 0; c < count; c++)
for (c = 0; c < PROFILE_COUNT; c++)
glibtop_get_proc_mem (&data.proc_mem, pid);
printf ("Proc_Mem PID %5u (0x%08lx): "
@@ -197,7 +197,7 @@ main (int argc, char *argv [])
data.proc_mem.resident, data.proc_mem.share,
data.proc_mem.rss, data.proc_mem.rss_rlim);
for (c = 0; c < count; c++)
for (c = 0; c < PROFILE_COUNT; c++)
glibtop_get_proc_time (&data.proc_time, pid);
printf ("Proc_Time PID %5u (0x%08lx): "
@@ -207,7 +207,7 @@ main (int argc, char *argv [])
data.proc_time.cstime, data.proc_time.timeout,
data.proc_time.it_real_value);
for (c = 0; c < count; c++)
for (c = 0; c < PROFILE_COUNT; c++)
glibtop_get_proc_signal (&data.proc_signal, pid);
printf ("Proc_Signal PID %5u (0x%08lx): "
@@ -215,7 +215,7 @@ main (int argc, char *argv [])
data.proc_signal.signal, data.proc_signal.blocked,
data.proc_signal.sigignore, data.proc_signal.sigcatch);
for (c = 0; c < count; c++)
for (c = 0; c < PROFILE_COUNT; c++)
glibtop_get_proc_kernel (&data.proc_kernel, pid);
printf ("Proc_Kernel PID %5u (0x%08lx): "
@@ -226,7 +226,7 @@ main (int argc, char *argv [])
data.proc_kernel.kstk_esp, data.proc_kernel.kstk_eip,
data.proc_kernel.wchan);
for (c = 0; c < count; c++)
for (c = 0; c < PROFILE_COUNT; c++)
glibtop_get_proc_segment (&data.proc_segment, pid);
printf ("Proc_Segment PID %5u (0x%08lx): "
@@ -238,7 +238,7 @@ main (int argc, char *argv [])
printf ("\n");
for (c = 0; c < count; c++)
for (c = 0; c < PROFILE_COUNT; c++)
glibtop_get_proc_state (&data.proc_state, ppid);
printf ("Proc_State PPID %5u (0x%08lx): '%s', %c, %u, %u\n",
@@ -246,7 +246,7 @@ main (int argc, char *argv [])
data.proc_state.state, data.proc_state.uid,
data.proc_state.gid);
for (c = 0; c < count; c++)
for (c = 0; c < PROFILE_COUNT; c++)
glibtop_get_proc_uid (&data.proc_uid, ppid);
printf ("Proc_Uid PPID %5u (0x%08lx): "
@@ -259,7 +259,7 @@ main (int argc, char *argv [])
data.proc_uid.tpgid, data.proc_uid.priority,
data.proc_uid.nice);
for (c = 0; c < count; c++)
for (c = 0; c < PROFILE_COUNT; c++)
glibtop_get_proc_mem (&data.proc_mem, ppid);
printf ("Proc_Mem PPID %5u (0x%08lx): "
@@ -268,7 +268,7 @@ main (int argc, char *argv [])
data.proc_mem.resident, data.proc_mem.share,
data.proc_mem.rss, data.proc_mem.rss_rlim);
for (c = 0; c < count; c++)
for (c = 0; c < PROFILE_COUNT; c++)
glibtop_get_proc_time (&data.proc_time, ppid);
printf ("Proc_Time PPID %5u (0x%08lx): "
@@ -278,7 +278,7 @@ main (int argc, char *argv [])
data.proc_time.cstime, data.proc_time.timeout,
data.proc_time.it_real_value);
for (c = 0; c < count; c++)
for (c = 0; c < PROFILE_COUNT; c++)
glibtop_get_proc_signal (&data.proc_signal, ppid);
printf ("Proc_Signal PPID %5u (0x%08lx): "
@@ -286,7 +286,7 @@ main (int argc, char *argv [])
data.proc_signal.signal, data.proc_signal.blocked,
data.proc_signal.sigignore, data.proc_signal.sigcatch);
for (c = 0; c < count; c++)
for (c = 0; c < PROFILE_COUNT; c++)
glibtop_get_proc_kernel (&data.proc_kernel, ppid);
printf ("Proc_Kernel PPID %5u (0x%08lx): "
@@ -297,7 +297,7 @@ main (int argc, char *argv [])
data.proc_kernel.kstk_esp, data.proc_kernel.kstk_eip,
data.proc_kernel.wchan);
for (c = 0; c < count; c++)
for (c = 0; c < PROFILE_COUNT; c++)
glibtop_get_proc_segment (&data.proc_segment, ppid);
printf ("Proc_Segment PPID %5u (0x%08lx): "
@@ -309,7 +309,7 @@ main (int argc, char *argv [])
printf ("\n");
for (c = 0; c < count; c++)
for (c = 0; c < PROFILE_COUNT; c++)
glibtop_get_proc_state (&data.proc_state, 1);
printf ("Proc_State INIT %5u (0x%08lx): '%s', %c, %u, %u\n",
@@ -317,7 +317,7 @@ main (int argc, char *argv [])
data.proc_state.state, data.proc_state.uid,
data.proc_state.gid);
for (c = 0; c < count; c++)
for (c = 0; c < PROFILE_COUNT; c++)
glibtop_get_proc_uid (&data.proc_uid, 1);
printf ("Proc_Uid INIT %5u (0x%08lx): "
@@ -330,7 +330,7 @@ main (int argc, char *argv [])
data.proc_uid.tpgid, data.proc_uid.priority,
data.proc_uid.nice);
for (c = 0; c < count; c++)
for (c = 0; c < PROFILE_COUNT; c++)
glibtop_get_proc_mem (&data.proc_mem, 1);
printf ("Proc_Mem INIT %5u (0x%08lx): "
@@ -339,7 +339,7 @@ main (int argc, char *argv [])
data.proc_mem.resident, data.proc_mem.share,
data.proc_mem.rss, data.proc_mem.rss_rlim);
for (c = 0; c < count; c++)
for (c = 0; c < PROFILE_COUNT; c++)
glibtop_get_proc_time (&data.proc_time, 1);
printf ("Proc_Time INIT %5u (0x%08lx): "
@@ -349,7 +349,7 @@ main (int argc, char *argv [])
data.proc_time.cstime, data.proc_time.timeout,
data.proc_time.it_real_value);
for (c = 0; c < count; c++)
for (c = 0; c < PROFILE_COUNT; c++)
glibtop_get_proc_signal (&data.proc_signal, 1);
printf ("Proc_Signal INIT %5u (0x%08lx): "
@@ -357,7 +357,7 @@ main (int argc, char *argv [])
data.proc_signal.signal, data.proc_signal.blocked,
data.proc_signal.sigignore, data.proc_signal.sigcatch);
for (c = 0; c < count; c++)
for (c = 0; c < PROFILE_COUNT; c++)
glibtop_get_proc_kernel (&data.proc_kernel, 1);
printf ("Proc_Kernel INIT %5u (0x%08lx): "
@@ -368,7 +368,7 @@ main (int argc, char *argv [])
data.proc_kernel.kstk_esp, data.proc_kernel.kstk_eip,
data.proc_kernel.wchan);
for (c = 0; c < count; c++)
for (c = 0; c < PROFILE_COUNT; c++)
glibtop_get_proc_segment (&data.proc_segment, 1);
printf ("Proc_Segment INIT %5u (0x%08lx): "
@@ -378,5 +378,7 @@ main (int argc, char *argv [])
data.proc_segment.start_code, data.proc_segment.end_code,
data.proc_segment.start_stack);
glibtop_close ();
exit (0);
}

View File

@@ -60,7 +60,7 @@ extern const unsigned long glibtop_server_features;
#define glibtop_init() glibtop_init_r(&glibtop_global_server, 0, 0);
#define glibtop_close() glibtop_close_r(&glibtop_global_server);
#define glibtop_close() glibtop_close_r(glibtop_global_server);
extern glibtop *glibtop_init_r __P((glibtop **, const unsigned long, const unsigned));

View File

@@ -53,7 +53,9 @@ __BEGIN_DECLS
#define _GLIBTOP_PARAM_SIZE 16
typedef struct _glibtop_command glibtop_command;
typedef struct _glibtop_response glibtop_response;
typedef union _glibtop_response_union glibtop_response_union;
struct _glibtop_command
{
@@ -73,7 +75,7 @@ struct _glibtop_response
{
off_t offset;
size_t size, data_size;
union _glibtop_response_union u;
glibtop_response_union u;
};
#define glibtop_call(p1, p2, p3, p4) glibtop_call_r(glibtop_global_server, p1, p2, p3, p4)

View File

@@ -54,10 +54,8 @@ static char header_rcsid [] = "!Header: gnuserv.h,v 2.4 95/02/16 11:58:11 arup a
* sockets with sysv ipc
*/
#define INTERNET_DOMAIN_SOCKETS
// #define UNIX_DOMAIN_SOCKETS
// #define SYSV_IPC
#define UNIX_DOMAIN_SOCKETS
/*
* Define additional authentication protocols to be used. These methods will
@@ -91,15 +89,13 @@ static char header_rcsid [] = "!Header: gnuserv.h,v 2.4 95/02/16 11:58:11 arup a
* Pick a default communication scheme, if none was specified.
*/
#if !defined(SYSV_IPC) && !defined(UNIX_DOMAIN_SOCKETS) && !defined(INTERNET_DOMAIN_SOCKETS)
#if !defined(UNIX_DOMAIN_SOCKETS) && !defined(INTERNET_DOMAIN_SOCKETS)
#ifdef HAVE_SYSVIPC
#define SYSV_IPC /* SYSV systems use SYSV IPC by default */
#endif /* HAVE_SYSVIPC */
/* BSD systems use Unix Domain sockets by default */
#ifdef BSD
#define UNIX_DOMAIN_SOCKETS /* BSD systems use Unix Domain sockets by default */
#endif /* BSD */
#define UNIX_DOMAIN_SOCKETS
#endif
#endif /* No communication method pre-defined */
@@ -111,24 +107,6 @@ static char header_rcsid [] = "!Header: gnuserv.h,v 2.4 95/02/16 11:58:11 arup a
* 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 */
@@ -155,9 +133,6 @@ 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;
/* 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))
@@ -178,16 +153,6 @@ static char header_rcsid [] = "!Header: gnuserv.h,v 2.4 95/02/16 11:58:11 arup a
/* function declarations */
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);
#endif
#ifdef INTERNET_DOMAIN_SOCKETS
extern long glibtop_internet_addr __P((const char *));
#endif

View File

@@ -38,6 +38,7 @@ __BEGIN_DECLS
#define GLIBTOP_METHOD_DIRECT 1
#define GLIBTOP_METHOD_PIPE 2
#define GLIBTOP_METHOD_INET 3
#define GLIBTOP_METHOD_UNIX 4
extern void glibtop_open_l __P((glibtop *, const char *, const unsigned long, const unsigned));

View File

@@ -4,7 +4,7 @@ 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
CFLAGS = -Wall -W @CFLAGS@ -DGTOP_SERVER=\""@LIBGTOP_SERVER@"\"
lib_LTLIBRARIES = libgtop.la
@@ -13,8 +13,8 @@ libgtop_la_SOURCES = init.c open.c close.c command.c read.c read_data.c \
BUILT_SOURCES = lib.c
lib.c: lib.awk $(top_builddir)/config.h $(top_builddir)/features.def
$(AWK) -f $(srcdir)/lib.awk < $(top_builddir)/features.def > lib-t
lib.c: lib.awk $(top_builddir)/config.h $(top_srcdir)/features.def
$(AWK) -f $(srcdir)/lib.awk < $(top_srcdir)/features.def > lib-t
mv lib-t lib.c
EXTRA_DIST = lib.awk

View File

@@ -19,14 +19,30 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <glibtop.h>
#include <glibtop/open.h>
#include <glibtop/close.h>
#include <glibtop/command.h>
/* Closes pipe to gtop server. */
/* Closes server. */
void
glibtop_close_r (glibtop *server)
{
kill (server->pid, SIGKILL);
close (server->input [0]);
close (server->output [1]);
switch (server->method) {
case GLIBTOP_METHOD_UNIX:
case GLIBTOP_METHOD_INET:
glibtop_call_l (server, GLIBTOP_CMND_QUIT,
0, NULL, 0, NULL);
if (close (server->socket))
glibtop_warn_io ("close");
break;
case GLIBTOP_METHOD_PIPE:
kill (server->pid, SIGKILL);
close (server->input [0]);
close (server->output [1]);
break;
}
}

View File

@@ -27,8 +27,8 @@
#include <glibtop/xmalloc.h>
void *
glibtop_call_l (glibtop *server, unsigned command, size_t send_size, void *send_buf,
size_t recv_size, void *recv_buf)
glibtop_call_l (glibtop *server, unsigned command, size_t send_size,
void *send_buf, size_t recv_size, void *recv_buf)
{
glibtop_command cmnd;
glibtop_response response;
@@ -45,11 +45,6 @@ glibtop_call_l (glibtop *server, unsigned command, size_t send_size, void *send_
* 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;
@@ -58,14 +53,17 @@ glibtop_call_l (glibtop *server, unsigned command, size_t send_size, void *send_
}
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);
#ifdef DEBUG
fprintf (stderr, "RESPONSE: %lu - %d\n",
response.offset, response.data_size);
#endif
if (recv_buf)
memcpy (recv_buf, ((char *) &response) + response.offset, recv_size);
memcpy (recv_buf, ((char *) &response) + response.offset,
recv_size);
if (response.data_size) {
void *ptr = glibtop_malloc_r (server, response.data_size);

View File

@@ -63,16 +63,11 @@ _init_server (glibtop *server, const unsigned features)
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;
}
@@ -92,21 +87,19 @@ _init_server (glibtop *server, const unsigned features)
/* 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. */
/* 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. */
/* Connect to internet server. */
if (temp == NULL) {
/* If no value was set, we use 'localhost'. */
/* If no value was set, we use 'localhost'. */
if (server->server_host == NULL)
server->server_host = glibtop_strdup_r
(server, "localhost");
@@ -114,7 +107,7 @@ _init_server (glibtop *server, const unsigned features)
char *temp2 = strstr (temp+1, ":");
if (temp2) *temp2 = 0;
/* Override default. */
/* Override default. */
if (server->server_host)
glibtop_free_r (server, (char *) server->server_host);
@@ -125,7 +118,7 @@ _init_server (glibtop *server, const unsigned features)
}
if (temp == NULL) {
/* If no value was set, we use DEFAULT_PORT. */
/* If no value was set, we use DEFAULT_PORT. */
if (server->server_port == 0)
server->server_port = DEFAULT_PORT;
} else {
@@ -137,9 +130,17 @@ _init_server (glibtop *server, const unsigned features)
temp = temp2 ? temp2 + 1 : temp2;
}
} else if (!strcmp (command, "unix")) {
/* Connect to unix domain socket. */
server->method = GLIBTOP_METHOD_UNIX;
} else {
glibtop_error_r (server, "Unknown server method '%s'",
server->server_command+1);
}
glibtop_free_r (server, command);

View File

@@ -33,6 +33,8 @@ void
glibtop_open_l (glibtop *server, const char *program_name,
const unsigned long features, const unsigned flags)
{
int connect_type;
server->name = program_name;
/* It is important to set _GLIBTOP_INIT_STATE_OPEN here when we
@@ -40,19 +42,39 @@ glibtop_open_l (glibtop *server, const char *program_name,
server->flags |= _GLIBTOP_INIT_STATE_OPEN;
if (server->method == GLIBTOP_METHOD_INET) {
int connect_type;
switch (server->method) {
case GLIBTOP_METHOD_DIRECT:
fprintf (stderr, "Calling sysdeps open function.\n");
fprintf (stderr, "Connecting to '%s' port %d.\n",
glibtop_open_r (server, program_name, features, flags);
break;
case GLIBTOP_METHOD_INET:
fprintf (stderr, "Connecting to '%s' port %ld.\n",
server->server_host, server->server_port);
connect_type = glibtop_make_connection
(server->server_host, server->server_port,
&server->socket);
fprintf (stderr, "Connect Type is %d.\n", connect_type);
server->flags |= _GLIBTOP_INIT_STATE_SERVER;
server->features = -1;
break;
case GLIBTOP_METHOD_UNIX:
fprintf (stderr, "Connecting to Unix Domain Socket.\n");
return;
connect_type = glibtop_make_connection
("unix", 0, &server->socket);
fprintf (stderr, "Connect Type is %d.\n", connect_type);
server->flags |= _GLIBTOP_INIT_STATE_SERVER;
server->features = -1;
break;
}
/* If the server has been started, ask it for its features. */
@@ -64,5 +86,8 @@ glibtop_open_l (glibtop *server, const char *program_name,
sizeof (glibtop_sysdeps), &sysdeps);
server->features = sysdeps.features;
fprintf (stderr, "Server features are %lu.\n",
server->features);
}
}

View File

@@ -28,6 +28,14 @@
memcpy (data_ptr, ptr, size); \
return size;
#define _check_data(size) \
if ((data_ptr == NULL) || (data_size != size)) { \
glibtop_error_r (server, "glibtop_set_parameter (%d): " \
"Expected %lu bytes but got %lu.", \
parameter, size, data_size); \
return; \
}
#define _strlen(ptr) (ptr ? strlen (ptr) : 0)
size_t
@@ -59,4 +67,14 @@ void
glibtop_set_parameter_l (glibtop *server, const unsigned parameter,
const void *data_ptr, size_t data_size)
{
switch (parameter) {
case GLIBTOP_PARAM_METHOD:
_check_data (sizeof (server->method));
memcpy (&server->method, data_ptr, data_size);
break;
case GLIBTOP_PARAM_FEATURES:
_check_data (sizeof (server->features));
memcpy (&server->features, data_ptr, data_size);
break;
}
}

View File

@@ -1 +1 @@
SUBDIRS = server proxy daemon
SUBDIRS = server daemon

View File

@@ -1,3 +1,4 @@
Makefile.in
Makefile
gnuserv
server_config.h

View File

@@ -10,7 +10,7 @@ bin_PROGRAMS = gnuserv
EXTRA_PROGRAMS = gtop_daemon
gnuserv_SOURCES = gnuserv.c main.c
gnuserv_SOURCES = gnuserv.c main.c slave.c
gnuserv_LDADD = $(top_builddir)/lib/libgtop.la \
$(top_builddir)/sysdeps/common/libgtop_common.la \
$(top_builddir)/sysdeps/@sysdeps_dir@/libgtop_sysdeps.la \

File diff suppressed because it is too large Load Diff

View File

@@ -21,15 +21,22 @@
#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 <glibtop/union.h>
#include <glibtop/xmalloc.h>
#include <glibtop/version.h>
#include <glibtop/command.h>
#include <glibtop/parameter.h>
#include <fcntl.h>
#include <locale.h>
#undef REAL_DEBUG
#define PARENT_DEBUG
#define MSG_BUFSZ sizeof (struct _glibtop_ipc_message)
#define MSG_MSGSZ (MSG_BUFSZ - sizeof (long))
#if defined(HAVE_GETDTABLESIZE)
#define GET_MAX_FDS() getdtablesize()
#else
@@ -38,180 +45,266 @@
#define GET_MAX_FDS() 256
#endif
#define _offset_union(p) ((char *) &response.u.p - (char *) &response)
extern void handle_slave_command __P((glibtop_command *, glibtop_response *, const void *));
#define _offset_union(p) ((char *) &resp->u.p - (char *) resp)
#define _offset_data(p) _offset_union (data.p)
static void do_output __P((int, glibtop_response *, off_t, size_t, const void *));
static int do_read __P((int, void *, size_t));
static void
do_output (int s, glibtop_response *response, off_t offset,
do_output (int s, glibtop_response *resp, off_t offset,
size_t data_size, const void *data)
{
#ifdef REAL_DEBUG
fprintf (stderr, "Really writing %d bytes at offset %d.\n",
fprintf (stderr, "Really writing %d bytes at offset %lu.\n",
sizeof (glibtop_response), offset);
#endif
response->offset = offset;
response->data_size = data_size;
resp->offset = offset;
resp->data_size = data_size;
if (send (s, response, sizeof (glibtop_response), 0) < 0)
if (send (s, resp, sizeof (glibtop_response), 0) < 0)
glibtop_warn_io ("send");
if (response->data_size) {
if (resp->data_size) {
#ifdef REAL_DEBUG
fprintf (stderr, "Writing %d bytes of data.\n", response->data_size);
fprintf (stderr, "Writing %d bytes of data.\n", resp->data_size);
#endif
if (send (s, data, response->data_size, 0) , 0)
if (send (s, data, resp->data_size, 0) , 0)
glibtop_warn_io ("send");
}
}
static void
static int
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 (s)
nread = recv (s, ptr, remaining, 0);
else
nread = read (0, ptr, remaining);
if ((already_read == 0) && (nread == 0)) {
glibtop_warn ("pid %d received eof.", getpid ());
return 0;
}
if (nread <= 0) {
glibtop_error_io ("recv");
return;
glibtop_warn_io ("recv");
return 0;
}
already_read += nread;
remaining -= nread;
(char *) ptr += nread;
#ifdef REAL_DEBUG
fprintf (stderr, "READ (%d): %d - %d - %d\n",
nread, already_read, remaining, total_size);
#endif
}
return already_read;
}
void
handle_socket_connection (glibtop *server, int s)
handle_parent_connection (int s)
{
pid_t pid;
glibtop *server = glibtop_global_server;
glibtop_response _resp, *resp = &_resp;
glibtop_command _cmnd, *cmnd = &_cmnd;
char parameter [BUFSIZ];
struct timeval tv;
glibtop_response response;
glibtop_command cmnd;
pid_t pid;
void *ptr;
tv.tv_sec = 5;
tv.tv_usec = 0;
while(1) {
do_read (s, &cmnd, sizeof (glibtop_command));
fprintf (stderr, "Parent features = %lu\n", glibtop_server_features);
#ifdef REAL_DEBUG
fprintf (stderr, "Received command %d from client.\n", cmnd.command);
while (do_read (s, &cmnd, sizeof (glibtop_command))) {
#ifdef PARENT_DEBUG
fprintf (stderr, "Parent (%d) received command %d from client.\n",
getpid (), cmnd->command);
#endif
if (cmnd.data_size >= BUFSIZ) {
glibtop_warn ("Client sent %d bytes, but buffer is %d", cmnd.size, BUFSIZ);
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);
if (cmnd->data_size) {
#ifdef PARENT_DEBUG
fprintf (stderr, "Client has %d bytes of data.\n", cmnd->data_size);
#endif
do_read (s, parameter, cmnd.data_size);
do_read (s, parameter, cmnd->data_size);
} else if (cmnd.size) {
memcpy (parameter, cmnd.parameter, cmnd.size);
} else if (cmnd->size) {
memcpy (parameter, cmnd->parameter, cmnd->size);
}
switch (cmnd.command) {
switch (cmnd->command) {
case GLIBTOP_CMND_QUIT:
do_output (s, resp, 0, 0, NULL);
fprintf (stderr, "Sending QUIT command (%d).\n",
server->socket);
glibtop_call_l (server, GLIBTOP_CMND_QUIT,
0, NULL, 0, NULL);
fprintf (stderr, "Done sending QUIT command (%d).\n",
server->socket);
close (server->socket);
return;
case GLIBTOP_CMND_SYSDEPS:
response.u.sysdeps.features = GLIBTOP_SYSDEPS_ALL;
do_output (s, &response, _offset_union (sysdeps), 0, NULL);
resp->u.sysdeps.features = GLIBTOP_SYSDEPS_ALL;
do_output (s, resp, _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);
glibtop_get_cpu_l (server, &resp->u.data.cpu);
do_output (s, resp, _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);
glibtop_get_mem_l (server, &resp->u.data.mem);
do_output (s, resp, _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);
glibtop_get_swap_l (server, &resp->u.data.swap);
do_output (s, resp, _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);
glibtop_get_uptime_l (server, &resp->u.data.uptime);
do_output (s, resp, _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);
glibtop_get_loadavg_l (server, &resp->u.data.loadavg);
do_output (s, resp, _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);
glibtop_get_shm_limits_l (server, &resp->u.data.shm_limits);
do_output (s, resp, _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);
glibtop_get_msg_limits_l (server, &resp->u.data.msg_limits);
do_output (s, resp, _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);
glibtop_get_sem_limits_l (server, &resp->u.data.sem_limits);
do_output (s, resp, _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);
ptr = glibtop_get_proclist_l (server, &resp->u.data.proclist);
do_output (s, resp, _offset_data (proclist),
resp->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);
(server, &resp->u.data.proc_state, pid);
do_output (s, resp, _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);
(server, &resp->u.data.proc_uid, pid);
do_output (s, resp, _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);
(server, &resp->u.data.proc_mem, pid);
do_output (s, resp, _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);
(server, &resp->u.data.proc_time, pid);
do_output (s, resp, _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);
(server, &resp->u.data.proc_signal, pid);
do_output (s, resp, _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);
(server, &resp->u.data.proc_kernel, pid);
do_output (s, resp, _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);
(server, &resp->u.data.proc_segment, pid);
do_output (s, resp, _offset_data (proc_segment), 0, NULL);
break;
default:
glibtop_warn ("Parent received unknown command %u",
cmnd->command);
break;
}
}
}
void
handle_child_connection (int s)
{
glibtop *server = glibtop_global_server;
glibtop_response _resp, *resp = &_resp;
glibtop_command _cmnd, *cmnd = &_cmnd;
char parameter [BUFSIZ];
void *ptr;
while (do_read (s, cmnd, sizeof (glibtop_command))) {
#ifdef CHILD_DEBUG
fprintf (stderr, "Child (%d - %d) received command "
"%d from client.\n", getpid (), s, 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 CHILD_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_QUIT:
do_output (s, resp, 0, 0, NULL);
return;
#if GLIBTOP_SUID_PROCLIST
case GLIBTOP_CMND_PROCLIST:
ptr = glibtop_get_proclist_p
(server, &resp->u.data.proclist);
do_output (s, resp, _offset_data (proclist),
resp->u.data.proclist.total, ptr);
glibtop_free_r (server, ptr);
break;
#endif
default:
handle_slave_command (cmnd, resp, parameter);
do_output (s, resp, resp->offset, 0, NULL);
break;
}
}

View File

@@ -0,0 +1,40 @@
/* This is a sample config file.
*
* Copy this file to 'server_config.h' and edit it to fix your needs !
*
* You can also use the 'server_config.pl' script to create 'server_config.h'.
*
/
#define SERVER_PORT 42800 /* Port the server should listen on. */
/* NOTE: On RedHat 5.1 nobody is UID 99 and GID 99.
*
* The 'server_config.pl' script will use the real UID and GID of 'nobody'
* on your system as default.
*
* NOTE: This only works if the server is started as root or SUID to root.
*/
#define SERVER_UID 99 /* User ID the server should run as. */
#define SERVER_GID 99 /* Group ID the server should run as. */
#define HOST_TABLE_ENTRIES 1 /* Number of entries in the host table. */
/* List of hosts that should be authorized to connect to the server.
*
* SECURITY WARNING:
* Enabling access for a particular hosts means the ALL USERS on this host will
* be allowed to connect to the server !
*
* If you want security, let this table empty and use the 'xauth' method instead.
* Look at the manpage of gnuserv (1) as shipped with GNU Emacs for more details
* about security. The server uses the same security mechanisms like gnuserv from
* XEmacs 20.3.
*/
const char *permitted_host_names [HOST_TABLE_ENTRIES] =
{ "localhost" };
unsigned long permitted_hosts [HOST_TABLE_ENTRIES];

111
src/daemon/server_config.pl Executable file
View File

@@ -0,0 +1,111 @@
#!/usr/bin/perl -w
require 5.004;
use strict;
print "Enter port the server should listen on [42800]: ";
my $port = <stdin>; chop $port;
$port = 42800 unless $port =~ /^\d+$/;
print "\nUser name or UID to run as [nobody]: ";
my $user = <stdin>; chop $user; $user = 'nobody' if $user eq '';
my ($login, $pass, $uid, $gid);
unless ($user =~ /^\d+$/) {
($login, $pass, $uid, $gid) = getpwnam ($user) or
die "User '$user' not in passwd file.";
}
my $g_default = (defined $gid) ? $gid : 'nogroup';
print "Group name or GID to run as [$g_default]: ";
my $group = <stdin>; chop $group; $group = $g_default if $group eq '';
unless ($group =~ /^\d+$/) {
$gid = getgrnam ($group) or
die "Group '$group' not in group file.";
}
print "\nEnter list of hosts which should be authorized to";
print "\nconnect to the server (terminate with a blank line):\n\n";
print "SECURITY WARNING:\n";
print " Enabling access for a particular hosts means the ALL USERS on this host will\n";
print " be allowed to connect to the server !\n\n";
print " If you want security, let this table empty and use the 'xauth' method instead.\n";
print " Look at the manpage of gnuserv (1) as shipped with GNU Emacs for more details\n";
print " about security. The server uses the same security mechanisms like gnuserv from\n";
print " XEmacs 20.3\n\n";
my @hosts = ();
my @host_addrs = ();
my @host_names = ();
while (1) {
print "Host: ";
my $host = <stdin>; chop $host;
last if $host eq '';
my ($name,$aliases,$addrtype,$length,@addrs) = gethostbyname ($host) or
die "gethostbyname (): Can't resolve '$host'";
my ($a,$b,$c,$d) = unpack('C4',$addrs[0]);
push @hosts, sprintf ("0x%02X%02X%02X%02X", $d, $c, $b, $a);
push @host_addrs, sprintf ("%d.%d.%d.%d", $a, $b, $c, $d);
push @host_names, $name;
};
print "\n";
print "This is your config:\n";
print "====================\n\n";
printf qq[%-30s: %d\n\n], 'Port', $port;
printf qq[%-30s: %d\n], 'UID', $uid;
printf qq[%-30s: %d\n\n], 'GID', $gid;
foreach (0..$#hosts) {
printf qq[%-30s (%s - %s)\n], $host_names[$_], $hosts[$_], $host_addrs [$_];
}
print "\n";
print "Accept? (yes/no) ";
my $accept = <stdin>; chop $accept;
exit unless $accept eq 'yes';
print "\n";
open CONFIG, "> server_config.h" or
die "open (server_config.h): $!";
select CONFIG;
printf qq[\#define SERVER_PORT\t\t%d\n\n], $port;
printf qq[\#define SERVER_UID\t\t%d\n], $uid;
printf qq[\#define SERVER_GID\t\t%d\n\n], $gid;
printf qq[\#define HOST_TABLE_ENTRIES\t%d\n\n], $#hosts + 1;
foreach (@host_names) {
$_ = qq["$_"];
}
printf qq[const char *permitted_host_names [HOST_TABLE_ENTRIES] = \n];
printf qq[{ %s };\n\n], join (', ', @host_names);
printf qq[unsigned long permitted_hosts [HOST_TABLE_ENTRIES];\n];
close CONFIG;
select STDOUT;
print "Your config has successfully been written to 'server_config.h'.\n";

155
src/daemon/slave.c Normal file
View File

@@ -0,0 +1,155 @@
/* $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/gnuserv.h>
#include <glibtop/open.h>
#include <glibtop/union.h>
#include <glibtop/command.h>
#include <glibtop/parameter.h>
#define _offset_union(p) ((char *) &resp->u.p - (char *) resp)
#define _offset_data(p) _offset_union (data.p)
void
handle_slave_command (glibtop_command *cmnd, glibtop_response *resp,
const void *parameter)
{
glibtop *server = glibtop_global_server;
pid_t pid;
switch (cmnd->command) {
case GLIBTOP_CMND_SYSDEPS:
resp->u.sysdeps.features = glibtop_server_features;
resp->offset = _offset_union (sysdeps);
break;
#if GLIBTOP_SUID_CPU
case GLIBTOP_CMND_CPU:
glibtop_get_cpu_p (server, &resp->u.data.cpu);
resp->offset = _offset_data (cpu);
break;
#endif
#if GLIBTOP_SUID_MEM
case GLIBTOP_CMND_MEM:
glibtop_get_mem_p (server, &resp->u.data.mem);
resp->offset = _offset_data (mem);
break;
#endif
#if GLIBTOP_SUID_SWAP
case GLIBTOP_CMND_SWAP:
glibtop_get_swap_p (server, &resp->u.data.swap);
resp->offset = _offset_data (swap);
break;
#endif
#if GLIBTOP_SUID_UPTIME
case GLIBTOP_CMND_UPTIME:
glibtop_get_uptime_p (server, &resp->u.data.uptime);
resp->offset = _offset_data (uptime);
break;
#endif
#if GLIBTOP_SUID_LOADAVG
case GLIBTOP_CMND_LOADAVG:
glibtop_get_loadavg_p (server, &resp->u.data.loadavg);
resp->offset = _offset_data (loadavg);
break;
#endif
#if GLIBTOP_SUID_SHM_LIMITS
case GLIBTOP_CMND_SHM_LIMITS:
glibtop_get_shm_limits_p (server, &resp->u.data.shm_limits);
resp->offset = _offset_data (shm_limits);
break;
#endif
#if GLIBTOP_SUID_MSG_LIMITS
case GLIBTOP_CMND_MSG_LIMITS:
glibtop_get_msg_limits_p (server, &resp->u.data.msg_limits);
resp->offset = _offset_data (msg_limits);
break;
#endif
#if GLIBTOP_SUID_SEM_LIMITS
case GLIBTOP_CMND_SEM_LIMITS:
glibtop_get_sem_limits_p (server, &resp->u.data.sem_limits);
resp->offset = _offset_data (sem_limits);
break;
#endif
#if GLIBTOP_SUID_PROC_STATE
case GLIBTOP_CMND_PROC_STATE:
memcpy (&pid, parameter, sizeof (pid_t));
glibtop_get_proc_state_p
(server, &resp->u.data.proc_state, pid);
resp->offset = _offset_data (proc_state);
break;
#endif
#if GLIBTOP_SUID_PROC_UID
case GLIBTOP_CMND_PROC_UID:
memcpy (&pid, parameter, sizeof (pid_t));
glibtop_get_proc_uid_p
(server, &resp->u.data.proc_uid, pid);
resp->offset = _offset_data (proc_uid);
break;
#endif
#if GLIBTOP_SUID_PROC_MEM
case GLIBTOP_CMND_PROC_MEM:
memcpy (&pid, parameter, sizeof (pid_t));
glibtop_get_proc_mem_p
(server, &resp->u.data.proc_mem, pid);
resp->offset = _offset_data (proc_mem);
break;
#endif
#if GLIBTOP_SUID_PROC_TIME
case GLIBTOP_CMND_PROC_TIME:
memcpy (&pid, parameter, sizeof (pid_t));
glibtop_get_proc_time_p
(server, &resp->u.data.proc_time, pid);
resp->offset = _offset_data (proc_time);
break;
#endif
#if GLIBTOP_SUID_PROC_SIGNAL
case GLIBTOP_CMND_PROC_SIGNAL:
memcpy (&pid, parameter, sizeof (pid_t));
glibtop_get_proc_signal_p
(server, &resp->u.data.proc_signal, pid);
resp->offset = _offset_data (proc_signal);
break;
#endif
#if GLIBTOP_SUID_PROC_KERNEL
case GLIBTOP_CMND_PROC_KERNEL:
memcpy (&pid, parameter, sizeof (pid_t));
glibtop_get_proc_kernel_p
(server, &resp->u.data.proc_kernel, pid);
resp->offset = _offset_data (proc_kernel);
break;
#endif
#if GLIBTOP_SUID_PROC_SEGMENT
case GLIBTOP_CMND_PROC_SEGMENT:
memcpy (&pid, parameter, sizeof (pid_t));
glibtop_get_proc_segment_p
(server, &resp->u.data.proc_segment, pid);
resp->offset = _offset_data (proc_segment);
break;
#endif
default:
glibtop_error ("Child received unknown command %u",
cmnd->command);
break;
}
}

View File

@@ -21,6 +21,8 @@
#include <glibtop/error.h>
#define DEFAULT_NAME "ERROR"
/* Prints error message and exits. */
void
@@ -30,7 +32,7 @@ glibtop_error_r (glibtop *server, char *format, ...)
va_start (ap, format);
fprintf (stderr, "%s: ", server->name);
fprintf (stderr, "%s: ", server ? server->name : DEFAULT_NAME);
vfprintf (stderr, format, ap);
fprintf (stderr, "\n");
@@ -45,7 +47,7 @@ glibtop_error_io_r (glibtop *server, char *format, ...)
va_start (ap, format);
fprintf (stderr, "%s: ", server->name);
fprintf (stderr, "%s: ", server ? server->name : DEFAULT_NAME);
vfprintf (stderr, format, ap);
fprintf (stderr, ": %s\n", strerror (errno));
@@ -60,7 +62,7 @@ glibtop_warn_r (glibtop *server, char *format, ...)
va_start (ap, format);
fprintf (stderr, "%s: ", server->name);
fprintf (stderr, "%s: ", server ? server->name : DEFAULT_NAME);
vfprintf (stderr, format, ap);
fprintf (stderr, "\n");
@@ -74,7 +76,7 @@ glibtop_warn_io_r (glibtop *server, char *format, ...)
va_start (ap, format);
fprintf (stderr, "%s: ", server->name);
fprintf (stderr, "%s: ", server ? server->name : DEFAULT_NAME);
vfprintf (stderr, format, ap);
fprintf (stderr, ": %s\n", strerror (errno));

View File

@@ -1,22 +1,22 @@
/* -*-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.
*/
* 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
* 11-Nov-1990 bristor@simba
* Added EOT stuff.
*/
@@ -29,35 +29,30 @@
* ../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 <glibtop.h>
#include <glibtop/gnuserv.h>
#include <fcntl.h>
#ifdef SYSV_IPC
static int connect_to_ipc_server (void);
#endif
#ifdef UNIX_DOMAIN_SOCKETS
static int connect_to_unix_server (void);
static int connect_to_unix_server __P((void));
#endif
#ifdef INTERNET_DOMAIN_SOCKETS
static int connect_to_internet_server (const char *serverhost, u_short port);
static int connect_to_internet_server __P((const char *, u_short));
#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)
#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)
#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 <arpa/inet.h>
@@ -69,365 +64,309 @@ glibtop_make_connection (hostarg, portarg, s)
int *s;
{
#ifdef INTERNET_DOMAIN_SOCKETS
char *ptr;
if (hostarg == NULL)
hostarg = getenv ("LIBGTOP_HOST");
if (portarg == 0 && (ptr = getenv("LIBGTOP_PORT")) != NULL)
portarg = atoi (ptr);
char *ptr;
if (hostarg == NULL)
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 LIBGTOP_HOST,
* so obey it. */
if (hostarg != NULL) {
/* 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 ();
return (int) CONN_UNIX;
}
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;
*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. */
} 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;
*s = connect_to_unix_server ();
return (int) CONN_UNIX;
#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;
}
{
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/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)
glibtop_error_io ("unable to access msg queue");
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.
*/
* send_string -- send string to socket.
*/
#if 0
static void
send_string(s,msg)
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 */
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 */
} /* send_string */
/*
read_line -- read a \n terminated line from a socket
*/
* read_line -- read a \n terminated line from a socket
*/
static int
read_line(int s, char *dest)
read_line (int s, char *dest)
{
int length;
int offset=0;
char buffer[GSERV_BUFSZ+1];
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 */
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
#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.
*/
* 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 */
int s; /* connected socket descriptor */
struct sockaddr_un server; /* for unix connections */
if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) < 0)
glibtop_error_io ("unable to create socket");
server.sun_family = AF_UNIX;
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/lgtddir%d/lgtd", (int)geteuid());
#else /* HIDE_UNIX_SOCKET */
sprintf(server.sun_path, "/tmp/lgtd%d", (int)geteuid());
sprintf (server.sun_path, "/tmp/lgtddir%d/lgtd", (int) geteuid ());
#else /* HIDE_UNIX_SOCKET */
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)
glibtop_error_io ("unable to connect to local");
if (connect (s, (struct sockaddr *) &server, strlen (server.sun_path) + 2) < 0)
glibtop_error_io ("unable to connect to local");
return(s);
return (s);
} /* connect_to_unix_server */
} /* 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.
*/
long glibtop_internet_addr (host)
* internet_addr -- return the internet addr of the hostname or
* internet address passed. Return -1 on error.
*/
long
glibtop_internet_addr (host)
const char *host;
{
struct hostent *hp; /* pointer to host info for remote host */
IN_ADDR numeric_addr; /* host address */
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 {
glibtop_warn_io ("gethostbyname (%s)", host);
return -1;
}
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 {
glibtop_warn_io ("gethostbyname (%s)", host);
return -1;
}
} /* glibtop_internet_addr */
} /* glibtop_internet_addr */
#ifdef AUTH_MAGIC_COOKIE
# include <X11/X.h>
# include <X11/Xauth.h>
#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.
*/
* 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 (const 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 */
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;
/* clear out address structures */
memset ((char *) &peeraddr_in, 0, sizeof (struct sockaddr_in));
/* look up the server host's internet address */
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 ("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);
/* Create the socket. */
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)
glibtop_error_io ("unable to connect to remote");
/* 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 (((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 ("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);
/* Create the socket. */
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)
glibtop_error_io ("unable to connect to remote");
#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);
/* send credentials using MIT-MAGIC-COOKIE-1 protocol */
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);
}
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));
sprintf (buf, "%s\n", DEFAUTH_NAME);
write (s, buf, strlen (buf));
return(s);
return (s);
} /* connect_to_internet_server */
} /* 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.
*/
* disconnect_from_server -- inform the server that sending has finished, and wait for
* its reply.
*/
#if 0
static void
disconnect_from_server(s,echo)
disconnect_from_server (s, echo)
int s;
int echo;
{
#if 0
char buffer[REPLYSIZ+1];
char buffer[REPLYSIZ + 1];
#else
char buffer[GSERV_BUFSZ+1];
char buffer[GSERV_BUFSZ + 1];
#endif
int add_newline = 1;
int length;
int add_newline = 1;
int length;
send_string(s,EOT_STR); /* make sure server gets string */
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 !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 */
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 */
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 */
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 */
if (echo && add_newline)
putchar ('\n');
} /* disconnect_from_server */
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
#endif /* INTERNET_DOMAIN_SOCKETS || UNIX_DOMAIN_SOCKETS */

View File

@@ -34,10 +34,19 @@ void free ();
#include <strings.h>
#endif
#include <glibtop.h>
#include <glibtop/xmalloc.h>
#undef xmalloc
#undef xrealloc
#undef xstrdup
#define xmalloc(p1) glibtop_malloc_r (NULL, p1)
#define xrealloc(p1,p2) glibtop_realloc_r (NULL, p1, p2)
#define xstrdup(p1) glibtop_strdup_r (NULL, p1)
#define xfree(p1) glibtop_free_r (NULL, p1)
char *strstr ();
char *xmalloc ();
char *xrealloc ();
char *xstrdup ();
void error ();
#ifdef HAVE_SYS_PARAM_H

View File

@@ -18,8 +18,8 @@ libgtop_guile_la_SOURCES = guile.c
BUILT_SOURCES = guile.c
guile.c: guile.awk $(top_builddir)/config.h $(top_builddir)/features.def
$(AWK) -f $(srcdir)/guile.awk < $(top_builddir)/features.def > gnc-t
guile.c: guile.awk $(top_builddir)/config.h $(top_srcdir)/features.def
$(AWK) -f $(srcdir)/guile.awk < $(top_srcdir)/features.def > gnc-t
mv gnc-t guile.c
EXTRA_DIST = guile.awk

View File

@@ -12,8 +12,8 @@ libgtop_guile_names_la_SOURCES = guile-names.c
BUILT_SOURCES = guile-names.c
guile-names.c: guile-names.awk $(top_builddir)/config.h $(top_builddir)/features.def
$(AWK) -f $(srcdir)/guile-names.awk < $(top_builddir)/features.def > gnc-t
guile-names.c: guile-names.awk $(top_builddir)/config.h $(top_srcdir)/features.def
$(AWK) -f $(srcdir)/guile-names.awk < $(top_srcdir)/features.def > gnc-t
mv gnc-t guile-names.c
EXTRA_DIST = guile-names.awk

View File

@@ -27,7 +27,7 @@ glibtop *glibtop_global_server = NULL;
glibtop *
glibtop_init_r (glibtop **server, const unsigned long features,
const unsigned flags)
const unsigned flags)
{
if (*server != NULL)
return *server;
@@ -37,7 +37,7 @@ glibtop_init_r (glibtop **server, const unsigned long features,
if (glibtop_global_server == NULL) {
glibtop_global_server = &_glibtop_global_server;
glibtop_open_r (glibtop_global_server, "glibtop",
features, flags);
features, flags);
}
return *server = glibtop_global_server;

View File

@@ -48,7 +48,8 @@ glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
if (!f) return;
fscanf (f, "%*[^\n]\nMem: %lu %lu %lu %lu %lu %lu\n",
&buf->total, &buf->used, &buf->free, &buf->shared, &buf->buffer, &buf->cached);
&buf->total, &buf->used, &buf->free, &buf->shared,
&buf->buffer, &buf->cached);
buf->user = buf->total - buf->free - buf->shared - buf->buffer;

View File

@@ -52,9 +52,8 @@ static void set_linux_version(void) {
void
glibtop_open_r (glibtop *server, const char *program_name,
const unsigned long features, const unsigned flags)
const unsigned long features, const unsigned flags)
{
memset (server, 0, sizeof (glibtop));
server->name = program_name;
set_linux_version ();

View File

@@ -73,8 +73,10 @@ glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, pid_t pid)
return;
}
input [nread] = 0;
fclose (f);
input [nread] = 0;
/* This is from guile-utils/gtop/proc/readproc.c */
/* split into "PID (cmd" and "<rest>" */

View File

@@ -24,5 +24,5 @@
/* Closes pipe to gtop server. */
void
glibtop_close (glibtop *server)
glibtop_close_l (glibtop *server)
{ }

View File

@@ -25,7 +25,7 @@
/* Provides information about cpu usage. */
void
glibtop_get_cpu_r (glibtop *server, glibtop_cpu *buf)
glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
{
memset (buf, 0, sizeof (glibtop_cpu));
}

View File

@@ -0,0 +1,46 @@
/* $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. */
#ifndef __GLIBTOP_SERVER_H__
#define __GLIBTOP_SERVER_H__
__BEGIN_DECLS
#define GLIBTOP_SUID_CPU 0
#define GLIBTOP_SUID_MEM 0
#define GLIBTOP_SUID_SWAP 0
#define GLIBTOP_SUID_UPTIME 0
#define GLIBTOP_SUID_LOADAVG 0
#define GLIBTOP_SUID_SHM_LIMITS 0
#define GLIBTOP_SUID_MSG_LIMITS 0
#define GLIBTOP_SUID_SEM_LIMITS 0
#define GLIBTOP_SUID_PROCLIST 0
#define GLIBTOP_SUID_PROC_STATE 0
#define GLIBTOP_SUID_PROC_UID 0
#define GLIBTOP_SUID_PROC_MEM 0
#define GLIBTOP_SUID_PROC_TIME 0
#define GLIBTOP_SUID_PROC_SIGNAL 0
#define GLIBTOP_SUID_PROC_KERNEL 0
#define GLIBTOP_SUID_PROC_SEGMENT 0
__END_DECLS
#endif

View File

@@ -26,14 +26,16 @@ static glibtop _glibtop_global_server;
glibtop *glibtop_global_server = NULL;
glibtop *
glibtop_init_r (glibtop **server)
glibtop_init_r (glibtop **server, const unsigned long features,
const unsigned flags)
{
if (*server != NULL)
return *server;
if (glibtop_global_server == NULL) {
glibtop_global_server = &_glibtop_global_server;
glibtop_open (glibtop_global_server, "glibtop");
glibtop_open_r (glibtop_global_server, "glibtop",
features, flags);
}
return *server = glibtop_global_server;

View File

@@ -25,7 +25,7 @@
/* Provides load averange. */
void
glibtop_get_loadavg_r (glibtop *server, glibtop_loadavg *buf)
glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
{
memset (buf, 0, sizeof (glibtop_loadavg));
}

View File

@@ -25,7 +25,7 @@
/* Provides information about memory usage. */
void
glibtop_get_mem_r (glibtop *server, glibtop_mem *buf)
glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
{
memset (buf, 0, sizeof (glibtop_mem));
}

View File

@@ -24,7 +24,7 @@
/* Provides information about sysv ipc limits. */
void
glibtop_get_msg_limits_r (glibtop *server, glibtop_msg_limits *buf)
glibtop_get_msg_limits_s (glibtop *server, glibtop_msg_limits *buf)
{
memset (buf, 0, sizeof (glibtop_msg_limits));
}

View File

@@ -24,8 +24,8 @@
/* Opens pipe to gtop server. Returns 0 on success and -1 on error. */
void
glibtop_open (glibtop *server, const char *program_name)
glibtop_open_r (glibtop *server, const char *program_name,
const unsigned long features, const unsigned flags)
{
memset (server, 0, sizeof (glibtop));
server->name = program_name;
}

View File

@@ -25,8 +25,8 @@
/* Provides detailed information about a process. */
void
glibtop_get_proc_kernel_r (glibtop *server, glibtop_proc_kernel *buf,
pid_t pid)
glibtop_get_proc_kernel_s (glibtop *server, glibtop_proc_kernel *buf,
pid_t pid)
{
memset (buf, 0, sizeof (glibtop_proc_kernel));
}

View File

@@ -32,7 +32,7 @@
* each buf->size big. The total size is stored in buf->total. */
unsigned *
glibtop_get_proclist_r (glibtop *server, glibtop_proclist *buf)
glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf)
{
memset (buf, 0, sizeof (glibtop_proclist));
return NULL;

View File

@@ -25,8 +25,8 @@
/* Provides detailed information about a process. */
void
glibtop_get_proc_mem_r (glibtop *server, glibtop_proc_mem *buf,
pid_t pid)
glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf,
pid_t pid)
{
memset (buf, 0, sizeof (glibtop_proc_mem));
}

View File

@@ -25,8 +25,8 @@
/* Provides detailed information about a process. */
void
glibtop_get_proc_segment_r (glibtop *server, glibtop_proc_segment *buf,
pid_t pid)
glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf,
pid_t pid)
{
memset (buf, 0, sizeof (glibtop_proc_segment));
}

View File

@@ -25,7 +25,7 @@
/* Provides detailed information about a process. */
void
glibtop_get_proc_signal_r (glibtop *server, glibtop_proc_signal *buf,
glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf,
pid_t pid)
{
memset (buf, 0, sizeof (glibtop_proc_signal));

View File

@@ -25,8 +25,8 @@
/* Provides detailed information about a process. */
void
glibtop_get_proc_state_r (glibtop *server, glibtop_proc_state *buf,
pid_t pid)
glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf,
pid_t pid)
{
memset (buf, 0, sizeof (glibtop_proc_state));
}

View File

@@ -25,8 +25,8 @@
/* Provides detailed information about a process. */
void
glibtop_get_proc_time_r (glibtop *server, glibtop_proc_time *buf,
pid_t pid)
glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf,
pid_t pid)
{
memset (buf, 0, sizeof (glibtop_proc_time));
}

View File

@@ -25,8 +25,8 @@
/* Provides detailed information about a process. */
void
glibtop_get_proc_uid_r (glibtop *server, glibtop_proc_uid *buf,
pid_t pid)
glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf,
pid_t pid)
{
memset (buf, 0, sizeof (glibtop_proc_uid));
}

View File

@@ -24,7 +24,7 @@
/* Provides information about sysv sem limits. */
void
glibtop_get_sem_limits_r (glibtop *server, glibtop_sem_limits *buf)
glibtop_get_sem_limits_s (glibtop *server, glibtop_sem_limits *buf)
{
memset (buf, 0, sizeof (glibtop_sem_limits));
}

View File

@@ -24,7 +24,7 @@
/* Provides information about sysv ipc limits. */
void
glibtop_get_shm_limits_r (glibtop *server, glibtop_shm_limits *buf)
glibtop_get_shm_limits_s (glibtop *server, glibtop_shm_limits *buf)
{
memset (buf, 0, sizeof (glibtop_shm_limits));
}

View File

@@ -25,7 +25,7 @@
/* Provides information about swap usage. */
void
glibtop_get_swap_r (glibtop *server, glibtop_swap *buf)
glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
{
memset (buf, 0, sizeof (glibtop_swap));
}

View File

@@ -25,7 +25,7 @@
/* Provides uptime and idle time. */
void
glibtop_get_uptime_r (glibtop *server, glibtop_uptime *buf)
glibtop_get_uptime_s (glibtop *server, glibtop_uptime *buf)
{
memset (buf, 0, sizeof (glibtop_uptime));
}

View File

@@ -27,7 +27,7 @@ glibtop *glibtop_global_server = NULL;
glibtop *
glibtop_init_r (glibtop **server, const unsigned long features,
const unsigned flags)
const unsigned flags)
{
if (*server != NULL)
return *server;
@@ -35,7 +35,7 @@ glibtop_init_r (glibtop **server, const unsigned long features,
if (glibtop_global_server == NULL) {
glibtop_global_server = &_glibtop_global_server;
glibtop_open_r (glibtop_global_server, "glibtop",
features, flags);
features, flags);
}
return *server = glibtop_global_server;

View File

@@ -19,15 +19,45 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <config.h>
#include <glibtop.h>
#include <glibtop/loadavg.h>
static const unsigned long _glibtop_sysdeps_loadavg =
(1 << GLIBTOP_LOADAVG_LOADAVG);
/* Provides load averange. */
void
glibtop_get_loadavg_p (glibtop *server, glibtop_loadavg *buf)
{
load_avg avenrun [3];
int i;
glibtop_init_r (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_loadavg));
/* !!! THE FOLLOWING CODE RUNS SGID KMEM - CHANGE WITH CAUTION !!! */
setregid (server->machine.gid, server->machine.egid);
/* get the load average array */
(void) _glibtop_getkval (server, _glibtop_nlist [X_AVENRUN].n_value,
(int *) avenrun, sizeof (avenrun),
_glibtop_nlist [X_AVENRUN].n_name);
if (setregid (server->machine.egid, server->machine.gid))
_exit (1);
/* !!! END OF SGID KMEM PART !!! */
for (i = 0; i < 3; i++) {
/* Calculate loadavg values from avenrun. */
buf->loadavg [i] = loaddouble (avenrun [i]);
}
/* Now we can set the flags. */
buf->flags = _glibtop_sysdeps_loadavg;
}

57
sysdeps/sun4/loadavg.h Normal file
View File

@@ -0,0 +1,57 @@
/*
* Top - a top users display for Berkeley Unix
*
* Defines required to access load average figures.
*
* This include file sets up everything we need to access the load average
* values in the kernel in a machine independent way. First, it sets the
* typedef "load_avg" to be either double or long (depending on what is
* needed), then it defines these macros appropriately:
*
* loaddouble(la) - convert load_avg to double.
* intload(i) - convert integer to load_avg.
*/
/*
* We assume that if FSCALE is defined, then avenrun and ccpu are type long.
* If your machine is an exception (mips, perhaps?) then make adjustments
* here.
*
* Defined types: load_avg for load averages, pctcpu for cpu percentages.
*/
#if defined(mips) && !defined(NetBSD)
# include <sys/fixpoint.h>
# if defined(FBITS) && !defined(FSCALE)
# define FSCALE (1 << FBITS) /* mips */
# endif
#endif
#ifdef FSCALE
# define FIXED_LOADAVG FSCALE
# define FIXED_PCTCPU FSCALE
#endif
#ifdef ibm032
# undef FIXED_LOADAVG
# undef FIXED_PCTCPU
# define FIXED_PCTCPU PCT_SCALE
#endif
#ifdef FIXED_PCTCPU
typedef long pctcpu;
# define pctdouble(p) ((double)(p) / FIXED_PCTCPU)
#else
typedef double pctcpu;
# define pctdouble(p) (p)
#endif
#ifdef FIXED_LOADAVG
typedef long load_avg;
# define loaddouble(la) ((double)(la) / FIXED_LOADAVG)
# define intload(i) ((int)((i) * FIXED_LOADAVG))
#else
typedef double load_avg;
# define loaddouble(la) (la)
# define intload(i) ((double)(i))
#endif

View File

@@ -64,7 +64,6 @@ glibtop_open_r (glibtop *server, const char *program_name,
/* !!! WE ARE ROOT HERE - CHANGE WITH CAUTION !!! */
memset (server, 0, sizeof (glibtop));
server->name = program_name;
server->machine.uid = getuid ();