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.in
aclocal.m4
alpha-dec-osf1
autoh31167
config.cache
config.h
config.h.in
@@ -25,3 +23,4 @@ sun4
sun4sol2
support
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>
* doc/ChangeLog: New file.

View File

@@ -231,6 +231,13 @@ if test "$need_gnome_support" = yes; then
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([
Makefile
po/Makefile.in

View File

@@ -211,7 +211,7 @@ main (int argc, char *argv [])
glibtop_get_proc_signal (&data.proc_signal, pid);
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.sigignore, data.proc_signal.sigcatch);
@@ -282,7 +282,7 @@ main (int argc, char *argv [])
glibtop_get_proc_signal (&data.proc_signal, ppid);
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.sigignore, data.proc_signal.sigcatch);
@@ -353,7 +353,7 @@ main (int argc, char *argv [])
glibtop_get_proc_signal (&data.proc_signal, 1);
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.sigignore, data.proc_signal.sigcatch);

View File

@@ -110,7 +110,7 @@ main (int argc, char *argv [])
glibtop_get_proc_signal (&data.proc_signal, pid);
fprintf (stderr, "Proc_Signal PID %5u (0x%08lx): "
"%d %d %d %d\n", pid, data.proc_signal.flags,
"%lu %lu %lu %lu\n", pid, data.proc_signal.flags,
data.proc_signal.signal, data.proc_signal.blocked,
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_mem long(size,vsize,resident,share,rss,rss_rlim)
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_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);
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

View File

@@ -28,6 +28,9 @@ __BEGIN_DECLS
extern void glibtop_close_r __P((glibtop *));
extern void glibtop_close_s __P((glibtop *));
extern void glibtop_close_p __P((glibtop *));
__END_DECLS
#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_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

View File

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

View File

@@ -191,3 +191,21 @@ glibtop_init_r (glibtop **server_ptr, const unsigned long features,
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

@@ -9,7 +9,6 @@ BEGIN {
print "#include <glibtop/command.h>";
print "";
}
function output(feature) {
@@ -35,16 +34,30 @@ function output(feature) {
print "\t{";
if (feature ~ /^proc_/) {
print "\t\t"prefix"glibtop_call_l (server, GLIBTOP_CMND_"toupper(feature)", sizeof (pid_t),";
print "\t\t\t\t&pid, sizeof (glibtop_"feature"), buf);";
print "\t\tglibtop_call_l (server, GLIBTOP_CMND_"toupper(feature)",";
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\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 {
print "\t\t"prefix"glibtop_call_l (server, GLIBTOP_CMND_"toupper(feature)", 0, NULL,";
print "\t\t\t sizeof (glibtop_"feature"), buf);";
if (feature ~ /^proclist$/) {
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 "#if (!GLIBTOP_SUID_"toupper(feature)")";
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 "}";
print "";

View File

@@ -44,12 +44,23 @@ glibtop_open_l (glibtop *server, const char *program_name,
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) {
case GLIBTOP_METHOD_DIRECT:
fprintf (stderr, "Calling sysdeps open function.\n");
glibtop_open_r (server, program_name, features, flags);
server->features = 0;
break;
case GLIBTOP_METHOD_INET:
fprintf (stderr, "Connecting to '%s' port %ld.\n",
@@ -81,14 +92,6 @@ glibtop_open_l (glibtop *server, const char *program_name,
fprintf (stderr, "Opening pipe to server (%s).\n",
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))
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->output [0], 0);
execl (GTOP_SERVER, NULL);
glibtop_error_io_r (server, "execl %s", GTOP_SERVER);
glibtop_error_io_r (server, "execl (%s)", GTOP_SERVER);
_exit (2);
}
@@ -138,4 +141,11 @@ glibtop_open_l (glibtop *server, const char *program_name,
fprintf (stderr, "Server features are %lu.\n",
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@ \
-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
gnuserv_LDADD = $(top_builddir)/lib/libgtop.la \
libgtop_daemon_SOURCES = gnuserv.c main.c io.c
libgtop_daemon_LDADD = $(top_builddir)/lib/libgtop.la \
$(top_builddir)/sysdeps/common/libgtop_common.la \
$(top_builddir)/sysdeps/@sysdeps_dir@/libgtop_sysdeps.la \
@sysdeps_suid_lib@ \
@INTLLIBS@ @LIBSUPPORT@ @X_LIBS@ -lXau
gnuserv_LDFLAGS = -static
gtop_daemon_SOURCES = main.c inet.c loop.c output.c version.c
gtop_daemon_LDADD = $(top_builddir)/lib/libgtop.la \
$(top_builddir)/sysdeps/common/libgtop_common.la \
$(top_builddir)/sysdeps/@sysdeps_dir@/libgtop_sysdeps.la \
@INTLLIBS@ @LIBSUPPORT@
gtop_daemon_LDFLAGS = -static
libgtop_daemon_LDFLAGS = -static

View File

@@ -19,26 +19,43 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#ifndef __GLIBTOP_DAEMON_H__
#define __GLIBTOP_DAEMON_H__
#include <glibtop.h>
#include <glibtop/gnuserv.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;
glibtop *glibtop_global_server = NULL;
#include <fcntl.h>
glibtop *
glibtop_init_r (glibtop **server, const unsigned long features,
const unsigned flags)
{
if (*server != NULL)
return *server;
__BEGIN_DECLS
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) {
glibtop_global_server = &_glibtop_global_server;
glibtop_open_r (glibtop_global_server, "glibtop",
features, flags);
}
#define _offset_union(p) ((char *) &resp->u.p - (char *) resp)
#define _offset_data(p) _offset_union (data.p)
return *server = glibtop_global_server;
}
#define MSG_BUFSZ sizeof (struct _glibtop_ipc_message)
#define MSG_MSGSZ (MSG_BUFSZ - sizeof (long))
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
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));
#if !defined(UNIX_DOMAIN_SOCKETS) && !defined(INTERNET_DOMAIN_SOCKETS)
@@ -216,7 +216,7 @@ static int
setup_table (void)
{
char hostname [HOSTNAMSZ];
u_int host_addr;
long host_addr;
int i, hosts = 0;
/* Make sure every entry is null */
@@ -225,7 +225,7 @@ setup_table (void)
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);
#ifdef AUTH_MAGIC_COOKIE
@@ -326,13 +326,15 @@ handle_internet_request (int ls)
glibtop_error_io ("accept");
#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
/* Check that access is allowed - if not return crud to the client */
if (!permitted (peer.sin_addr.s_addr, 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;
} /* if */
@@ -453,6 +455,7 @@ handle_unix_request (int ls)
fprintf (stderr, "Accepted connection on socket %d.\n", s);
#endif
#ifdef GLIBTOP_DAEMON_SLAVE
pid = fork ();
if (pid == -1)
@@ -461,7 +464,8 @@ handle_unix_request (int ls)
if (pid)
return;
handle_child_connection (s);
handle_slave_connection (s, s);
#endif
close (s);
@@ -502,7 +506,11 @@ main (int argc, char *argv [])
signal (SIGCHLD, handle_signal);
#ifdef GLIBTOP_DAEMON_SLAVE
pid = fork ();
#else
pid = getpid ();
#endif
if (pid == -1)
glibtop_error_io ("fork failed");
@@ -542,7 +550,11 @@ main (int argc, char *argv [])
} else {
/* We are the parent. */
#ifdef GLIBTOP_DAEMON_SLAVE
const unsigned method = GLIBTOP_METHOD_UNIX;
#else
const unsigned method = GLIBTOP_METHOD_PIPE;
#endif
const unsigned long features = GLIBTOP_SYSDEPS_ALL;
@@ -657,8 +669,11 @@ main (int argc, char *argv [])
handle_internet_request (ils);
#endif
if (FD_ISSET (fileno (stdin), &rmask))
handle_child_connection (fileno (stdin));
#ifdef GLIBTOP_DAEMON_SLAVE
if ((pid == 0) && FD_ISSET (fileno (stdin), &rmask))
handle_slave_connection (fileno (stdin),
fileno (stdout));
#endif
}
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,
Boston, MA 02111-1307, USA. */
#include <glibtop/gnuserv.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;
}
#include "daemon.h"
void
handle_parent_connection (int s)
@@ -125,7 +33,7 @@ handle_parent_connection (int s)
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
fprintf (stderr, "Parent (%d) received command %d from client.\n",
getpid (), cmnd->command);
@@ -153,6 +61,7 @@ handle_parent_connection (int s)
case GLIBTOP_CMND_QUIT:
do_output (s, resp, 0, 0, NULL);
#ifdef GLIBTOP_DAEMON_SLAVE
fprintf (stderr, "Sending QUIT command (%d).\n",
server->socket);
@@ -163,6 +72,7 @@ handle_parent_connection (int s)
server->socket);
close (server->socket);
#endif
return;
case GLIBTOP_CMND_SYSDEPS:
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,
Boston, MA 02111-1307, USA. */
#include <glibtop.h>
#include <glibtop/gnuserv.h>
#include "daemon.h"
#include <glibtop/open.h>
#include <glibtop/union.h>
void
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>
#include <glibtop/parameter.h>
while (do_read (input, cmnd, sizeof (glibtop_command))) {
#ifdef SLAVE_DEBUG
fprintf (stderr, "Slave %d received command "
"%d from client.\n", getpid (), cmnd->command);
#endif
#define _offset_union(p) ((char *) &resp->u.p - (char *) resp)
#define _offset_data(p) _offset_union (data.p)
if (cmnd->data_size >= BUFSIZ)
glibtop_error ("Client sent %d bytes, "
"but buffer is %d",
cmnd->size, BUFSIZ);
memset (parameter, 0, sizeof (parameter));
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
handle_slave_command (glibtop_command *cmnd, glibtop_response *resp,

View File

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

View File

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

View File

@@ -6,6 +6,8 @@ INCLUDES = -I$(top_builddir) -I$(top_srcdir) @machine_incs@ \
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_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);
if (!buf)
glibtop_error_r (server, _("malloc %d bytes: %s"),
size, strerror (errno));
glibtop_error_io_r (server, "malloc %d bytes", size);
return buf;
}
@@ -41,8 +40,8 @@ glibtop_calloc_r (glibtop *server, size_t nmemb, size_t size)
void *buf = calloc (nmemb, size);
if (!buf)
glibtop_error_r (server, _("calloc %d block (%d bytes each): %s"),
nmemb, size, strerror (errno));
glibtop_error_io_r (server, "calloc %d blocks (%d bytes each)",
nmemb, size);
return buf;
}
@@ -53,8 +52,7 @@ glibtop_realloc_r (glibtop *server, void *ptr, size_t size)
void *buf = realloc (ptr, size);
if (!buf)
glibtop_error_r (server, _("realloc %d bytes: %s"),
size, strerror (errno));
glibtop_error_io_r (server, "realloc %d bytes", size);
return buf;
}

View File

@@ -8,7 +8,7 @@ CFLAGS = -Wall -W @CFLAGS@
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 \
sem_limits.c proclist.c procstate.c procuid.c \
proctime.c procmem.c procsignal.c prockernel.c \

View File

@@ -24,5 +24,5 @@
/* Closes pipe to gtop server. */
void
glibtop_close_l (glibtop *server)
glibtop_close_s (glibtop *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. */
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)
{
server->name = program_name;

View File

@@ -24,5 +24,5 @@
/* Closes pipe to gtop server. */
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. */
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)
{
server->name = program_name;

View File

@@ -6,11 +6,14 @@ INCLUDES = -I$(top_builddir) -I$(top_srcdir) @machine_incs@ \
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 \
sem_limits.c proclist.c procstate.c procuid.c \
proctime.c procmem.c procsignal.c prockernel.c \
procsegment.c
sem_limits.c
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. */
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,
Boston, MA 02111-1307, USA. */
#include <glibtop.h>
#include <glibtop/open.h>
#include <glibtop/close.h>
static glibtop _glibtop_global_server;
glibtop *glibtop_global_server = NULL;
/* Closes pipe to gtop server. */
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;
}
void
glibtop_close_p (glibtop *server)
{ }

View File

@@ -36,7 +36,7 @@ glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
struct tbl_sysinfo sysinfo;
int ret;
glibtop_init ();
glibtop_init_s (&server, 0, 0);
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;
int ret;
glibtop_init ();
glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_loadavg));

View File

@@ -40,7 +40,7 @@ glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
{
vm_statistics_data_t vmstats;
glibtop_init ();
glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_mem));

View File

@@ -35,7 +35,7 @@ glibtop_get_msg_limits_s (glibtop *server, glibtop_msg_limits *buf)
{
int ret, value;
glibtop_init ();
glibtop_init_s (&server, 0, 0);
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,
Boston, MA 02111-1307, USA. */
#include <glibtop.h>
#include <glibtop/open.h>
#include <unistd.h>
@@ -26,39 +27,7 @@
/* Opens pipe to gtop server. Returns 0 on success and -1 on error. */
/* !!! THIS FUNCTION RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
void
glibtop_open (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 ();
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.
*/
}
glibtop_open_s (glibtop *server, const char *program_name,
const unsigned long features, const unsigned flags)
{ }

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,7 +25,7 @@
/* Provides detailed information about a process. */
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)
{
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 !!! */
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 pids [BLOCK_COUNT], *pids_chain = NULL;
@@ -62,7 +62,7 @@ glibtop_get_proclist_r (glibtop *server, glibtop_proclist *buf)
struct tbl_procinfo procinfo [8];
int entry, max_elements, k;
glibtop_init ();
glibtop_open_p (server, 0, 0);
memset (buf, 0, sizeof (glibtop_proclist));

View File

@@ -25,7 +25,7 @@
/* Provides detailed information about a process. */
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)
{
memset (buf, 0, sizeof (glibtop_proc_mem));

View File

@@ -25,7 +25,7 @@
/* Provides detailed information about a process. */
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)
{
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_p (glibtop *server, glibtop_proc_signal *buf,
pid_t pid)
{
memset (buf, 0, sizeof (glibtop_proc_signal));

View File

@@ -25,7 +25,7 @@
/* Provides detailed information about a process. */
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)
{
memset (buf, 0, sizeof (glibtop_proc_state));

View File

@@ -25,7 +25,7 @@
/* Provides detailed information about a process. */
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)
{
memset (buf, 0, sizeof (glibtop_proc_time));

View File

@@ -39,7 +39,7 @@ static const unsigned long _glibtop_sysdeps_proc_uid =
(1 << GLIBTOP_PROC_UID_TTY) + (1 << GLIBTOP_PROC_UID_TPGID);
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)
{
struct tbl_procinfo procinfo;
@@ -47,7 +47,7 @@ glibtop_get_proc_uid_r (glibtop *server, glibtop_proc_uid *buf,
int ret, info_count;
task_t thistask;
glibtop_init ();
glibtop_open_p (server, 0, 0);
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;
glibtop_init ();
glibtop_init_s (&server, 0, 0);
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;
glibtop_init ();
glibtop_init_s (&server, 0, 0);
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;
int i;
glibtop_init ();
glibtop_init_s (&server, 0, 0);
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;
int ret;
glibtop_init ();
glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_uptime));

View File

@@ -8,7 +8,7 @@ CFLAGS = -Wall -W @CFLAGS@
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 \
sem_limits.c proclist.c procstate.c procuid.c \
proctime.c procmem.c procsignal.c prockernel.c \

View File

@@ -24,5 +24,5 @@
/* Closes pipe to gtop server. */
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. */
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)
{
server->name = program_name;

View File

@@ -6,11 +6,14 @@ INCLUDES = -I$(top_builddir) -I$(top_srcdir) @machine_incs@ \
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 \
sem_limits.c proclist.c procstate.c procuid.c \
proctime.c procmem.c procsignal.c prockernel.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. */
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];
int i;
glibtop_init_r (&server, 0, 0);
glibtop_init_p (&server, 0, 0);
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];
int i;
glibtop_init_r (&server, 0, 0);
glibtop_init_p (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_loadavg));

View File

@@ -35,7 +35,7 @@ static const unsigned long _glibtop_sysdeps_mem =
void
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));

View File

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

View File

@@ -22,19 +22,11 @@
#include <glibtop.h>
#include <glibtop/open.h>
static glibtop _glibtop_global_server;
glibtop *glibtop_global_server = NULL;
void
glibtop_open_s (glibtop *server, const char *program_name,
const unsigned long features, const unsigned flags)
{ }
glibtop *
glibtop_init_r (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;
}
void
glibtop_close_s (glibtop *server)
{ }

View File

@@ -63,7 +63,17 @@ struct nlist _glibtop_nlist[] = {
/* !!! THIS FUNCTION RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
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)
{
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;
@@ -82,22 +92,25 @@ glibtop_open_r (glibtop *server, const char *program_name,
server->machine.kd = kvm_open (NULL, NULL, NULL, O_RDONLY, "libgtop");
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 */
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)
glibtop_error_r (server, "nlist: %s", strerror (errno));
glibtop_error_io_r (server, "nlist");
#ifdef MULTIPROCESSOR
/* 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)) {
/* we were compiled on an MP system but we are not running on one */
/* so we will pretend this didn't happen and set ncpu = 1 */
/* we were compiled on an MP system but we are not running
* on one, so we will pretend this didn't happen and set
* ncpu = 1 */
server->machine.nlist_count -= 2;
server->machine.ncpu = 1;
}
@@ -108,7 +121,8 @@ glibtop_open_r (glibtop *server, const char *program_name,
unsigned int status, type;
/* 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
@@ -181,16 +195,17 @@ glibtop_open_r (glibtop *server, const char *program_name,
/* !!! 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.
*/
* 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.
* 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.
*/
/* NOTE: On SunOS, we do not need to be suid root, we just need to
* be 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
_glibtop_check_nlist (void *server, register struct nlist *nlst)
@@ -206,12 +221,16 @@ _glibtop_check_nlist (void *server, register struct nlist *nlst)
#ifdef i386
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++;
}
#else
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++;
}
#endif
@@ -225,7 +244,8 @@ _glibtop_check_nlist (void *server, register struct nlist *nlst)
/* Used internally. Fetches value from kernel. */
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;

View File

@@ -33,7 +33,7 @@ glibtop_get_proc_kernel_p (glibtop *server, glibtop_proc_kernel *buf,
{
struct proc *pp;
glibtop_init_r (&server, 0, 0);
glibtop_init_p (&server, 0, 0);
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;
size_t proc_size;
glibtop_init_r (&server, 0, 0);
glibtop_init_p (&server, 0, 0);
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;
glibtop_init_r (&server, 0, 0);
glibtop_init_p (&server, 0, 0);
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;
glibtop_init_r (&server, 0, 0);
glibtop_init_p (&server, 0, 0);
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;
glibtop_init_r (&server, 0, 0);
glibtop_init_p (&server, 0, 0);
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;
glibtop_init_r (&server, 0, 0);
glibtop_init_p (&server, 0, 0);
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;
glibtop_init_r (&server, 0, 0);
glibtop_init_p (&server, 0, 0);
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;
glibtop_init_r (&server, 0, 0);
glibtop_init_p (&server, 0, 0);
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;
glibtop_init_r (&server, 0, 0);
glibtop_init_p (&server, 0, 0);
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;
glibtop_init_r (&server, 0, 0);
glibtop_init_p (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_shm_limits));

View File

@@ -27,7 +27,7 @@
void
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));
}

View File

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