Summary of this long ChangeLog:

* Splitted `libgtop_sysdeps.la' into `libgtop_sysdeps.la' and
   `libgtop_sysdeps_suid.la'.

   Everything that needs to be suid/sgid is in `libgtop_sysdeps_suid.la'
   and the rest in `libgtop_sysdeps.la'.

   The functions from `libgtop_sysdeps_suid.la' have the `_p' prefix and
   the ones from `libgtop_sysdeps.la' the `_s' prefix.

   The suid library uses `glibtop_open_p' and `glibtop_close_p', the
   normal one `glibtop_init_s' (found in lib/init.c), `glibtop_open_s'
   and `glibtop_close_s'.

 * Added `libgtop_suid_common.la' containing stuff from sysdeps/common
   that is required from the suid server (currently everything from
   error.c and xmalloc.c).

   This means, we can add some more stuff to `libgtop_common.la' without
   the risk that it may be dangerous in the suid server.

 * The ``library order'' is much clearer now:

   -> `libgtop.la' (from lib/) contains user-level stuff;
      all functions except `glibtop_init_r' have the `_l'
      suffix.

   -> `libgtop_common.la' (from sysdeps/common/) contains stuff
      that is common among the sysdeps directories.
      use anything from `libgtop_sysdeps.la' and
      `libgtop_sysdeps_suid.la'.

   -> `libgtop_sysdeps.la' (from sysdeps/<sysdeps_dir>/) contains
      everything from the sysdeps directory that doesn't need to
      be suid/sgid.

   -> `libgtop_suid_common.la' (from sysdeps/common/) is used from
      the suid server instead of `libgtop_common.la'.

   -> `libgtop_sysdeps_suid.la' (from sysdeps/<sysdeps_dir>/) contains
      everything from the sysdeps directory that needs to be in the
      suid server.

 * To summarize: the server is linked only with functions that need
   to be suid and everything else is linked only with functions that
   do not need to be suid.

Martin

1998-07-22  Martin Baulig  <martin@home-of-linux.org>

	* lib/init.c (glibtop_init_s): Added this init function of
	the sysdeps directory `libgtop_sysdeps.la'.

	* lib/open.c (glibtop_open_l): Unconditionally calling
	`glibtop_init_s' after server initialization.

	* lib/lib.awk: Removed references to functions from
	`libgtop_sysdeps_suid.la' to avoid undefined symbols.

	* sysdeps/stub/open.c (glibtop_open_s): Renamed this
	function from `glibtop_open_r'.

	* sysdeps/stub/close.c (glibtop_close_s): Renamed this
	function from `glibtop_close_l'.

	* sysdeps/kernel/open.c (glibtop_open_s): Renamed this
	function from `glibtop_open_r'.

	* sysdeps/kernel/close.c (glibtop_close_s): Renamed this
	function from `glibtop_close_l'.

	* sysdeps/linux/open.c (glibtop_open_s): Renamed this
	function from `glibtop_open_r'.

	* sysdeps/linux/close.c (glibtop_close_s): Renamed this
	function from `glibtop_close_l'.

	* sysdeps/osf1/Makefile.am (lib_LTLIBRARIES): Added
	`libgtop_sysdeps_suid.la' for the suid server.

	* sysdeps/osf1/open_suid.c (glibtop_open_p): New file.
	Contains all stuff that was formerly in `open.c'.

	* sysdeps/osf1/open.c: Moved everything from here into
	the new file `open_suid.c'.

	* sysdeps/osf1/open.c (glibtop_open_s): New function.

	* sysdeps/osf1/close_suid.c (glibtop_close_p): New file.

	* sysdeps/osf1/close.c (glibtop_close_s): New function.

	* sysdeps/osf1/*.c: Using the new init, open and close
	functions.

	* sysdeps/sun4/Makefile.am (lib_LTLIBRARIES): Added
	`libgtop_sysdeps_suid.la' for the suid server.

	* sysdeps/sun4/nosuid.c (glibtop_open_s, glibtop_close_s): New file

	* sysdeps/sun4/*.c: All functions now have the `_p' suffix.

	* sysdeps/common/Makefile.am (lib_LTLIBRARIES): Added
	`libgtop_suid_common.la' which only contains stuff that is
	needed in the suid parts.

	* sysdeps/common/xmalloc.c: Using `glibtop_error_io_r' instead
	of `glibtop_error_r'.

	* sysdeps/{kernel, linux, osf1, sun4, stub}/init.c: Removed.
	`glibtop_init_s' has been moved into `lib/init.c' since it's the
	same in all the sysdeps directories.

	* src/server/main.c: It is now an error to request a feature that
	does not need the suid server.

	* src/proxy: Removed.
This commit is contained in:
Martin Baulig
1998-07-22 09:26:43 +00:00
committed by Martin Baulig
parent 7efcda3082
commit 5e97af535f
75 changed files with 622 additions and 523 deletions

View File

@@ -1,8 +1,6 @@
Makefile Makefile
Makefile.in Makefile.in
aclocal.m4 aclocal.m4
alpha-dec-osf1
autoh31167
config.cache config.cache
config.h config.h
config.h.in config.h.in
@@ -25,3 +23,4 @@ sun4
sun4sol2 sun4sol2
support support
i386-freebsd i386-freebsd
alpha-dec-osf3.0

View File

@@ -1,3 +1,73 @@
1998-07-22 Martin Baulig <martin@home-of-linux.org>
* lib/init.c (glibtop_init_s): Added this init function of
the sysdeps directory `libgtop_sysdeps.la'.
* lib/open.c (glibtop_open_l): Unconditionally calling
`glibtop_init_s' after server initialization.
* lib/lib.awk: Removed references to functions from
`libgtop_sysdeps_suid.la' to avoid undefined symbols.
* sysdeps/stub/open.c (glibtop_open_s): Renamed this
function from `glibtop_open_r'.
* sysdeps/stub/close.c (glibtop_close_s): Renamed this
function from `glibtop_close_l'.
* sysdeps/kernel/open.c (glibtop_open_s): Renamed this
function from `glibtop_open_r'.
* sysdeps/kernel/close.c (glibtop_close_s): Renamed this
function from `glibtop_close_l'.
* sysdeps/linux/open.c (glibtop_open_s): Renamed this
function from `glibtop_open_r'.
* sysdeps/linux/close.c (glibtop_close_s): Renamed this
function from `glibtop_close_l'.
* sysdeps/osf1/Makefile.am (lib_LTLIBRARIES): Added
`libgtop_sysdeps_suid.la' for the suid server.
* sysdeps/osf1/open_suid.c (glibtop_open_p): New file.
Contains all stuff that was formerly in `open.c'.
* sysdeps/osf1/open.c: Moved everything from here into
the new file `open_suid.c'.
* sysdeps/osf1/open.c (glibtop_open_s): New function.
* sysdeps/osf1/close_suid.c (glibtop_close_p): New file.
* sysdeps/osf1/close.c (glibtop_close_s): New function.
* sysdeps/osf1/*.c: Using the new init, open and close
functions.
* sysdeps/sun4/Makefile.am (lib_LTLIBRARIES): Added
`libgtop_sysdeps_suid.la' for the suid server.
* sysdeps/sun4/nosuid.c (glibtop_open_s, glibtop_close_s): New file
* sysdeps/sun4/*.c: All functions now have the `_p' suffix.
* sysdeps/common/Makefile.am (lib_LTLIBRARIES): Added
`libgtop_suid_common.la' which only contains stuff that is
needed in the suid parts.
* sysdeps/common/xmalloc.c: Using `glibtop_error_io_r' instead
of `glibtop_error_r'.
* sysdeps/{kernel, linux, osf1, sun4, stub}/init.c: Removed.
`glibtop_init_s' has been moved into `lib/init.c' since it's the
same in all the sysdeps directories.
* src/server/main.c: It is now an error to request a feature that
does not need the suid server.
* src/proxy: Removed.
1998-07-21 Martin Baulig <martin@home-of-linux.org> 1998-07-21 Martin Baulig <martin@home-of-linux.org>
* doc/ChangeLog: New file. * doc/ChangeLog: New file.

View File

@@ -231,6 +231,13 @@ if test "$need_gnome_support" = yes; then
fi fi
fi fi
if test x$libgtop_need_server = xyes ; then
sysdeps_suid_lib="\$(top_builddir)/sysdeps/\$(sysdeps_dir)/libgtop_sysdeps_suid.la"
else
sysdeps_suid_lib=
fi
AC_SUBST(sysdeps_suid_lib)
AC_OUTPUT([ AC_OUTPUT([
Makefile Makefile
po/Makefile.in po/Makefile.in

View File

@@ -211,7 +211,7 @@ main (int argc, char *argv [])
glibtop_get_proc_signal (&data.proc_signal, pid); glibtop_get_proc_signal (&data.proc_signal, pid);
printf ("Proc_Signal PID %5u (0x%08lx): " printf ("Proc_Signal PID %5u (0x%08lx): "
"%d %d %d %d\n", pid, data.proc_signal.flags, "%lu %lu %lu %lu\n", pid, data.proc_signal.flags,
data.proc_signal.signal, data.proc_signal.blocked, data.proc_signal.signal, data.proc_signal.blocked,
data.proc_signal.sigignore, data.proc_signal.sigcatch); data.proc_signal.sigignore, data.proc_signal.sigcatch);
@@ -282,7 +282,7 @@ main (int argc, char *argv [])
glibtop_get_proc_signal (&data.proc_signal, ppid); glibtop_get_proc_signal (&data.proc_signal, ppid);
printf ("Proc_Signal PPID %5u (0x%08lx): " printf ("Proc_Signal PPID %5u (0x%08lx): "
"%d %d %d %d\n", ppid, data.proc_signal.flags, "%lu %lu %lu %u\n", ppid, data.proc_signal.flags,
data.proc_signal.signal, data.proc_signal.blocked, data.proc_signal.signal, data.proc_signal.blocked,
data.proc_signal.sigignore, data.proc_signal.sigcatch); data.proc_signal.sigignore, data.proc_signal.sigcatch);
@@ -353,7 +353,7 @@ main (int argc, char *argv [])
glibtop_get_proc_signal (&data.proc_signal, 1); glibtop_get_proc_signal (&data.proc_signal, 1);
printf ("Proc_Signal INIT %5u (0x%08lx): " printf ("Proc_Signal INIT %5u (0x%08lx): "
"%d %d %d %d\n", 1, data.proc_signal.flags, "%lu %lu %lu %lu\n", 1, data.proc_signal.flags,
data.proc_signal.signal, data.proc_signal.blocked, data.proc_signal.signal, data.proc_signal.blocked,
data.proc_signal.sigignore, data.proc_signal.sigcatch); data.proc_signal.sigignore, data.proc_signal.sigcatch);

View File

@@ -110,7 +110,7 @@ main (int argc, char *argv [])
glibtop_get_proc_signal (&data.proc_signal, pid); glibtop_get_proc_signal (&data.proc_signal, pid);
fprintf (stderr, "Proc_Signal PID %5u (0x%08lx): " fprintf (stderr, "Proc_Signal PID %5u (0x%08lx): "
"%d %d %d %d\n", pid, data.proc_signal.flags, "%lu %lu %lu %lu\n", pid, data.proc_signal.flags,
data.proc_signal.signal, data.proc_signal.blocked, data.proc_signal.signal, data.proc_signal.blocked,
data.proc_signal.sigignore, data.proc_signal.sigcatch); data.proc_signal.sigignore, data.proc_signal.sigcatch);

View File

@@ -11,6 +11,6 @@ proc_state str(cmd):char(state):ulong(uid,gid)
proc_uid long(uid,euid,gid,egid,pid,ppid,pgrp,session,tty,tpgid,priority,nice) proc_uid long(uid,euid,gid,egid,pid,ppid,pgrp,session,tty,tpgid,priority,nice)
proc_mem long(size,vsize,resident,share,rss,rss_rlim) proc_mem long(size,vsize,resident,share,rss,rss_rlim)
proc_time long(start_time,utime,stime,cutime,cstime,timeout,it_real_value) proc_time long(start_time,utime,stime,cutime,cstime,timeout,it_real_value)
proc_signal long(signal,blocked,sigignore,sigcatch) proc_signal ulong(signal,blocked,sigignore,sigcatch)
proc_kernel ulong(k_flags,min_flt,maj_flt,cmin_flt,cmaj_flt,kstk_esp,kstk_eip,wchan) proc_kernel ulong(k_flags,min_flt,maj_flt,cmin_flt,cmaj_flt,kstk_esp,kstk_eip,wchan)
proc_segment long(trs,lrs,drs,dt):ulong(start_code,end_code,start_stack) proc_segment long(trs,lrs,drs,dt):ulong(start_code,end_code,start_stack)

View File

@@ -63,6 +63,7 @@ extern const unsigned long glibtop_server_features;
#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)); extern glibtop *glibtop_init_r __P((glibtop **, const unsigned long, const unsigned));
extern glibtop *glibtop_init_s __P((glibtop **, const unsigned long, const unsigned));
#ifdef HAVE_GUILE #ifdef HAVE_GUILE

View File

@@ -28,6 +28,9 @@ __BEGIN_DECLS
extern void glibtop_close_r __P((glibtop *)); extern void glibtop_close_r __P((glibtop *));
extern void glibtop_close_s __P((glibtop *));
extern void glibtop_close_p __P((glibtop *));
__END_DECLS __END_DECLS
#endif #endif

View File

@@ -42,7 +42,8 @@ __BEGIN_DECLS
extern void glibtop_open_l __P((glibtop *, const char *, const unsigned long, const unsigned)); 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)); extern void glibtop_open_p __P((glibtop *, const char *, const unsigned long, const unsigned));
extern void glibtop_open_s __P((glibtop *, const char *, const unsigned long, const unsigned));
__END_DECLS __END_DECLS

View File

@@ -41,7 +41,7 @@ typedef struct _glibtop_proc_signal glibtop_proc_signal;
struct _glibtop_proc_signal struct _glibtop_proc_signal
{ {
unsigned long flags; unsigned long flags;
int signal, /* mask of pending signals */ unsigned long signal, /* mask of pending signals */
blocked, /* mask of blocked signals */ blocked, /* mask of blocked signals */
sigignore, /* mask of ignored signals */ sigignore, /* mask of ignored signals */
sigcatch; /* mask of caught signals */ sigcatch; /* mask of caught signals */

View File

@@ -191,3 +191,21 @@ glibtop_init_r (glibtop **server_ptr, const unsigned long features,
return server; return server;
} }
glibtop *
glibtop_init_s (glibtop **server, const unsigned long features,
const unsigned flags)
{
if (*server != NULL)
return *server;
fprintf (stderr, "DEBUG: %s (%d)\n", __FILE__, __LINE__);
if (glibtop_global_server == NULL) {
glibtop_global_server = &_glibtop_global_server;
glibtop_open_s (glibtop_global_server, "glibtop",
features, flags);
}
return *server = glibtop_global_server;
}

View File

@@ -2,14 +2,13 @@ BEGIN {
print "/* lib.c */"; print "/* lib.c */";
print "/* This is a generated file. Please modify `lib.awk' */"; print "/* This is a generated file. Please modify `lib.awk' */";
print ""; print "";
print "#include <glibtop.h>"; print "#include <glibtop.h>";
print "#include <glibtop/open.h>"; print "#include <glibtop/open.h>";
print "#include <glibtop/sysdeps.h>"; print "#include <glibtop/sysdeps.h>";
print "#include <glibtop/command.h>"; print "#include <glibtop/command.h>";
print ""; print "";
} }
function output(feature) { function output(feature) {
@@ -25,7 +24,7 @@ function output(feature) {
} else { } else {
param = ""; param = "";
} }
print "glibtop_get_"feature"_l (glibtop *server, glibtop_"feature" *buf"param")"; print "glibtop_get_"feature"_l (glibtop *server, glibtop_"feature" *buf"param")";
print "{"; print "{";
print "\tglibtop_init_r (&server, GLIBTOP_SYSDEPS_"toupper(feature)", 0);"; print "\tglibtop_init_r (&server, GLIBTOP_SYSDEPS_"toupper(feature)", 0);";
@@ -33,23 +32,37 @@ function output(feature) {
print "\tif ((server->flags & _GLIBTOP_INIT_STATE_SERVER) &&"; print "\tif ((server->flags & _GLIBTOP_INIT_STATE_SERVER) &&";
print "\t (server->features & (1 << GLIBTOP_SYSDEPS_"toupper(feature)")))"; print "\t (server->features & (1 << GLIBTOP_SYSDEPS_"toupper(feature)")))";
print "\t{"; print "\t{";
if (feature ~ /^proc_/) { if (feature ~ /^proc_/) {
print "\t\t"prefix"glibtop_call_l (server, GLIBTOP_CMND_"toupper(feature)", sizeof (pid_t),"; print "\t\tglibtop_call_l (server, GLIBTOP_CMND_"toupper(feature)",";
print "\t\t\t\t&pid, sizeof (glibtop_"feature"), buf);"; print "\t\t\t\tsizeof (pid_t), &pid,";
print "\t\t\t\tsizeof (glibtop_"feature"),";
print "\t\t\t\tbuf);";
print "\t} else {"; print "\t} else {";
print "\t\t"prefix"glibtop_get_"feature"_r (server, buf, pid);"; print "#if (!GLIBTOP_SUID_"toupper(feature)")";
print "\t\tglibtop_get_"feature"_r (server, buf, pid);";
} else { } else {
print "\t\t"prefix"glibtop_call_l (server, GLIBTOP_CMND_"toupper(feature)", 0, NULL,"; if (feature ~ /^proclist$/) {
print "\t\t\t sizeof (glibtop_"feature"), buf);"; print "\t\treturn glibtop_call_l (server, GLIBTOP_CMND_PROCLIST,";
print "\t\t\t\t 0, NULL, sizeof (glibtop_proclist),";
print "\t\t\t\t buf);";
} else {
print "\t\tglibtop_call_l (server, GLIBTOP_CMND_"toupper(feature)", 0, NULL,";
print "\t\t\t\tsizeof (glibtop_"feature"), buf);";
}
print "\t} else {"; print "\t} else {";
print "#if (!GLIBTOP_SUID_"toupper(feature)")";
print "\t\t"prefix"glibtop_get_"feature"_r (server, buf);"; print "\t\t"prefix"glibtop_get_"feature"_r (server, buf);";
} }
print "#else";
print "\t\terrno = ENOSYS;";
print "\t\tglibtop_error_io_r (server, \"glibtop_get_"feature"\");";
print "#endif";
print "\t}"; print "\t}";
print "}"; print "}";
print ""; print "";
} }
/^(\w+)/ { output($1) } /^(\w+)/ { output($1) }

View File

@@ -44,12 +44,23 @@ glibtop_open_l (glibtop *server, const char *program_name,
server->flags |= _GLIBTOP_INIT_STATE_OPEN; server->flags |= _GLIBTOP_INIT_STATE_OPEN;
server->features = features;
switch (server->method) {
case GLIBTOP_METHOD_PIPE:
case GLIBTOP_METHOD_UNIX:
if (glibtop_server_features & features)
break;
fprintf (stderr, "Using the server is not required.\n");
server->method = GLIBTOP_METHOD_DIRECT;
break;
}
switch (server->method) { switch (server->method) {
case GLIBTOP_METHOD_DIRECT: case GLIBTOP_METHOD_DIRECT:
fprintf (stderr, "Calling sysdeps open function.\n"); server->features = 0;
glibtop_open_r (server, program_name, features, flags);
break; break;
case GLIBTOP_METHOD_INET: case GLIBTOP_METHOD_INET:
fprintf (stderr, "Connecting to '%s' port %ld.\n", fprintf (stderr, "Connecting to '%s' port %ld.\n",
@@ -58,9 +69,9 @@ glibtop_open_l (glibtop *server, const char *program_name,
connect_type = glibtop_make_connection connect_type = glibtop_make_connection
(server->server_host, server->server_port, (server->server_host, server->server_port,
&server->socket); &server->socket);
fprintf (stderr, "Connect Type is %d.\n", connect_type); fprintf (stderr, "Connect Type is %d.\n", connect_type);
server->flags |= _GLIBTOP_INIT_STATE_SERVER; server->flags |= _GLIBTOP_INIT_STATE_SERVER;
server->features = -1; server->features = -1;
@@ -81,14 +92,6 @@ glibtop_open_l (glibtop *server, const char *program_name,
fprintf (stderr, "Opening pipe to server (%s).\n", fprintf (stderr, "Opening pipe to server (%s).\n",
GTOP_SERVER); GTOP_SERVER);
#if 0
if (socketpair (AF_UNIX, SOCK_STREAM, 0, server->input))
glibtop_error_io_r (server, "socketpair");
if (socketpair (AF_UNIX, SOCK_STREAM, 0, server->output))
glibtop_error_io_r (server, "socketpair");
#endif
if (pipe (server->input) || pipe (server->output)) if (pipe (server->input) || pipe (server->output))
glibtop_error_io_r (server, "cannot make a pipe"); glibtop_error_io_r (server, "cannot make a pipe");
@@ -102,7 +105,7 @@ glibtop_open_l (glibtop *server, const char *program_name,
dup2 (server->input [1], 1); dup2 (server->input [1], 1);
dup2 (server->output [0], 0); dup2 (server->output [0], 0);
execl (GTOP_SERVER, NULL); execl (GTOP_SERVER, NULL);
glibtop_error_io_r (server, "execl %s", GTOP_SERVER); glibtop_error_io_r (server, "execl (%s)", GTOP_SERVER);
_exit (2); _exit (2);
} }
@@ -138,4 +141,11 @@ glibtop_open_l (glibtop *server, const char *program_name,
fprintf (stderr, "Server features are %lu.\n", fprintf (stderr, "Server features are %lu.\n",
server->features); server->features);
} }
/* In any case, we call the open functions of our own sysdeps
* directory. */
fprintf (stderr, "Calling sysdeps open function.\n");
glibtop_open_s (server, program_name, features, flags);
} }

View File

@@ -1 +1,10 @@
SUBDIRS = server daemon if NEED_LIBGTOP
server_SUBDIRS = server
else
server_SUBDIRS =
endif
SUBDIRS = $(server_SUBDIRS) daemon
DIST_SUBDIRS = server daemon

View File

@@ -4,22 +4,23 @@ INCLUDES = -I$(top_builddir) -I$(top_srcdir) @machine_incs@ \
-I$(top_srcdir)/include -I$(top_srcdir)/intl @GUILE_INCS@ \ -I$(top_srcdir)/include -I$(top_srcdir)/intl @GUILE_INCS@ \
-DGTOPLOCALEDIR=\"$(datadir)/locale\" -D_GNU_SOURCE -DGTOPLOCALEDIR=\"$(datadir)/locale\" -D_GNU_SOURCE
CFLAGS = -Wall -W @CFLAGS@ -DGTOP_SERVER=\""@LIBGTOP_SERVER@"\" -DDEBUG -DREAL_DEBUG CFLAGS = -Wall -W @CFLAGS@ \
-DGTOP_SERVER=\""@LIBGTOP_SERVER@"\" \
-DDEBUG -DREAL_DEBUG -D_BSD \
-DLIBGTOP_DAEMON_SLAVE
bin_PROGRAMS = gnuserv bin_PROGRAMS = libgtop_daemon
EXTRA_PROGRAMS = gtop_daemon if NEED_LIBGTOP
suid_sysdeps = $(top_builddir)/sysdeps/@sysdeps_dir@/libgtop_sysdeps_suid.la
else
suid_sysdeps =
endif
gnuserv_SOURCES = gnuserv.c main.c slave.c libgtop_daemon_SOURCES = gnuserv.c main.c io.c
gnuserv_LDADD = $(top_builddir)/lib/libgtop.la \ libgtop_daemon_LDADD = $(top_builddir)/lib/libgtop.la \
$(top_builddir)/sysdeps/common/libgtop_common.la \ $(top_builddir)/sysdeps/common/libgtop_common.la \
$(top_builddir)/sysdeps/@sysdeps_dir@/libgtop_sysdeps.la \ $(top_builddir)/sysdeps/@sysdeps_dir@/libgtop_sysdeps.la \
@sysdeps_suid_lib@ \
@INTLLIBS@ @LIBSUPPORT@ @X_LIBS@ -lXau @INTLLIBS@ @LIBSUPPORT@ @X_LIBS@ -lXau
gnuserv_LDFLAGS = -static libgtop_daemon_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

View File

@@ -19,26 +19,43 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */ Boston, MA 02111-1307, USA. */
#ifndef __GLIBTOP_DAEMON_H__
#define __GLIBTOP_DAEMON_H__
#include <glibtop.h> #include <glibtop.h>
#include <glibtop/gnuserv.h>
#include <glibtop/open.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>
static glibtop _glibtop_global_server; #include <fcntl.h>
glibtop *glibtop_global_server = NULL;
glibtop * __BEGIN_DECLS
glibtop_init_r (glibtop **server, const unsigned long features,
const unsigned flags)
{
if (*server != NULL)
return *server;
fprintf (stderr, "DEBUG: %s (%d)\n", __FILE__, __LINE__); #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
if (glibtop_global_server == NULL) { #define _offset_union(p) ((char *) &resp->u.p - (char *) resp)
glibtop_global_server = &_glibtop_global_server; #define _offset_data(p) _offset_union (data.p)
glibtop_open_r (glibtop_global_server, "glibtop",
features, flags); #define MSG_BUFSZ sizeof (struct _glibtop_ipc_message)
} #define MSG_MSGSZ (MSG_BUFSZ - sizeof (long))
return *server = glibtop_global_server; extern void handle_slave_connection __P((int, int));
} extern void handle_slave_command __P((glibtop_command *, glibtop_response *, const void *));
extern void do_output __P((int, glibtop_response *, off_t, size_t, const void *));
extern int do_read __P((int, void *, size_t));
__END_DECLS
#endif

View File

@@ -49,7 +49,7 @@
#endif #endif
extern void handle_parent_connection __P ((int)); extern void handle_parent_connection __P ((int));
extern void handle_child_connection __P ((int)); extern void handle_slave_connection __P ((int, int));
extern void handle_ipc_connection __P ((int)); extern void handle_ipc_connection __P ((int));
#if !defined(UNIX_DOMAIN_SOCKETS) && !defined(INTERNET_DOMAIN_SOCKETS) #if !defined(UNIX_DOMAIN_SOCKETS) && !defined(INTERNET_DOMAIN_SOCKETS)
@@ -216,7 +216,7 @@ static int
setup_table (void) setup_table (void)
{ {
char hostname [HOSTNAMSZ]; char hostname [HOSTNAMSZ];
u_int host_addr; long host_addr;
int i, hosts = 0; int i, hosts = 0;
/* Make sure every entry is null */ /* Make sure every entry is null */
@@ -225,7 +225,7 @@ setup_table (void)
gethostname (hostname, HOSTNAMSZ); gethostname (hostname, HOSTNAMSZ);
if (((long) host_addr = glibtop_internet_addr (hostname)) == -1) if ((host_addr = glibtop_internet_addr (hostname)) == -1)
glibtop_error ("Can't resolve '%s'", hostname); glibtop_error ("Can't resolve '%s'", hostname);
#ifdef AUTH_MAGIC_COOKIE #ifdef AUTH_MAGIC_COOKIE
@@ -326,13 +326,15 @@ handle_internet_request (int ls)
glibtop_error_io ("accept"); glibtop_error_io ("accept");
#ifdef DEBUG #ifdef DEBUG
fprintf (stderr, "Connection was made from %s.\n", inet_ntoa (peer.sin_addr)); fprintf (stderr, "Connection was made from %s.\n",
inet_ntoa (peer.sin_addr));
#endif #endif
/* Check that access is allowed - if not return crud to the client */ /* 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)) {
close (s); close (s);
glibtop_warn ("Refused connection from %s.", inet_ntoa (peer.sin_addr)); glibtop_warn ("Refused connection from %s.",
inet_ntoa (peer.sin_addr));
return; return;
} /* if */ } /* if */
@@ -453,6 +455,7 @@ handle_unix_request (int ls)
fprintf (stderr, "Accepted connection on socket %d.\n", s); fprintf (stderr, "Accepted connection on socket %d.\n", s);
#endif #endif
#ifdef GLIBTOP_DAEMON_SLAVE
pid = fork (); pid = fork ();
if (pid == -1) if (pid == -1)
@@ -461,7 +464,8 @@ handle_unix_request (int ls)
if (pid) if (pid)
return; return;
handle_child_connection (s); handle_slave_connection (s, s);
#endif
close (s); close (s);
@@ -502,7 +506,11 @@ main (int argc, char *argv [])
signal (SIGCHLD, handle_signal); signal (SIGCHLD, handle_signal);
#ifdef GLIBTOP_DAEMON_SLAVE
pid = fork (); pid = fork ();
#else
pid = getpid ();
#endif
if (pid == -1) if (pid == -1)
glibtop_error_io ("fork failed"); glibtop_error_io ("fork failed");
@@ -542,7 +550,11 @@ main (int argc, char *argv [])
} else { } else {
/* We are the parent. */ /* We are the parent. */
#ifdef GLIBTOP_DAEMON_SLAVE
const unsigned method = GLIBTOP_METHOD_UNIX; const unsigned method = GLIBTOP_METHOD_UNIX;
#else
const unsigned method = GLIBTOP_METHOD_PIPE;
#endif
const unsigned long features = GLIBTOP_SYSDEPS_ALL; const unsigned long features = GLIBTOP_SYSDEPS_ALL;
@@ -657,8 +669,11 @@ main (int argc, char *argv [])
handle_internet_request (ils); handle_internet_request (ils);
#endif #endif
if (FD_ISSET (fileno (stdin), &rmask)) #ifdef GLIBTOP_DAEMON_SLAVE
handle_child_connection (fileno (stdin)); if ((pid == 0) && FD_ISSET (fileno (stdin), &rmask))
handle_slave_connection (fileno (stdin),
fileno (stdout));
#endif
} }
return 0; return 0;

82
src/daemon/io.c Normal file
View File

@@ -0,0 +1,82 @@
/* $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 "daemon.h"
void
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 %lu.\n",
sizeof (glibtop_response), offset);
#endif
resp->offset = offset;
resp->data_size = data_size;
if (send (s, resp, sizeof (glibtop_response), 0) < 0)
glibtop_warn_io ("send");
if (resp->data_size) {
#ifdef REAL_DEBUG
fprintf (stderr, "Writing %d bytes of data.\n", resp->data_size);
#endif
if (send (s, data, resp->data_size, 0) , 0)
glibtop_warn_io ("send");
}
}
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) {
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_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;
}

View File

@@ -19,99 +19,7 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */ Boston, MA 02111-1307, USA. */
#include <glibtop/gnuserv.h> #include "daemon.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
/* Fallthrough case - please add other #elif cases above
for different OS's as necessary */
#define GET_MAX_FDS() 256
#endif
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 *resp, off_t offset,
size_t data_size, const void *data)
{
#ifdef REAL_DEBUG
fprintf (stderr, "Really writing %d bytes at offset %lu.\n",
sizeof (glibtop_response), offset);
#endif
resp->offset = offset;
resp->data_size = data_size;
if (send (s, resp, sizeof (glibtop_response), 0) < 0)
glibtop_warn_io ("send");
if (resp->data_size) {
#ifdef REAL_DEBUG
fprintf (stderr, "Writing %d bytes of data.\n", resp->data_size);
#endif
if (send (s, data, resp->data_size, 0) , 0)
glibtop_warn_io ("send");
}
}
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) {
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_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 void
handle_parent_connection (int s) handle_parent_connection (int s)
@@ -125,7 +33,7 @@ handle_parent_connection (int s)
fprintf (stderr, "Parent features = %lu\n", glibtop_server_features); fprintf (stderr, "Parent features = %lu\n", glibtop_server_features);
while (do_read (s, &cmnd, sizeof (glibtop_command))) { while (do_read (s, cmnd, sizeof (glibtop_command))) {
#ifdef PARENT_DEBUG #ifdef PARENT_DEBUG
fprintf (stderr, "Parent (%d) received command %d from client.\n", fprintf (stderr, "Parent (%d) received command %d from client.\n",
getpid (), cmnd->command); getpid (), cmnd->command);
@@ -153,6 +61,7 @@ handle_parent_connection (int s)
case GLIBTOP_CMND_QUIT: case GLIBTOP_CMND_QUIT:
do_output (s, resp, 0, 0, NULL); do_output (s, resp, 0, 0, NULL);
#ifdef GLIBTOP_DAEMON_SLAVE
fprintf (stderr, "Sending QUIT command (%d).\n", fprintf (stderr, "Sending QUIT command (%d).\n",
server->socket); server->socket);
@@ -163,6 +72,7 @@ handle_parent_connection (int s)
server->socket); server->socket);
close (server->socket); close (server->socket);
#endif
return; return;
case GLIBTOP_CMND_SYSDEPS: case GLIBTOP_CMND_SYSDEPS:
resp->u.sysdeps.features = GLIBTOP_SYSDEPS_ALL; resp->u.sysdeps.features = GLIBTOP_SYSDEPS_ALL;
@@ -255,57 +165,3 @@ handle_parent_connection (int s)
} }
} }
} }
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

@@ -19,17 +19,62 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */ Boston, MA 02111-1307, USA. */
#include <glibtop.h> #include "daemon.h"
#include <glibtop/gnuserv.h>
#include <glibtop/open.h> void
#include <glibtop/union.h> handle_slave_connection (int input, int output)
{
glibtop *server = glibtop_global_server;
glibtop_response _resp, *resp = &_resp;
glibtop_command _cmnd, *cmnd = &_cmnd;
char parameter [BUFSIZ];
void *ptr;
#include <glibtop/command.h> while (do_read (input, cmnd, sizeof (glibtop_command))) {
#include <glibtop/parameter.h> #ifdef SLAVE_DEBUG
fprintf (stderr, "Slave %d received command "
"%d from client.\n", getpid (), cmnd->command);
#endif
if (cmnd->data_size >= BUFSIZ)
glibtop_error ("Client sent %d bytes, "
"but buffer is %d",
cmnd->size, BUFSIZ);
#define _offset_union(p) ((char *) &resp->u.p - (char *) resp) memset (parameter, 0, sizeof (parameter));
#define _offset_data(p) _offset_union (data.p)
if (cmnd->data_size) {
#ifdef SLAVE_DEBUG
fprintf (stderr, "Client has %d bytes of data.\n",
cmnd->data_size);
#endif
do_read (input, parameter, cmnd->data_size);
} else if (cmnd->size) {
memcpy (parameter, cmnd->parameter, cmnd->size);
}
switch (cmnd->command) {
case GLIBTOP_CMND_QUIT:
do_output (output, 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 (output, 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 (output, resp, resp->offset, 0, NULL);
break;
}
}
}
void void
handle_slave_command (glibtop_command *cmnd, glibtop_response *resp, handle_slave_command (glibtop_command *cmnd, glibtop_response *resp,

View File

@@ -9,8 +9,8 @@ CFLAGS = -Wall -W @CFLAGS@
bin_PROGRAMS = gtop_server bin_PROGRAMS = gtop_server
gtop_server_SOURCES = main.c output.c version.c gtop_server_SOURCES = main.c output.c version.c
gtop_server_LDADD = $(top_builddir)/sysdeps/common/libgtop_common.la \ gtop_server_LDADD = $(top_builddir)/sysdeps/@sysdeps_dir@/libgtop_sysdeps_suid.la \
$(top_builddir)/sysdeps/@sysdeps_dir@/libgtop_sysdeps.la \ $(top_builddir)/sysdeps/common/libgtop_suid_common.la \
@INTLLIBS@ @LIBSUPPORT@ @LIBSUPPORT@
gtop_server_LDFLAGS = -static gtop_server_LDFLAGS = -static

View File

@@ -57,7 +57,7 @@ int main(int argc, char *argv[])
glibtop_version (); glibtop_version ();
glibtop_open_r (&server, argv [0], 0, 0); glibtop_open_p (&server, argv [0], 0, 0);
if (setreuid (euid, uid)) _exit (1); if (setreuid (euid, uid)) _exit (1);
@@ -128,147 +128,146 @@ int main(int argc, char *argv[])
glibtop_output (sizeof (glibtop_sysdeps), &sysdeps); glibtop_output (sizeof (glibtop_sysdeps), &sysdeps);
glibtop_output (0, NULL); glibtop_output (0, NULL);
break; break;
case GLIBTOP_CMND_CPU:
#if GLIBTOP_SUID_CPU #if GLIBTOP_SUID_CPU
case GLIBTOP_CMND_CPU:
glibtop_get_cpu_p (&server, &data.cpu); glibtop_get_cpu_p (&server, &data.cpu);
#endif
glibtop_output (sizeof (glibtop_cpu), &data.cpu); glibtop_output (sizeof (glibtop_cpu), &data.cpu);
glibtop_output (0, NULL); glibtop_output (0, NULL);
break; break;
case GLIBTOP_CMND_MEM:
#if GLIBTOP_SUID_MEM
glibtop_get_mem_p (&server, &data.mem);
#endif #endif
#if GLIBTOP_SUID_MEM
case GLIBTOP_CMND_MEM:
glibtop_get_mem_p (&server, &data.mem);
glibtop_output (sizeof (glibtop_mem), &data.mem); glibtop_output (sizeof (glibtop_mem), &data.mem);
glibtop_output (0, NULL); glibtop_output (0, NULL);
break; break;
case GLIBTOP_CMND_SWAP:
#if GLIBTOP_SUID_SWAP
glibtop_get_swap_p (&server, &data.swap);
#endif #endif
#if GLIBTOP_SUID_SWAP
case GLIBTOP_CMND_SWAP:
glibtop_get_swap_p (&server, &data.swap);
glibtop_output (sizeof (glibtop_swap), &data.swap); glibtop_output (sizeof (glibtop_swap), &data.swap);
glibtop_output (0, NULL); glibtop_output (0, NULL);
break; break;
case GLIBTOP_CMND_UPTIME:
#if GLIBTOP_SUID_UPTIME
glibtop_get_uptime_p (&server, &data.uptime);
#endif #endif
#if GLIBTOP_SUID_UPTIME
case GLIBTOP_CMND_UPTIME:
glibtop_get_uptime_p (&server, &data.uptime);
glibtop_output (sizeof (glibtop_uptime), &data.uptime); glibtop_output (sizeof (glibtop_uptime), &data.uptime);
glibtop_output (0, NULL); glibtop_output (0, NULL);
break; break;
case GLIBTOP_CMND_LOADAVG:
#if GLIBTOP_SUID_LOADAVG
glibtop_get_loadavg_p (&server, &data.loadavg);
#endif #endif
#if GLIBTOP_SUID_LOADAVG
case GLIBTOP_CMND_LOADAVG:
glibtop_get_loadavg_p (&server, &data.loadavg);
glibtop_output (sizeof (glibtop_loadavg), &data.loadavg); glibtop_output (sizeof (glibtop_loadavg), &data.loadavg);
glibtop_output (0, NULL); glibtop_output (0, NULL);
break; break;
case GLIBTOP_CMND_SHM_LIMITS:
#if GLIBTOP_SUID_SHM_LIMITS
glibtop_get_shm_limits_p (&server, &data.shm_limits);
#endif #endif
#if GLIBTOP_SUID_SHM_LIMITS
case GLIBTOP_CMND_SHM_LIMITS:
glibtop_get_shm_limits_p (&server, &data.shm_limits);
glibtop_output (sizeof (glibtop_shm_limits), glibtop_output (sizeof (glibtop_shm_limits),
&data.shm_limits); &data.shm_limits);
glibtop_output (0, NULL); glibtop_output (0, NULL);
break; break;
case GLIBTOP_CMND_MSG_LIMITS:
#if GLIBTOP_SUID_MSG_LIMITS
glibtop_get_msg_limits_p (&server, &data.msg_limits);
#endif #endif
#if GLIBTOP_SUID_MSG_LIMITS
case GLIBTOP_CMND_MSG_LIMITS:
glibtop_get_msg_limits_p (&server, &data.msg_limits);
glibtop_output (sizeof (glibtop_msg_limits), glibtop_output (sizeof (glibtop_msg_limits),
&data.msg_limits); &data.msg_limits);
glibtop_output (0, NULL); glibtop_output (0, NULL);
break; break;
case GLIBTOP_CMND_SEM_LIMITS:
#if GLIBTOP_SUID_SEM_LIMITS
glibtop_get_sem_limits_p (&server, &data.sem_limits);
#endif #endif
#if GLIBTOP_SUID_SEM_LIMITS
case GLIBTOP_CMND_SEM_LIMITS:
glibtop_get_sem_limits_p (&server, &data.sem_limits);
glibtop_output (sizeof (glibtop_sem_limits), glibtop_output (sizeof (glibtop_sem_limits),
&data.sem_limits); &data.sem_limits);
glibtop_output (0, NULL); glibtop_output (0, NULL);
break; break;
case GLIBTOP_CMND_PROCLIST:
#if GLIBTOP_SUID_PROCLIST
ptr = glibtop_get_proclist_p (&server, &data.proclist);
#else
ptr = NULL;
#endif #endif
#if GLIBTOP_SUID_PROCLIST
case GLIBTOP_CMND_PROCLIST:
ptr = glibtop_get_proclist_p (&server, &data.proclist);
glibtop_output (sizeof (glibtop_proclist), glibtop_output (sizeof (glibtop_proclist),
&data.proclist); &data.proclist);
glibtop_output (data.proclist.total, ptr); glibtop_output (data.proclist.total, ptr);
glibtop_free_r (&server, ptr); if (ptr) free (ptr);
break; break;
#endif
#if GLIBTOP_SUID_PROC_STATE
case GLIBTOP_CMND_PROC_STATE: case GLIBTOP_CMND_PROC_STATE:
memcpy (&pid, parameter, sizeof (pid_t)); memcpy (&pid, parameter, sizeof (pid_t));
#if GLIBTOP_SUID_PROC_STATE
glibtop_get_proc_state_p glibtop_get_proc_state_p
(&server, &data.proc_state, pid); (&server, &data.proc_state, pid);
#endif
glibtop_output (sizeof (glibtop_proc_state), glibtop_output (sizeof (glibtop_proc_state),
&data.proc_state); &data.proc_state);
glibtop_output (0, NULL); glibtop_output (0, NULL);
break; break;
#endif
#if GLIBTOP_SUID_PROC_UID
case GLIBTOP_CMND_PROC_UID: case GLIBTOP_CMND_PROC_UID:
memcpy (&pid, parameter, sizeof (pid_t)); memcpy (&pid, parameter, sizeof (pid_t));
#if GLIBTOP_SUID_PROC_UID
glibtop_get_proc_uid_p glibtop_get_proc_uid_p
(&server, &data.proc_uid, pid); (&server, &data.proc_uid, pid);
#endif
glibtop_output (sizeof (glibtop_proc_uid), glibtop_output (sizeof (glibtop_proc_uid),
&data.proc_uid); &data.proc_uid);
glibtop_output (0, NULL); glibtop_output (0, NULL);
break; break;
#endif
#if GLIBTOP_SUID_PROC_MEM
case GLIBTOP_CMND_PROC_MEM: case GLIBTOP_CMND_PROC_MEM:
memcpy (&pid, parameter, sizeof (pid_t)); memcpy (&pid, parameter, sizeof (pid_t));
#if GLIBTOP_SUID_PROC_MEM
glibtop_get_proc_mem_p glibtop_get_proc_mem_p
(&server, &data.proc_mem, pid); (&server, &data.proc_mem, pid);
#endif
glibtop_output (sizeof (glibtop_proc_mem), glibtop_output (sizeof (glibtop_proc_mem),
&data.proc_mem); &data.proc_mem);
glibtop_output (0, NULL); glibtop_output (0, NULL);
break; break;
#endif
#if GLIBTOP_SUID_PROC_TIME
case GLIBTOP_CMND_PROC_TIME: case GLIBTOP_CMND_PROC_TIME:
memcpy (&pid, parameter, sizeof (pid_t)); memcpy (&pid, parameter, sizeof (pid_t));
#if GLIBTOP_SUID_PROC_TIME
glibtop_get_proc_time_p glibtop_get_proc_time_p
(&server, &data.proc_time, pid); (&server, &data.proc_time, pid);
#endif
glibtop_output (sizeof (glibtop_proc_time), glibtop_output (sizeof (glibtop_proc_time),
&data.proc_time); &data.proc_time);
glibtop_output (0, NULL); glibtop_output (0, NULL);
break; break;
#endif
#if GLIBTOP_SUID_PROC_SIGNAL
case GLIBTOP_CMND_PROC_SIGNAL: case GLIBTOP_CMND_PROC_SIGNAL:
memcpy (&pid, parameter, sizeof (pid_t)); memcpy (&pid, parameter, sizeof (pid_t));
#if GLIBTOP_SUID_PROC_SIGNAL
glibtop_get_proc_signal_p glibtop_get_proc_signal_p
(&server, &data.proc_signal, pid); (&server, &data.proc_signal, pid);
#endif
glibtop_output (sizeof (glibtop_proc_signal), glibtop_output (sizeof (glibtop_proc_signal),
&data.proc_signal); &data.proc_signal);
glibtop_output (0, NULL); glibtop_output (0, NULL);
break; break;
#endif
#if GLIBTOP_SUID_PROC_KERNEL
case GLIBTOP_CMND_PROC_KERNEL: case GLIBTOP_CMND_PROC_KERNEL:
memcpy (&pid, parameter, sizeof (pid_t)); memcpy (&pid, parameter, sizeof (pid_t));
#if GLIBTOP_SUID_PROC_KERNEL
glibtop_get_proc_kernel_p glibtop_get_proc_kernel_p
(&server, &data.proc_kernel, pid); (&server, &data.proc_kernel, pid);
#endif
glibtop_output (sizeof (glibtop_proc_kernel), glibtop_output (sizeof (glibtop_proc_kernel),
&data.proc_kernel); &data.proc_kernel);
glibtop_output (0, NULL); glibtop_output (0, NULL);
break; break;
#endif
#if GLIBTOP_SUID_PROC_SEGMENT
case GLIBTOP_CMND_PROC_SEGMENT: case GLIBTOP_CMND_PROC_SEGMENT:
memcpy (&pid, parameter, sizeof (pid_t)); memcpy (&pid, parameter, sizeof (pid_t));
#if GLIBTOP_SUID_PROC_SEGMENT
glibtop_get_proc_segment_p glibtop_get_proc_segment_p
(&server, &data.proc_segment, pid); (&server, &data.proc_segment, pid);
#endif
glibtop_output (sizeof (glibtop_proc_segment), glibtop_output (sizeof (glibtop_proc_segment),
&data.proc_segment); &data.proc_segment);
glibtop_output (0, NULL); glibtop_output (0, NULL);
break; break;
#endif
default:
_exit(1);
} }
} }
_exit(0); _exit(0);

View File

@@ -6,6 +6,8 @@ INCLUDES = -I$(top_builddir) -I$(top_srcdir) @machine_incs@ \
CFLAGS = -Wall -W @CFLAGS@ CFLAGS = -Wall -W @CFLAGS@
lib_LTLIBRARIES = libgtop_common.la lib_LTLIBRARIES = libgtop_common.la libgtop_suid_common.la
libgtop_common_la_SOURCES = sysdeps.c xmalloc.c error.c gnuslib.c libgtop_common_la_SOURCES = sysdeps.c xmalloc.c error.c gnuslib.c
libgtop_suid_common_la_SOURCES = xmalloc.c error.c

View File

@@ -29,8 +29,7 @@ glibtop_malloc_r (glibtop *server, size_t size)
void *buf = malloc (size); void *buf = malloc (size);
if (!buf) if (!buf)
glibtop_error_r (server, _("malloc %d bytes: %s"), glibtop_error_io_r (server, "malloc %d bytes", size);
size, strerror (errno));
return buf; return buf;
} }
@@ -41,8 +40,8 @@ glibtop_calloc_r (glibtop *server, size_t nmemb, size_t size)
void *buf = calloc (nmemb, size); void *buf = calloc (nmemb, size);
if (!buf) if (!buf)
glibtop_error_r (server, _("calloc %d block (%d bytes each): %s"), glibtop_error_io_r (server, "calloc %d blocks (%d bytes each)",
nmemb, size, strerror (errno)); nmemb, size);
return buf; return buf;
} }
@@ -53,8 +52,7 @@ glibtop_realloc_r (glibtop *server, void *ptr, size_t size)
void *buf = realloc (ptr, size); void *buf = realloc (ptr, size);
if (!buf) if (!buf)
glibtop_error_r (server, _("realloc %d bytes: %s"), glibtop_error_io_r (server, "realloc %d bytes", size);
size, strerror (errno));
return buf; return buf;
} }

View File

@@ -8,7 +8,7 @@ CFLAGS = -Wall -W @CFLAGS@
lib_LTLIBRARIES = libgtop_sysdeps.la lib_LTLIBRARIES = libgtop_sysdeps.la
libgtop_sysdeps_la_SOURCES = init.c open.c close.c kernel.s cpu.c mem.c swap.c \ libgtop_sysdeps_la_SOURCES = open.c close.c kernel.s cpu.c mem.c swap.c \
uptime.c loadavg.c shm_limits.c msg_limits.c \ uptime.c loadavg.c shm_limits.c msg_limits.c \
sem_limits.c proclist.c procstate.c procuid.c \ sem_limits.c proclist.c procstate.c procuid.c \
proctime.c procmem.c procsignal.c prockernel.c \ proctime.c procmem.c procsignal.c prockernel.c \

View File

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

View File

@@ -51,11 +51,11 @@ static void set_linux_version(void) {
/* Opens pipe to gtop server. Returns 0 on success and -1 on error. */ /* Opens pipe to gtop server. Returns 0 on success and -1 on error. */
void void
glibtop_open_r (glibtop *server, const char *program_name, glibtop_open_s (glibtop *server, const char *program_name,
const unsigned long features, const unsigned flags) const unsigned long features, const unsigned flags)
{ {
server->name = program_name; server->name = program_name;
set_linux_version (); set_linux_version ();
server->os_version_code = (unsigned long) linux_version_code; server->os_version_code = (unsigned long) linux_version_code;
} }

View File

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

View File

@@ -1,44 +0,0 @@
/* $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/open.h>
static glibtop _glibtop_global_server;
glibtop *glibtop_global_server = NULL;
glibtop *
glibtop_init_r (glibtop **server, const unsigned long features,
const unsigned flags)
{
if (*server != NULL)
return *server;
fprintf (stderr, "DEBUG: %s (%d)\n", __FILE__, __LINE__);
if (glibtop_global_server == NULL) {
glibtop_global_server = &_glibtop_global_server;
glibtop_open_r (glibtop_global_server, "glibtop",
features, flags);
}
return *server = glibtop_global_server;
}

View File

@@ -51,7 +51,7 @@ static void set_linux_version(void) {
/* Opens pipe to gtop server. Returns 0 on success and -1 on error. */ /* Opens pipe to gtop server. Returns 0 on success and -1 on error. */
void void
glibtop_open_r (glibtop *server, const char *program_name, glibtop_open_s (glibtop *server, const char *program_name,
const unsigned long features, const unsigned flags) const unsigned long features, const unsigned flags)
{ {
server->name = program_name; server->name = program_name;

View File

@@ -6,11 +6,14 @@ INCLUDES = -I$(top_builddir) -I$(top_srcdir) @machine_incs@ \
CFLAGS = -Wall -W @CFLAGS@ CFLAGS = -Wall -W @CFLAGS@
lib_LTLIBRARIES = libgtop_sysdeps.la lib_LTLIBRARIES = libgtop_sysdeps.la libgtop_sysdeps_suid.la
libgtop_sysdeps_la_SOURCES = init.c open.c close.c cpu.c mem.c swap.c \ libgtop_sysdeps_la_SOURCES = open.c close.c cpu.c mem.c swap.c \
uptime.c loadavg.c shm_limits.c msg_limits.c \ uptime.c loadavg.c shm_limits.c msg_limits.c \
sem_limits.c proclist.c procstate.c procuid.c \ sem_limits.c
proctime.c procmem.c procsignal.c prockernel.c \
procsegment.c
libgtop_sysdeps_la_LIBADD = -lmach libgtop_sysdeps_la_LIBADD = -lmach
libgtop_sysdeps_suid_la_SOURCES = open_suid.c close_suid.c proclist.c \
procstate.c procuid.c proctime.c procmem.c \
procsignal.c prockernel.c procsegment.c
libgtop_sysdeps_suid_la_LIBADD = -lmach

View File

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

View File

@@ -19,24 +19,10 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */ Boston, MA 02111-1307, USA. */
#include <glibtop.h> #include <glibtop/close.h>
#include <glibtop/open.h>
static glibtop _glibtop_global_server; /* Closes pipe to gtop server. */
glibtop *glibtop_global_server = NULL;
glibtop * void
glibtop_init_r (glibtop **server, const unsigned long features, glibtop_close_p (glibtop *server)
const unsigned flags) { }
{
if (*server != NULL)
return *server;
if (glibtop_global_server == NULL) {
glibtop_global_server = &_glibtop_global_server;
glibtop_open_r (glibtop_global_server, "glibtop",
features, flags);
}
return *server = glibtop_global_server;
}

View File

@@ -36,7 +36,7 @@ glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
struct tbl_sysinfo sysinfo; struct tbl_sysinfo sysinfo;
int ret; int ret;
glibtop_init (); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_cpu)); memset (buf, 0, sizeof (glibtop_cpu));

View File

@@ -34,7 +34,7 @@ glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
struct tbl_loadavg loadavg; struct tbl_loadavg loadavg;
int ret; int ret;
glibtop_init (); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_loadavg)); memset (buf, 0, sizeof (glibtop_loadavg));

View File

@@ -40,8 +40,8 @@ glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
{ {
vm_statistics_data_t vmstats; vm_statistics_data_t vmstats;
glibtop_init (); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_mem)); memset (buf, 0, sizeof (glibtop_mem));
buf->flags = _glibtop_sysdeps_mem; buf->flags = _glibtop_sysdeps_mem;

View File

@@ -35,7 +35,7 @@ glibtop_get_msg_limits_s (glibtop *server, glibtop_msg_limits *buf)
{ {
int ret, value; int ret, value;
glibtop_init (); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_msg_limits)); memset (buf, 0, sizeof (glibtop_msg_limits));

View File

@@ -19,6 +19,7 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */ Boston, MA 02111-1307, USA. */
#include <glibtop.h>
#include <glibtop/open.h> #include <glibtop/open.h>
#include <unistd.h> #include <unistd.h>
@@ -26,39 +27,7 @@
/* Opens pipe to gtop server. Returns 0 on success and -1 on error. */ /* Opens pipe to gtop server. Returns 0 on success and -1 on error. */
/* !!! THIS FUNCTION RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
void void
glibtop_open (glibtop *server, const char *program_name) glibtop_open_s (glibtop *server, const char *program_name,
{ const unsigned long features, const unsigned flags)
/* !!! WE ARE ROOT HERE - CHANGE WITH CAUTION !!! */ { }
memset (server, 0, sizeof (glibtop));
server->name = program_name;
server->machine.uid = getuid ();
server->machine.euid = geteuid ();
server->machine.gid = getgid ();
server->machine.egid = getegid ();
server->machine.proctable_entries = table (TBL_PROCINFO, 0, NULL, INT_MAX, 0);
/* Drop priviledges; we only become root when necessary.
setreuid (ruid, euid) - set real and effective user id;
setregid (rgid, egid) - set real and effective group id;
*/
if (setreuid (server->machine.euid, server->machine.uid))
_exit (1);
if (setregid (server->machine.egid, server->machine.gid))
_exit (1);
/* !!! END OF SUID ROOT PART !!! */
/* Our effective uid is now those of the user invoking the server,
so we do no longer have any priviledges.
*/
}

66
sysdeps/osf1/open_suid.c Normal file
View File

@@ -0,0 +1,66 @@
/* $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/open.h>
#include <unistd.h>
#include <sys/types.h>
/* Opens pipe to gtop server. Returns 0 on success and -1 on error. */
/* !!! THIS FUNCTION RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
void
glibtop_open_p (glibtop *server, const char *program_name,
const unsigned long features, const unsigned flags)
{
/* !!! WE ARE ROOT HERE - CHANGE WITH CAUTION !!! */
server->name = program_name;
server->machine.uid = getuid ();
server->machine.euid = geteuid ();
server->machine.gid = getgid ();
server->machine.egid = getegid ();
server->machine.proctable_entries = table
(TBL_PROCINFO, 0, NULL, INT_MAX, 0);
/* Drop priviledges; we only become root when necessary.
setreuid (ruid, euid) - set real and effective user id;
setregid (rgid, egid) - set real and effective group id;
*/
if (setreuid (server->machine.euid, server->machine.uid))
_exit (1);
if (setregid (server->machine.egid, server->machine.gid))
_exit (1);
/* !!! END OF SUID ROOT PART !!! */
/* Our effective uid is now those of the user invoking the server,
so we do no longer have any priviledges.
*/
}

View File

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

View File

@@ -54,7 +54,7 @@ static const unsigned long _glibtop_sysdeps_proclist =
/* !!! THIS FUNCTION RUNS SUID ROOT - CHANGE WITH CAUTION !!! */ /* !!! THIS FUNCTION RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
unsigned * unsigned *
glibtop_get_proclist_r (glibtop *server, glibtop_proclist *buf) glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf)
{ {
unsigned count = 0, total = 0; unsigned count = 0, total = 0;
unsigned pids [BLOCK_COUNT], *pids_chain = NULL; unsigned pids [BLOCK_COUNT], *pids_chain = NULL;
@@ -62,7 +62,7 @@ glibtop_get_proclist_r (glibtop *server, glibtop_proclist *buf)
struct tbl_procinfo procinfo [8]; struct tbl_procinfo procinfo [8];
int entry, max_elements, k; int entry, max_elements, k;
glibtop_init (); glibtop_open_p (server, 0, 0);
memset (buf, 0, sizeof (glibtop_proclist)); memset (buf, 0, sizeof (glibtop_proclist));

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -39,15 +39,15 @@ static const unsigned long _glibtop_sysdeps_proc_uid =
(1 << GLIBTOP_PROC_UID_TTY) + (1 << GLIBTOP_PROC_UID_TPGID); (1 << GLIBTOP_PROC_UID_TTY) + (1 << GLIBTOP_PROC_UID_TPGID);
void void
glibtop_get_proc_uid_r (glibtop *server, glibtop_proc_uid *buf, glibtop_get_proc_uid_p (glibtop *server, glibtop_proc_uid *buf,
pid_t pid) pid_t pid)
{ {
struct tbl_procinfo procinfo; struct tbl_procinfo procinfo;
task_basic_info_data_t taskinfo; task_basic_info_data_t taskinfo;
int ret, info_count; int ret, info_count;
task_t thistask; task_t thistask;
glibtop_init (); glibtop_open_p (server, 0, 0);
memset (buf, 0, sizeof (glibtop_proc_uid)); memset (buf, 0, sizeof (glibtop_proc_uid));

View File

@@ -35,7 +35,7 @@ glibtop_get_sem_limits_s (glibtop *server, glibtop_sem_limits *buf)
{ {
int ret, value; int ret, value;
glibtop_init (); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_sem_limits)); memset (buf, 0, sizeof (glibtop_sem_limits));

View File

@@ -34,7 +34,7 @@ glibtop_get_shm_limits_s (glibtop *server, glibtop_shm_limits *buf)
{ {
int ret, value; int ret, value;
glibtop_init (); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_shm_limits)); memset (buf, 0, sizeof (glibtop_shm_limits));

View File

@@ -35,7 +35,7 @@ glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
struct tbl_swapinfo swapinfo; struct tbl_swapinfo swapinfo;
int i; int i;
glibtop_init (); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_swap)); memset (buf, 0, sizeof (glibtop_swap));

View File

@@ -36,7 +36,7 @@ glibtop_get_uptime_s (glibtop *server, glibtop_uptime *buf)
struct tbl_sysinfo sysinfo; struct tbl_sysinfo sysinfo;
int ret; int ret;
glibtop_init (); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_uptime)); memset (buf, 0, sizeof (glibtop_uptime));

View File

@@ -8,7 +8,7 @@ CFLAGS = -Wall -W @CFLAGS@
lib_LTLIBRARIES = libgtop_sysdeps.la lib_LTLIBRARIES = libgtop_sysdeps.la
libgtop_sysdeps_la_SOURCES = init.c open.c close.c cpu.c mem.c swap.c \ libgtop_sysdeps_la_SOURCES = open.c close.c cpu.c mem.c swap.c \
uptime.c loadavg.c shm_limits.c msg_limits.c \ uptime.c loadavg.c shm_limits.c msg_limits.c \
sem_limits.c proclist.c procstate.c procuid.c \ sem_limits.c proclist.c procstate.c procuid.c \
proctime.c procmem.c procsignal.c prockernel.c \ proctime.c procmem.c procsignal.c prockernel.c \

View File

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

View File

@@ -1,42 +0,0 @@
/* $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/open.h>
static glibtop _glibtop_global_server;
glibtop *glibtop_global_server = NULL;
glibtop *
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_r (glibtop_global_server, "glibtop",
features, flags);
}
return *server = glibtop_global_server;
}

View File

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

View File

@@ -6,11 +6,14 @@ INCLUDES = -I$(top_builddir) -I$(top_srcdir) @machine_incs@ \
CFLAGS = -Wall -W @CFLAGS@ CFLAGS = -Wall -W @CFLAGS@
lib_LTLIBRARIES = libgtop_sysdeps.la lib_LTLIBRARIES = libgtop_sysdeps.la libgtop_sysdeps_suid.la
libgtop_sysdeps_la_SOURCES = init.c open.c close.c cpu.c mem.c swap.c \ libgtop_sysdeps_la_SOURCES = nosuid.c
libgtop_sysdeps_la_LIBADD = -lkvm
libgtop_sysdeps_suid_la_SOURCES = open.c close.c cpu.c mem.c swap.c \
uptime.c loadavg.c shm_limits.c msg_limits.c \ uptime.c loadavg.c shm_limits.c msg_limits.c \
sem_limits.c proclist.c procstate.c procuid.c \ sem_limits.c proclist.c procstate.c procuid.c \
proctime.c procmem.c procsignal.c prockernel.c \ proctime.c procmem.c procsignal.c prockernel.c \
procsegment.c procsegment.c
libgtop_sysdeps_la_LIBADD = -lkvm libgtop_sysdeps_suid_la_LIBADD = -lkvm

View File

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

View File

@@ -35,7 +35,7 @@ glibtop_get_cpu_p (glibtop *server, glibtop_cpu *buf)
long cp_time [CPUSTATES], mp_time [NCPU][CPUSTATES]; long cp_time [CPUSTATES], mp_time [NCPU][CPUSTATES];
int i; int i;
glibtop_init_r (&server, 0, 0); glibtop_init_p (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_cpu)); memset (buf, 0, sizeof (glibtop_cpu));

View File

@@ -33,7 +33,7 @@ glibtop_get_loadavg_p (glibtop *server, glibtop_loadavg *buf)
load_avg avenrun [3]; load_avg avenrun [3];
int i; int i;
glibtop_init_r (&server, 0, 0); glibtop_init_p (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_loadavg)); memset (buf, 0, sizeof (glibtop_loadavg));

View File

@@ -35,7 +35,7 @@ static const unsigned long _glibtop_sysdeps_mem =
void void
glibtop_get_mem_p (glibtop *server, glibtop_mem *buf) glibtop_get_mem_p (glibtop *server, glibtop_mem *buf)
{ {
glibtop_init_r (&server, 0, 0); glibtop_init_p (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_mem)); memset (buf, 0, sizeof (glibtop_mem));

View File

@@ -41,7 +41,7 @@ glibtop_get_msg_limits_p (glibtop *server, glibtop_msg_limits *buf)
{ {
struct msginfo msginfo; struct msginfo msginfo;
glibtop_init_r (&server, 0, 0); glibtop_init_p (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_msg_limits)); memset (buf, 0, sizeof (glibtop_msg_limits));

View File

@@ -22,19 +22,11 @@
#include <glibtop.h> #include <glibtop.h>
#include <glibtop/open.h> #include <glibtop/open.h>
static glibtop _glibtop_global_server; void
glibtop *glibtop_global_server = NULL; glibtop_open_s (glibtop *server, const char *program_name,
const unsigned long features, const unsigned flags)
{ }
glibtop * void
glibtop_init_r (glibtop **server) glibtop_close_s (glibtop *server)
{ { }
if (*server != NULL)
return *server;
if (glibtop_global_server == NULL) {
glibtop_global_server = &_glibtop_global_server;
glibtop_open (glibtop_global_server, "glibtop");
}
return *server = glibtop_global_server;
}

View File

@@ -63,8 +63,18 @@ struct nlist _glibtop_nlist[] = {
/* !!! THIS FUNCTION RUNS SUID ROOT - CHANGE WITH CAUTION !!! */ /* !!! THIS FUNCTION RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
void void
glibtop_open_r (glibtop *server, const char *program_name, glibtop_init_p (glibtop *server, const char *program_name,
const unsigned long features, const unsigned flags) const unsigned long features, const unsigned flags)
{
if (server == NULL)
glibtop_error_r (NULL, "glibtop_init_p (server == NULL)");
glibtop_open_p (server, program_name, features, flags);
}
void
glibtop_open_p (glibtop *server, const char *program_name,
const unsigned long features, const unsigned flags)
{ {
register int pagesize; register int pagesize;
@@ -82,22 +92,25 @@ glibtop_open_r (glibtop *server, const char *program_name,
server->machine.kd = kvm_open (NULL, NULL, NULL, O_RDONLY, "libgtop"); server->machine.kd = kvm_open (NULL, NULL, NULL, O_RDONLY, "libgtop");
if (server->machine.kd == NULL) if (server->machine.kd == NULL)
glibtop_error_r (server, "kvm_open: %s", strerror (errno)); glibtop_error_io_r (server, "kvm_open");
/* get the list of symbols we want to access in the kernel */ /* get the list of symbols we want to access in the kernel */
server->machine.nlist_count = kvm_nlist (server->machine.kd, _glibtop_nlist); server->machine.nlist_count = kvm_nlist
(server->machine.kd, _glibtop_nlist);
if (server->machine.nlist_count < 0) if (server->machine.nlist_count < 0)
glibtop_error_r (server, "nlist: %s", strerror (errno)); glibtop_error_io_r (server, "nlist");
#ifdef MULTIPROCESSOR #ifdef MULTIPROCESSOR
/* were ncpu and xp_time not found in the nlist? */ /* were ncpu and xp_time not found in the nlist? */
if ((server->machine.nlist_count > 0) && (_glibtop_nlist[X_NCPU].n_type == 0) && if ((server->machine.nlist_count > 0) &&
(_glibtop_nlist[X_NCPU].n_type == 0) &&
(_glibtop_nlist[X_MP_TIME].n_type == 0)) { (_glibtop_nlist[X_MP_TIME].n_type == 0)) {
/* we were compiled on an MP system but we are not running on one */ /* we were compiled on an MP system but we are not running
/* so we will pretend this didn't happen and set ncpu = 1 */ * on one, so we will pretend this didn't happen and set
* ncpu = 1 */
server->machine.nlist_count -= 2; server->machine.nlist_count -= 2;
server->machine.ncpu = 1; server->machine.ncpu = 1;
} }
@@ -108,7 +121,8 @@ glibtop_open_r (glibtop *server, const char *program_name,
unsigned int status, type; unsigned int status, type;
/* Get the number of CPUs on this system. */ /* Get the number of CPUs on this system. */
syscall(SYS_getcpustatus, &status, &server->machine.ncpu, &type); syscall(SYS_getcpustatus, &status,
&server->machine.ncpu, &type);
} }
#endif #endif
@@ -181,16 +195,17 @@ glibtop_open_r (glibtop *server, const char *program_name,
/* !!! END OF SUID ROOT PART !!! */ /* !!! END OF SUID ROOT PART !!! */
/* Our effective uid is now those of the user invoking the server, /* Our effective uid is now those of the user invoking the server,
so we do no longer have any priviledges. * so we do no longer have any priviledges. */
*/
/* NOTE: On SunOS, we do not need to be suid root, we just need to be sgid kmem. /* NOTE: On SunOS, we do not need to be suid root, we just need to
* The server will only use setegid() to get back it's priviledges, so it * be sgid kmem.
* will fail if it is suid root and not sgid kmem. *
*/ * The server will only use setegid() to get back it's priviledges,
* so it will fail if it is suid root and not sgid kmem. */
} }
/* Used internally. Returns number of symbols that cannot be found in the nlist. */ /* Used internally. Returns number of symbols that cannot be found in
* the nlist. */
int int
_glibtop_check_nlist (void *server, register struct nlist *nlst) _glibtop_check_nlist (void *server, register struct nlist *nlst)
@@ -206,12 +221,16 @@ _glibtop_check_nlist (void *server, register struct nlist *nlst)
#ifdef i386 #ifdef i386
if (nlst->n_value == 0) { if (nlst->n_value == 0) {
glibtop_error_r (server, "kernel: no symbol named `%s'", nlst->n_name); glibtop_error_r (server,
"kernel: no symbol named `%s'",
nlst->n_name);
not_found++; not_found++;
} }
#else #else
if (nlst->n_type == 0) { if (nlst->n_type == 0) {
glibtop_error_r (server, "kernel: no symbol named `%s'", nlst->n_name); glibtop_error_r (server,
"kernel: no symbol named `%s'",
nlst->n_name);
not_found++; not_found++;
} }
#endif #endif
@@ -225,18 +244,19 @@ _glibtop_check_nlist (void *server, register struct nlist *nlst)
/* Used internally. Fetches value from kernel. */ /* Used internally. Fetches value from kernel. */
int int
_glibtop_getkval (void *void_server, unsigned long offset, int *ptr, int size, char *refstr) _glibtop_getkval (void *void_server, unsigned long offset, int *ptr,
int size, char *refstr)
{ {
glibtop *server = (glibtop *) void_server; glibtop *server = (glibtop *) void_server;
if (kvm_read (server->machine.kd, offset, ptr, size) != size) if (kvm_read (server->machine.kd, offset, ptr, size) != size)
{ {
if (*refstr == '!') return 0; if (*refstr == '!') return 0;
glibtop_error_r (server, "kvm_read(%s): %s", glibtop_error_r (server, "kvm_read(%s): %s",
refstr, strerror (errno)); refstr, strerror (errno));
} }
return 1; return 1;
} }

View File

@@ -33,7 +33,7 @@ glibtop_get_proc_kernel_p (glibtop *server, glibtop_proc_kernel *buf,
{ {
struct proc *pp; struct proc *pp;
glibtop_init_r (&server, 0, 0); glibtop_init_p (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_proc_kernel)); memset (buf, 0, sizeof (glibtop_proc_kernel));

View File

@@ -42,7 +42,7 @@ glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf)
unsigned *proc_list = NULL; unsigned *proc_list = NULL;
size_t proc_size; size_t proc_size;
glibtop_init_r (&server, 0, 0); glibtop_init_p (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_proclist)); memset (buf, 0, sizeof (glibtop_proclist));

View File

@@ -34,7 +34,7 @@ glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf,
{ {
struct proc *pp; struct proc *pp;
glibtop_init_r (&server, 0, 0); glibtop_init_p (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_proc_mem)); memset (buf, 0, sizeof (glibtop_proc_mem));

View File

@@ -33,7 +33,7 @@ glibtop_get_proc_segment_p (glibtop *server, glibtop_proc_segment *buf,
{ {
struct proc *pp; struct proc *pp;
glibtop_init_r (&server, 0, 0); glibtop_init_p (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_proc_segment)); memset (buf, 0, sizeof (glibtop_proc_segment));

View File

@@ -34,7 +34,7 @@ glibtop_get_proc_signal_p (glibtop *server, glibtop_proc_signal *buf,
{ {
struct proc *pp; struct proc *pp;
glibtop_init_r (&server, 0, 0); glibtop_init_p (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_proc_signal)); memset (buf, 0, sizeof (glibtop_proc_signal));

View File

@@ -33,7 +33,7 @@ glibtop_get_proc_state_p (glibtop *server, glibtop_proc_state *buf,
{ {
struct proc *pp; struct proc *pp;
glibtop_init_r (&server, 0, 0); glibtop_init_p (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_proc_state)); memset (buf, 0, sizeof (glibtop_proc_state));

View File

@@ -33,7 +33,7 @@ glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf,
{ {
struct proc *pp; struct proc *pp;
glibtop_init_r (&server, 0, 0); glibtop_init_p (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_proc_time)); memset (buf, 0, sizeof (glibtop_proc_time));

View File

@@ -37,7 +37,7 @@ glibtop_get_proc_uid_p (glibtop *server, glibtop_proc_uid *buf,
{ {
struct proc *pp; struct proc *pp;
glibtop_init_r (&server, 0, 0); glibtop_init_p (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_proc_uid)); memset (buf, 0, sizeof (glibtop_proc_uid));

View File

@@ -43,7 +43,7 @@ glibtop_get_sem_limits_p (glibtop *server, glibtop_sem_limits *buf)
{ {
struct seminfo seminfo; struct seminfo seminfo;
glibtop_init_r (&server, 0, 0); glibtop_init_p (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_sem_limits)); memset (buf, 0, sizeof (glibtop_sem_limits));

View File

@@ -41,7 +41,7 @@ glibtop_get_shm_limits_p (glibtop *server, glibtop_shm_limits *buf)
{ {
struct shminfo shminfo; struct shminfo shminfo;
glibtop_init_r (&server, 0, 0); glibtop_init_p (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_shm_limits)); memset (buf, 0, sizeof (glibtop_shm_limits));

View File

@@ -27,7 +27,7 @@
void void
glibtop_get_swap_p (glibtop *server, glibtop_swap *buf) glibtop_get_swap_p (glibtop *server, glibtop_swap *buf)
{ {
glibtop_init_r (&server, 0, 0); glibtop_init_p (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_swap)); memset (buf, 0, sizeof (glibtop_swap));
} }

View File

@@ -33,7 +33,7 @@ glibtop_get_uptime_p (glibtop *server, glibtop_uptime *buf)
{ {
glibtop_cpu cpu; glibtop_cpu cpu;
glibtop_init_r (&server, 0, 0); glibtop_init_p (&server, 0, 0);
/* Get currect cpu usage. */ /* Get currect cpu usage. */