summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Baulig <martin@home-of-linux.org>1998-08-07 12:59:00 +0000
committerMartin Baulig <martin@src.gnome.org>1998-08-07 12:59:00 +0000
commita510ed127175d2f0cb04a7c5c76dfe71e9ac3ad9 (patch)
treefac819e144a625cd80ed18cbee7bd858478fbfe3
parent3b4e0378f962a485e7980e5089b6dcfee0298c5d (diff)
downloadlibgtop-a510ed127175d2f0cb04a7c5c76dfe71e9ac3ad9.tar.gz
Removed. New files. Added `libgtop_server'; this has been moved here from
1998-08-07 Martin Baulig <martin@home-of-linux.org> * src/server: Removed. * src/daemon/{server, version}.c: New files. * src/daemon/Makefile.am: Added `libgtop_server'; this has been moved here from `src/server' since it shares some source code files with the `libgtop_daemon'. * LIBGTOP-VERSION: Added `LIBGTOP_SERVER_VERSION'. * src/daemon/gnuserv.c, lib/open.c: Improved version check between client and server. * include/glibtop/output.h: Removed. * sysdeps/stub_suid: New directory. This is mainly used as example for people porting libgtop to other systems. * sysdeps/common/sysdeps_suid.c: New file. Defines `glibtop_init_hook_p'. * sysdeps/osf1/*.c (glibtop_init_<no-suid-feature>_s): New functions. (glibtop_init_<suid-feature>_p): New functions.
-rw-r--r--ChangeLog20
-rw-r--r--LIBGTOP-VERSION3
-rw-r--r--Makefile.am1
-rw-r--r--configure.in9
-rw-r--r--include/glibtop/sysdeps.h1
-rw-r--r--include/glibtop/version.h13
-rw-r--r--lib/open.c46
-rw-r--r--libgtopConf.sh.in2
-rw-r--r--src/Makefile.am10
-rw-r--r--src/daemon/Makefile.am18
-rw-r--r--src/daemon/io.c20
-rw-r--r--src/daemon/main.c2
-rw-r--r--src/daemon/server.c88
-rw-r--r--src/daemon/slave.c2
-rw-r--r--src/daemon/version.c (renamed from include/glibtop/output.h)49
-rw-r--r--sysdeps/Makefile.am4
-rw-r--r--sysdeps/common/Makefile.am2
-rw-r--r--sysdeps/common/sysdeps_suid.c76
-rw-r--r--sysdeps/osf1/cpu.c10
-rw-r--r--sysdeps/osf1/loadavg.c10
-rw-r--r--sysdeps/osf1/mem.c14
-rw-r--r--sysdeps/osf1/msg_limits.c8
-rw-r--r--sysdeps/osf1/open_suid.c17
-rw-r--r--sysdeps/osf1/prockernel.c17
-rw-r--r--sysdeps/osf1/proclist.c10
-rw-r--r--sysdeps/osf1/procmem.c10
-rw-r--r--sysdeps/osf1/procsegment.c10
-rw-r--r--sysdeps/osf1/procsignal.c10
-rw-r--r--sysdeps/osf1/procstate.c10
-rw-r--r--sysdeps/osf1/proctime.c10
-rw-r--r--sysdeps/osf1/procuid.c10
-rw-r--r--sysdeps/osf1/sem_limits.c8
-rw-r--r--sysdeps/osf1/shm_limits.c8
-rw-r--r--sysdeps/osf1/swap.c10
-rw-r--r--sysdeps/osf1/uptime.c10
35 files changed, 478 insertions, 70 deletions
diff --git a/ChangeLog b/ChangeLog
index c6a66266..dc091701 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,8 +1,28 @@
1998-08-07 Martin Baulig <martin@home-of-linux.org>
+ * src/server: Removed.
+ * src/daemon/{server, version}.c: New files.
+ * src/daemon/Makefile.am: Added `libgtop_server'; this has been
+ moved here from `src/server' since it shares some source code files
+ with the `libgtop_daemon'.
+
+ * LIBGTOP-VERSION: Added `LIBGTOP_SERVER_VERSION'.
+ * src/daemon/gnuserv.c, lib/open.c: Improved version check between
+ client and server.
+
+ * include/glibtop/output.h: Removed.
+
* sysdeps/stub_suid: New directory. This is mainly used as example
for people porting libgtop to other systems.
+ * sysdeps/common/sysdeps_suid.c: New file.
+ Defines `glibtop_init_hook_p'.
+
+ * sysdeps/osf1/*.c (glibtop_init_<no-suid-feature>_s): New functions.
+ (glibtop_init_<suid-feature>_p): New functions.
+
+1998-08-07 Martin Baulig <martin@home-of-linux.org>
+
* glibtop.h (_glibtop): New fields `error_method', `sysdeps' and
`required'. I added an improved error handling: the client can tell
the libraries which fields are absolutely required for each features
diff --git a/LIBGTOP-VERSION b/LIBGTOP-VERSION
index 8c95f426..97276b37 100644
--- a/LIBGTOP-VERSION
+++ b/LIBGTOP-VERSION
@@ -2,6 +2,9 @@ LIBGTOP_MAJOR_VERSION=0
LIBGTOP_MINOR_VERSION=2a
LIBGTOP_VERSION=$LIBGTOP_MAJOR_VERSION.$LIBGTOP_MINOR_VERSION
+# Increase each time you change the client/server protocol.
+LIBGTOP_SERVER_VERSION=1
+
# For automake.
VERSION=$LIBGTOP_VERSION
PACKAGE=libgtop
diff --git a/Makefile.am b/Makefile.am
index 74ff5c82..d44a082e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -56,6 +56,7 @@ libgtopConf.sh: libgtopConf.sh.in Makefile
-e 's,\@LIBGTOP_MAJOR_VERSION\@,$(LIBGTOP_MAJOR_VERSION),g' \
-e 's,\@LIBGTOP_MINOR_VERSION\@,$(LIBGTOP_MINOR_VERSION),g' \
-e 's,\@LIBGTOP_VERSION\@,$(LIBGTOP_VERSION),g' \
+ -e 's,\@LIBGTOP_SERVER_VERSION\@,$(LIBGTOP_SERVER_VERSION),g' \
-e 's,\@libgtop_sysdeps_dir\@,$(libgtop_sysdeps_dir),g' \
-e 's,\@libgtop_need_server\@,$(libgtop_need_server),g' \
-e 's,\@libgtop_use_machine_h\@,$(libgtop_use_machine_h),g' \
diff --git a/configure.in b/configure.in
index d267ddde..8f82b247 100644
--- a/configure.in
+++ b/configure.in
@@ -11,6 +11,7 @@ AM_INIT_AUTOMAKE($PACKAGE, $VERSION)
AC_SUBST(LIBGTOP_MAJOR_VERSION)
AC_SUBST(LIBGTOP_MINOR_VERSION)
+AC_SUBST(LIBGTOP_SERVER_VERSION)
AC_SUBST(LIBGTOP_VERSION)
AM_ACLOCAL_INCLUDE(macros)
@@ -175,7 +176,7 @@ LIBGTOP_INCS='-I$(includedir)'
LIBGTOP_GUILE_LIBS="$LIBGTOP_LIBS"
LIBGTOP_GUILE_INCS="$LIBGTOP_INCS"
LIBGTOP_BINDIR='$(bindir)'
-LIBGTOP_SERVER='$(bindir)/gtop_server'
+LIBGTOP_SERVER='$(bindir)/libgtop_server'
sysdeps_dir="$libgtop_sysdeps_dir"
AC_SUBST(sysdeps_dir)
@@ -218,7 +219,7 @@ else
guile_def=""
fi
-INCLUDES="$CFLAGS -D_IN_LIBGTOP -D_GNU_SOURCE -DGLIBTOP_NAMES $guile_def -I\$(top_builddir) -I\$(top_srcdir) -I\$(top_srcdir)/sysdeps/$sysdeps_dir -I\$(top_srcdir)/include -I\$(top_srcdir)/intl "'-DGTOPLOCALEDIR=\"$(datadir)/locale\" -DLIBGTOP_VERSION=\"'"$LIBGTOP_VERSION"'\" -DLIBGTOP_SERVER=\"'"$LIBGTOP_SERVER"'\"'
+INCLUDES="$CFLAGS -D_IN_LIBGTOP -D_GNU_SOURCE -DGLIBTOP_NAMES $guile_def -I\$(top_builddir) -I\$(top_srcdir) -I\$(top_srcdir)/sysdeps/$sysdeps_dir -I\$(top_srcdir)/include -I\$(top_srcdir)/intl "'-DGTOPLOCALEDIR=\"$(datadir)/locale\" -DLIBGTOP_VERSION=\"'"$LIBGTOP_VERSION"'\" -DLIBGTOP_SERVER_VERSION=\"'"$LIBGTOP_SERVER_VERSION"'\" -DLIBGTOP_SERVER=\"'"$LIBGTOP_SERVER"'\"'
AC_SUBST(INCLUDES)
@@ -247,10 +248,13 @@ fi
if test x$libgtop_need_server = xyes ; then
sysdeps_suid_lib="\$(top_builddir)/sysdeps/\$(sysdeps_dir)/libgtop_sysdeps_suid.la"
+ server_programs='libgtop_server'
else
sysdeps_suid_lib=
+ server_programs=
fi
AC_SUBST(sysdeps_suid_lib)
+AC_SUBST(server_programs)
AC_OUTPUT([
Makefile
@@ -264,6 +268,7 @@ sysdeps/names/Makefile
sysdeps/guile/Makefile
sysdeps/guile/names/Makefile
sysdeps/stub/Makefile
+sysdeps/stub_suid/Makefile
sysdeps/sun4/Makefile
sysdeps/osf1/Makefile
sysdeps/linux/Makefile
diff --git a/include/glibtop/sysdeps.h b/include/glibtop/sysdeps.h
index e3b9551b..14880f28 100644
--- a/include/glibtop/sysdeps.h
+++ b/include/glibtop/sysdeps.h
@@ -52,6 +52,7 @@ __BEGIN_DECLS
typedef void (*glibtop_init_func_t) (glibtop *);
extern glibtop_init_func_t _glibtop_init_hook_s [];
+extern glibtop_init_func_t _glibtop_init_hook_p [];
typedef struct _glibtop_sysdeps glibtop_sysdeps;
diff --git a/include/glibtop/version.h b/include/glibtop/version.h
index 5676b997..9a03faef 100644
--- a/include/glibtop/version.h
+++ b/include/glibtop/version.h
@@ -20,11 +20,20 @@
#ifndef __GLIBTOP_VERSION_H__
#define __GLIBTOP_VERSION_H__
-#include <glibtop/output.h>
+#include <glibtop.h>
+#include <glibtop/union.h>
+#include <glibtop/sysdeps.h>
+#include <glibtop/command.h>
+
+#define LIBGTOP_VERSION_STRING "Libgtop %s server version %s (%u,%u,%u,%u)."
__BEGIN_DECLS
-extern void glibtop_version __P((void));
+#if _IN_LIBGTOP
+
+extern void glibtop_send_version __P((glibtop *, int));
+
+#endif
__END_DECLS
diff --git a/lib/open.c b/lib/open.c
index 9d2d5f81..4580f1d0 100644
--- a/lib/open.c
+++ b/lib/open.c
@@ -21,6 +21,7 @@
#include <glibtop.h>
#include <glibtop/open.h>
+#include <glibtop/version.h>
#include <glibtop/sysdeps.h>
#include <glibtop/command.h>
#include <glibtop/xmalloc.h>
@@ -33,9 +34,7 @@ void
glibtop_open_l (glibtop *server, const char *program_name,
const unsigned long features, const unsigned flags)
{
- char version [BUFSIZ], buffer [BUFSIZ];
int connect_type;
- unsigned nbytes;
server->name = program_name;
@@ -133,21 +132,6 @@ glibtop_open_l (glibtop *server, const char *program_name,
close (server->input [1]);
close (server->output [0]);
- sprintf (version, "libgtop server %s ready.\n",
- LIBGTOP_VERSION);
-
- glibtop_read_l (server, sizeof (nbytes), &nbytes);
-
- if (nbytes != strlen (version))
- glibtop_error_r (server, "Requested %u bytes but got %u",
- strlen (version), nbytes);
-
- glibtop_read_l (server, nbytes, buffer);
-
- if (memcmp (version, buffer, strlen (version)))
- glibtop_error_r (server, "server version is not %s",
- LIBGTOP_VERSION);
-
server->flags |= _GLIBTOP_INIT_STATE_SERVER;
server->features = -1;
@@ -157,7 +141,35 @@ glibtop_open_l (glibtop *server, const char *program_name,
/* If the server has been started, ask it for its features. */
if (server->flags & _GLIBTOP_INIT_STATE_SERVER) {
+ char version [BUFSIZ], buffer [BUFSIZ];
glibtop_sysdeps sysdeps;
+ unsigned size, nbytes;
+
+ /* First check whether the server version is correct. */
+
+ sprintf (version, LIBGTOP_VERSION_STRING,
+ LIBGTOP_VERSION, LIBGTOP_SERVER_VERSION,
+ sizeof (glibtop_command),
+ sizeof (glibtop_response),
+ sizeof (glibtop_union),
+ sizeof (glibtop_sysdeps));
+
+ size = strlen (version) + 1;
+
+ glibtop_read_l (server, sizeof (nbytes), &nbytes);
+
+ if (nbytes != size)
+ glibtop_error_r (server,
+ "Requested %u bytes but got %u.",
+ size, nbytes);
+
+ glibtop_read_l (server, nbytes, buffer);
+
+ if (memcmp (version, buffer, size))
+ glibtop_error_r (server, "server version is not %s",
+ LIBGTOP_VERSION);
+
+ /* Now ask it for its features. */
glibtop_call_l (server, GLIBTOP_CMND_SYSDEPS, 0, NULL,
sizeof (glibtop_sysdeps), &sysdeps);
diff --git a/libgtopConf.sh.in b/libgtopConf.sh.in
index 1f7e646f..3072e6fb 100644
--- a/libgtopConf.sh.in
+++ b/libgtopConf.sh.in
@@ -24,6 +24,8 @@ LIBGTOP_MAJOR_VERSION="@LIBGTOP_MAJOR_VERSION@"
LIBGTOP_MINOR_VERSION="@LIBGTOP_MINOR_VERSION@"
LIBGTOP_VERSION="@LIBGTOP_VERSION@"
+LIBGTOP_SERVER_VERSION="@LIBGTOP_SERVER_VERSION@"
+
libgtop_sysdeps_dir="@libgtop_sysdeps_dir@"
libgtop_need_server="@libgtop_need_server@"
libgtop_use_machine_h="@libgtop_use_machine_h@"
diff --git a/src/Makefile.am b/src/Makefile.am
index a3e337cb..247882b8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,10 +1,4 @@
-if NEED_LIBGTOP
-server_SUBDIRS = server
-else
-server_SUBDIRS =
-endif
+SUBDIRS = daemon
-SUBDIRS = $(server_SUBDIRS) daemon
-
-DIST_SUBDIRS = server daemon
+DIST_SUBDIRS = daemon
diff --git a/src/daemon/Makefile.am b/src/daemon/Makefile.am
index 1a67b155..4d10814b 100644
--- a/src/daemon/Makefile.am
+++ b/src/daemon/Makefile.am
@@ -5,18 +5,30 @@ CFLAGS = -Wall -W @CFLAGS@ \
-DPARENT_DEBUG -DSLAVE_DEBUG \
-DGLIBTOP_DAEMON_SLAVE
-bin_PROGRAMS = libgtop_daemon
-
if NEED_LIBGTOP
suid_sysdeps = $(top_builddir)/sysdeps/@sysdeps_dir@/libgtop_sysdeps_suid.la
+suid_common = $(top_builddir)/sysdeps/common/libgtop_suid_common.la
else
suid_sysdeps =
+suid_common =
endif
-libgtop_daemon_SOURCES = gnuserv.c slave.c main.c io.c
+bin_PROGRAMS = libgtop_daemon @server_programs@
+
+EXTRA_PROGRAMS = libgtop_server
+
+libgtop_daemon_SOURCES = gnuserv.c slave.c main.c io.c version.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@ \
+ $(suid_sysdeps) $(suid_common)\
@INTLLIBS@ @LIBSUPPORT@ @X_LIBS@ -lXau
libgtop_daemon_LDFLAGS = -static
+
+libgtop_server_SOURCES = server.c slave.c io.c version.c
+libgtop_server_LDADD = $(top_builddir)/sysdeps/@sysdeps_dir@/libgtop_sysdeps_suid.la \
+ $(top_builddir)/sysdeps/common/libgtop_suid_common.la \
+ @LIBSUPPORT@
+libgtop_server_LDFLAGS = -static
+
diff --git a/src/daemon/io.c b/src/daemon/io.c
index f3c6a410..94189ce5 100644
--- a/src/daemon/io.c
+++ b/src/daemon/io.c
@@ -32,17 +32,27 @@ do_output (int s, glibtop_response *resp, off_t offset,
resp->offset = offset;
resp->data_size = data_size;
-
- if (send (s, resp, sizeof (glibtop_response), 0) < 0)
- glibtop_warn_io ("send");
+
+ if (s == 0) {
+ if (write (1, resp, sizeof (glibtop_response)) < 0)
+ glibtop_warn_io ("write");
+ } else {
+ 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");
+ if (s == 0) {
+ if (write (1, data, resp->data_size) < 0)
+ glibtop_warn_io ("write");
+ } else {
+ if (send (s, data, resp->data_size, 0) , 0)
+ glibtop_warn_io ("send");
+ }
}
}
diff --git a/src/daemon/main.c b/src/daemon/main.c
index abc9ae8d..3319a2e9 100644
--- a/src/daemon/main.c
+++ b/src/daemon/main.c
@@ -33,6 +33,8 @@ handle_parent_connection (int s)
pid_t pid;
void *ptr;
+ glibtop_send_version (glibtop_global_server, s);
+
fprintf (stderr, "Parent features = %lu\n", glibtop_server_features);
#ifdef DEBUG
diff --git a/src/daemon/server.c b/src/daemon/server.c
new file mode 100644
index 00000000..815a5f0f
--- /dev/null
+++ b/src/daemon/server.c
@@ -0,0 +1,88 @@
+/* $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"
+
+static glibtop _glibtop_global_server;
+glibtop *glibtop_global_server = &_glibtop_global_server;
+
+#include <glibtop.h>
+#include <glibtop/union.h>
+#include <glibtop/sysdeps.h>
+
+const unsigned long glibtop_server_features =
+GLIBTOP_SUID_CPU +
+GLIBTOP_SUID_MEM +
+GLIBTOP_SUID_SWAP +
+GLIBTOP_SUID_UPTIME +
+GLIBTOP_SUID_LOADAVG +
+GLIBTOP_SUID_SHM_LIMITS +
+GLIBTOP_SUID_MSG_LIMITS +
+GLIBTOP_SUID_SEM_LIMITS +
+GLIBTOP_SUID_PROCLIST +
+GLIBTOP_SUID_PROC_STATE +
+GLIBTOP_SUID_PROC_UID +
+GLIBTOP_SUID_PROC_MEM +
+GLIBTOP_SUID_PROC_TIME +
+GLIBTOP_SUID_PROC_SIGNAL +
+GLIBTOP_SUID_PROC_KERNEL +
+GLIBTOP_SUID_PROC_SEGMENT;
+
+#include <fcntl.h>
+#include <locale.h>
+
+#if defined(HAVE_GETDTABLESIZE)
+#define GET_MAX_FDS() getdtablesize()
+#else
+/* Fallthrough case - please add other #elif cases above
+ for different OS's as necessary */
+#define GET_MAX_FDS() 256
+#endif
+
+int
+main(int argc, char *argv[])
+{
+ int fd, max_fd;
+
+ /* !!! WE ARE ROOT HERE - CHANGE WITH CAUTION !!! */
+
+ int uid, euid, gid, egid;
+
+ uid = getuid (); euid = geteuid ();
+ gid = getgid (); egid = getegid ();
+
+ glibtop_open_p (glibtop_global_server, argv [0], 0, 0);
+
+ if (setreuid (euid, uid)) _exit (1);
+
+ if (setregid (egid, gid)) _exit (1);
+
+ /* !!! END OF SUID ROOT PART !!! */
+
+ /* close all file descriptors except ones used by the pipes (0 and 1). */
+ max_fd = GET_MAX_FDS();
+ for(fd = 3 /* The first fd after the pipes */; fd < max_fd; fd++)
+ close(fd);
+
+ handle_slave_connection (0, 0);
+
+ _exit (0);
+}
diff --git a/src/daemon/slave.c b/src/daemon/slave.c
index cefeda2d..ba58b2f1 100644
--- a/src/daemon/slave.c
+++ b/src/daemon/slave.c
@@ -30,6 +30,8 @@ handle_slave_connection (int input, int output)
char parameter [BUFSIZ];
void *ptr;
+ glibtop_send_version (glibtop_global_server, output);
+
while (do_read (input, cmnd, sizeof (glibtop_command))) {
#ifdef SLAVE_DEBUG
fprintf (stderr, "Slave %d received command "
diff --git a/include/glibtop/output.h b/src/daemon/version.c
index 293a967d..cd1a5539 100644
--- a/include/glibtop/output.h
+++ b/src/daemon/version.c
@@ -19,15 +19,40 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#ifndef __GLIBTOP_OUTPUT_H__
-#define __GLIBTOP_OUTPUT_H__
-
-#include <glibtop/global.h>
-
-__BEGIN_DECLS
-
-extern void glibtop_output __P((size_t, const void *));
-
-__END_DECLS
-
-#endif
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/version.h>
+
+void
+glibtop_send_version (glibtop *server, int fd)
+{
+ char buffer [BUFSIZ];
+ size_t size;
+
+ sprintf (buffer, LIBGTOP_VERSION_STRING,
+ LIBGTOP_VERSION, LIBGTOP_SERVER_VERSION,
+ sizeof (glibtop_command),
+ sizeof (glibtop_response),
+ sizeof (glibtop_union),
+ sizeof (glibtop_sysdeps));
+
+ size = strlen (buffer) + 1;
+
+ fprintf (stderr, "SERVER ID: |%s|\n", buffer);
+
+ if (fd == 0) {
+ if (write (1, &size, sizeof (size)) < 0)
+ glibtop_warn_io_r (server, "write");
+ } else {
+ if (send (fd, &size, sizeof (size), 0) < 0)
+ glibtop_warn_io_r (server, "send");
+ }
+
+ if (fd == 0) {
+ if (write (1, buffer, size) < 0)
+ glibtop_warn_io_r (server, "write");
+ } else {
+ if (send (fd, buffer, size, 0) < 0)
+ glibtop_warn_io_r (server, "send");
+ }
+}
diff --git a/sysdeps/Makefile.am b/sysdeps/Makefile.am
index 29e6fffe..5fe3e137 100644
--- a/sysdeps/Makefile.am
+++ b/sysdeps/Makefile.am
@@ -6,5 +6,5 @@ endif
SUBDIRS = @sysdeps_dir@ common names $(guile_SUBDIRS)
-DIST_SUBDIRS = common guile linux kernel names osf1 stub sun4 \
- freebsd
+DIST_SUBDIRS = common guile linux kernel names osf1 \
+ stub stud_suidsun4 freebsd
diff --git a/sysdeps/common/Makefile.am b/sysdeps/common/Makefile.am
index 34ff3782..eb7be430 100644
--- a/sysdeps/common/Makefile.am
+++ b/sysdeps/common/Makefile.am
@@ -7,4 +7,4 @@ lib_LTLIBRARIES = libgtop_common.la libgtop_suid_common.la
libgtop_common_la_SOURCES = xmalloc.c error.c gnuslib.c \
fsusage.c fsusage.h mountlist.c mountlist.h
-libgtop_suid_common_la_SOURCES = xmalloc.c error.c
+libgtop_suid_common_la_SOURCES = xmalloc.c error.c sysdeps_suid.c
diff --git a/sysdeps/common/sysdeps_suid.c b/sysdeps/common/sysdeps_suid.c
new file mode 100644
index 00000000..2723f3e8
--- /dev/null
+++ b/sysdeps/common/sysdeps_suid.c
@@ -0,0 +1,76 @@
+/* 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 <glibtop/union.h>
+#include <glibtop/sysdeps.h>
+
+glibtop_init_func_t _glibtop_init_hook_p [] = {
+#if GLIBTOP_SUID_CPU
+ glibtop_init_cpu_p,
+#endif
+#if GLIBTOP_SUID_MEM
+ glibtop_init_mem_p,
+#endif
+#if GLIBTOP_SUID_SWAP
+ glibtop_init_swap_p,
+#endif
+#if GLIBTOP_SUID_UPTIME
+ glibtop_init_uptime_p,
+#endif
+#if GLIBTOP_SUID_LOADAVG
+ glibtop_init_loadavg_p,
+#endif
+#if GLIBTOP_SUID_SHM_LIMITS
+ glibtop_init_shm_limits_p,
+#endif
+#if GLIBTOP_SUID_MSG_LIMITS
+ glibtop_init_msg_limits_p,
+#endif
+#if GLIBTOP_SUID_SEM_LIMITS
+ glibtop_init_sem_limits_p,
+#endif
+#if GLIBTOP_SUID_PROCLIST
+ glibtop_init_proclist_p,
+#endif
+#if GLIBTOP_SUID_PROC_STATE
+ glibtop_init_proc_state_p,
+#endif
+#if GLIBTOP_SUID_PROC_UID
+ glibtop_init_proc_uid_p,
+#endif
+#if GLIBTOP_SUID_PROC_MEM
+ glibtop_init_proc_mem_p,
+#endif
+#if GLIBTOP_SUID_PROC_TIME
+ glibtop_init_proc_time_p,
+#endif
+#if GLIBTOP_SUID_PROC_SIGNAL
+ glibtop_init_proc_signal_p,
+#endif
+#if GLIBTOP_SUID_PROC_KERNEL
+ glibtop_init_proc_kernel_p,
+#endif
+#if GLIBTOP_SUID_PROC_SEGMENT
+ glibtop_init_proc_segment_p,
+#endif
+ NULL
+};
+
diff --git a/sysdeps/osf1/cpu.c b/sysdeps/osf1/cpu.c
index 1258ac17..6eb74b42 100644
--- a/sysdeps/osf1/cpu.c
+++ b/sysdeps/osf1/cpu.c
@@ -28,6 +28,14 @@ static const unsigned long _glibtop_sysdeps_cpu =
(1 << GLIBTOP_CPU_NICE) + (1 << GLIBTOP_CPU_SYS) +
(1 << GLIBTOP_CPU_IDLE) + (1 << GLIBTOP_CPU_FREQUENCY);
+/* Init function. */
+
+void
+glibtop_init_cpu_s (glibtop *server)
+{
+ server->sysdeps.cpu = _glibtop_sysdeps_cpu;
+}
+
/* Provides information about cpu usage. */
void
@@ -36,7 +44,7 @@ glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
struct tbl_sysinfo sysinfo;
int ret;
- glibtop_init_s (&server, 0, 0);
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_CPU, 0);
memset (buf, 0, sizeof (glibtop_cpu));
diff --git a/sysdeps/osf1/loadavg.c b/sysdeps/osf1/loadavg.c
index 4bbf583f..b82a1825 100644
--- a/sysdeps/osf1/loadavg.c
+++ b/sysdeps/osf1/loadavg.c
@@ -26,6 +26,14 @@
static const unsigned long _glibtop_sysdeps_loadavg =
(1 << GLIBTOP_LOADAVG_LOADAVG);
+/* Init function. */
+
+void
+glibtop_init_loadavg_s (glibtop *server)
+{
+ server->sysdeps.loadavg = _glibtop_sysdeps_loadavg;
+}
+
/* Provides load averange. */
void
@@ -34,7 +42,7 @@ glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
struct tbl_loadavg loadavg;
int ret;
- glibtop_init_s (&server, 0, 0);
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_LOADAVG, 0);
memset (buf, 0, sizeof (glibtop_loadavg));
diff --git a/sysdeps/osf1/mem.c b/sysdeps/osf1/mem.c
index edb24ca7..b6141a81 100644
--- a/sysdeps/osf1/mem.c
+++ b/sysdeps/osf1/mem.c
@@ -33,6 +33,14 @@ static const unsigned long _glibtop_sysdeps_mem =
(1 << GLIBTOP_MEM_TOTAL) + (1 << GLIBTOP_MEM_USED) +
(1 << GLIBTOP_MEM_FREE);
+/* Init function. */
+
+void
+glibtop_init_mem_s (glibtop *server)
+{
+ server->sysdeps.mem = _glibtop_sysdeps_mem;
+}
+
/* Provides information about memory usage. */
void
@@ -40,7 +48,7 @@ glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
{
vm_statistics_data_t vmstats;
- glibtop_init_s (&server, 0, 0);
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_MEM, 0);
memset (buf, 0, sizeof (glibtop_mem));
@@ -54,6 +62,6 @@ glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
/* [FIXME]: Is this correct? */
buf->total = (vmstats.active_count + vmstats.inactive_count +
- vmstats.free_count + vmstats.wire_count) *
- vmstats.pagesize;
+ vmstats.free_count + vmstats.wire_count) *
+ vmstats.pagesize;
}
diff --git a/sysdeps/osf1/msg_limits.c b/sysdeps/osf1/msg_limits.c
index e0d33e13..a4d1fc54 100644
--- a/sysdeps/osf1/msg_limits.c
+++ b/sysdeps/osf1/msg_limits.c
@@ -28,6 +28,14 @@ static const unsigned long _glibtop_sysdeps_msg_limits =
(1 << GLIBTOP_IPC_MSGMNB) + (1 << GLIBTOP_IPC_MSGMNI) +
(1 << GLIBTOP_IPC_MSGTQL);
+/* Init function. */
+
+void
+glibtop_init_msg_limits_s (glibtop *server)
+{
+ server->sysdeps.msg_limits = _glibtop_sysdeps_msg_limits;
+}
+
/* Provides information about sysv ipc limits. */
void
diff --git a/sysdeps/osf1/open_suid.c b/sysdeps/osf1/open_suid.c
index f2e7a353..8eba2d8a 100644
--- a/sysdeps/osf1/open_suid.c
+++ b/sysdeps/osf1/open_suid.c
@@ -27,20 +27,31 @@
#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_init_p (glibtop *server, const unsigned long features,
const unsigned flags)
{
+ glibtop_init_func_t *init_fkt;
+
if (server == NULL)
glibtop_error_r (NULL, "glibtop_init_p (server == NULL)");
- glibtop_open_p (server, "glibtop", features, flags);
+ /* Do the initialization, but only if not already initialized. */
+
+ if ((server->flags & _GLIBTOP_INIT_STATE_INIT) == 0) {
+ glibtop_open_p (server, "glibtop", features, flags);
+
+ for (init_fkt = _glibtop_init_hook_p; *init_fkt; init_fkt++)
+ (*init_fkt) (server);
+
+ server->flags |= _GLIBTOP_INIT_STATE_INIT;
+ }
}
+/* !!! 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)
diff --git a/sysdeps/osf1/prockernel.c b/sysdeps/osf1/prockernel.c
index 9312f924..4f183894 100644
--- a/sysdeps/osf1/prockernel.c
+++ b/sysdeps/osf1/prockernel.c
@@ -19,14 +19,29 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#include <config.h>
+#include <glibtop.h>
+#include <glibtop/error.h>
#include <glibtop/prockernel.h>
+#include <glibtop_suid.h>
+
+static const unsigned long _glibtop_sysdeps_proc_kernel = 0;
+
+/* Init function. */
+
+void
+glibtop_init_proc_kernel_p (glibtop *server)
+{
+ server->sysdeps.proc_kernel = _glibtop_sysdeps_proc_kernel;
+}
+
/* Provides detailed information about a process. */
void
glibtop_get_proc_kernel_p (glibtop *server, glibtop_proc_kernel *buf,
pid_t pid)
{
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_KERNEL, 0);
+
memset (buf, 0, sizeof (glibtop_proc_kernel));
}
diff --git a/sysdeps/osf1/proclist.c b/sysdeps/osf1/proclist.c
index 79d9bcb5..0134c29b 100644
--- a/sysdeps/osf1/proclist.c
+++ b/sysdeps/osf1/proclist.c
@@ -30,6 +30,14 @@ static const unsigned long _glibtop_sysdeps_proclist =
(1 << GLIBTOP_PROCLIST_TOTAL) + (1 << GLIBTOP_PROCLIST_NUMBER) +
(1 << GLIBTOP_PROCLIST_SIZE);
+/* Init function. */
+
+void
+glibtop_init_proclist_p (glibtop *server)
+{
+ server->sysdeps.proclist = _glibtop_sysdeps_proclist;
+}
+
/* How many elements are there per proctable entry? */
#define ELEMENTS_PER_ENTRY 8
@@ -64,7 +72,7 @@ glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf)
struct tbl_procinfo procinfo [8];
int entry, max_elements, k;
- glibtop_init_p (server, 0, 0);
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_PROCLIST, 0);
memset (buf, 0, sizeof (glibtop_proclist));
diff --git a/sysdeps/osf1/procmem.c b/sysdeps/osf1/procmem.c
index 34eb915d..98fde9e5 100644
--- a/sysdeps/osf1/procmem.c
+++ b/sysdeps/osf1/procmem.c
@@ -37,6 +37,14 @@ static const unsigned long _glibtop_sysdeps_proc_mem =
(1 << GLIBTOP_PROC_MEM_VSIZE) + (1 << GLIBTOP_PROC_MEM_RESIDENT) +
(1 << GLIBTOP_PROC_MEM_RSS);
+/* Init function. */
+
+void
+glibtop_init_proc_mem_p (glibtop *server)
+{
+ server->sysdeps.proc_mem = _glibtop_sysdeps_proc_mem;
+}
+
/* Provides detailed information about a process. */
void
@@ -48,7 +56,7 @@ glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf,
task_t thistask;
struct user u;
- glibtop_init_p (server, 0, 0);
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_MEM, 0);
memset (buf, 0, sizeof (glibtop_proc_mem));
diff --git a/sysdeps/osf1/procsegment.c b/sysdeps/osf1/procsegment.c
index 59f98fad..e2312a2e 100644
--- a/sysdeps/osf1/procsegment.c
+++ b/sysdeps/osf1/procsegment.c
@@ -31,6 +31,14 @@ static const unsigned long _glibtop_sysdeps_proc_segment =
(1 << GLIBTOP_PROC_SEGMENT_START_CODE) + (1 << GLIBTOP_PROC_SEGMENT_END_CODE) +
(1 << GLIBTOP_PROC_SEGMENT_START_STACK);
+/* Init function. */
+
+void
+glibtop_init_proc_segment_p (glibtop *server)
+{
+ server->sysdeps.proc_segment = _glibtop_sysdeps_proc_segment;
+}
+
/* Provides detailed information about a process. */
void
@@ -40,7 +48,7 @@ glibtop_get_proc_segment_p (glibtop *server, glibtop_proc_segment *buf,
int ret;
struct user u;
- glibtop_init_p (server, 0, 0);
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_SEGMENT, 0);
memset (buf, 0, sizeof (glibtop_proc_segment));
diff --git a/sysdeps/osf1/procsignal.c b/sysdeps/osf1/procsignal.c
index 1871a384..f10c712f 100644
--- a/sysdeps/osf1/procsignal.c
+++ b/sysdeps/osf1/procsignal.c
@@ -29,6 +29,14 @@ static const unsigned long _glibtop_sysdeps_proc_signal =
(1 << GLIBTOP_PROC_SIGNAL_SIGNAL) + (1 << GLIBTOP_PROC_SIGNAL_BLOCKED) +
(1 << GLIBTOP_PROC_SIGNAL_SIGIGNORE) + (1 << GLIBTOP_PROC_SIGNAL_SIGCATCH);
+/* Init function. */
+
+void
+glibtop_init_proc_signal_p (glibtop *server)
+{
+ server->sysdeps.proc_signal = _glibtop_sysdeps_proc_signal;
+}
+
/* Provides detailed information about a process. */
void
@@ -38,7 +46,7 @@ glibtop_get_proc_signal_p (glibtop *server, glibtop_proc_signal *buf,
struct tbl_procinfo procinfo;
int ret;
- glibtop_init_p (server, 0, 0);
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_SIGNAL, 0);
memset (buf, 0, sizeof (glibtop_proc_signal));
diff --git a/sysdeps/osf1/procstate.c b/sysdeps/osf1/procstate.c
index d0debb36..6f583881 100644
--- a/sysdeps/osf1/procstate.c
+++ b/sysdeps/osf1/procstate.c
@@ -29,6 +29,14 @@ static const unsigned long _glibtop_sysdeps_proc_state =
(1 << GLIBTOP_PROC_STATE_CMD) + (1 << GLIBTOP_PROC_STATE_STATE) +
(1 << GLIBTOP_PROC_STATE_UID);
+/* Init function. */
+
+void
+glibtop_init_proc_state_p (glibtop *server)
+{
+ server->sysdeps.proc_state = _glibtop_sysdeps_proc_state;
+}
+
/* Provides detailed information about a process. */
void
@@ -38,7 +46,7 @@ glibtop_get_proc_state_p (glibtop *server, glibtop_proc_state *buf,
struct tbl_procinfo procinfo;
int ret;
- glibtop_init_p (server, 0, 0);
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_STATE, 0);
memset (buf, 0, sizeof (glibtop_proc_state));
diff --git a/sysdeps/osf1/proctime.c b/sysdeps/osf1/proctime.c
index f1d0aa74..8e40d033 100644
--- a/sysdeps/osf1/proctime.c
+++ b/sysdeps/osf1/proctime.c
@@ -32,6 +32,14 @@ static const unsigned long _glibtop_sysdeps_proc_time =
(1 << GLIBTOP_PROC_TIME_STIME) + (1 << GLIBTOP_PROC_TIME_CSTIME) +
(1 << GLIBTOP_PROC_TIME_START_TIME);
+/* Init function. */
+
+void
+glibtop_init_proc_time_p (glibtop *server)
+{
+ server->sysdeps.proc_time = _glibtop_sysdeps_proc_time;
+}
+
/* Provides detailed information about a process. */
void
@@ -41,7 +49,7 @@ glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf,
struct user u;
int ret;
- glibtop_init_p (server, 0, 0);
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_TIME, 0);
memset (buf, 0, sizeof (glibtop_proc_time));
diff --git a/sysdeps/osf1/procuid.c b/sysdeps/osf1/procuid.c
index 40dc3a05..b9cab01c 100644
--- a/sysdeps/osf1/procuid.c
+++ b/sysdeps/osf1/procuid.c
@@ -40,6 +40,14 @@ static const unsigned long _glibtop_sysdeps_proc_uid =
(1 << GLIBTOP_PROC_UID_PGRP) + (1 << GLIBTOP_PROC_UID_SESSION) +
(1 << GLIBTOP_PROC_UID_TTY) + (1 << GLIBTOP_PROC_UID_TPGID);
+/* Init function. */
+
+void
+glibtop_init_proc_uid_p (glibtop *server)
+{
+ server->sysdeps.proc_uid = _glibtop_sysdeps_proc_uid;
+}
+
void
glibtop_get_proc_uid_p (glibtop *server, glibtop_proc_uid *buf,
pid_t pid)
@@ -49,7 +57,7 @@ glibtop_get_proc_uid_p (glibtop *server, glibtop_proc_uid *buf,
int ret, info_count;
task_t thistask;
- glibtop_init_p (server, 0, 0);
+ glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_UID, 0);
memset (buf, 0, sizeof (glibtop_proc_uid));
diff --git a/sysdeps/osf1/sem_limits.c b/sysdeps/osf1/sem_limits.c
index 45c6e663..e807d194 100644
--- a/sysdeps/osf1/sem_limits.c
+++ b/sysdeps/osf1/sem_limits.c
@@ -28,6 +28,14 @@ static unsigned long _glibtop_sysdeps_sem_limits =
(1 << GLIBTOP_IPC_SEMOPM) + (1 << GLIBTOP_IPC_SEMVMX) +
(1 << GLIBTOP_IPC_SEMAEM);
+/* Init function. */
+
+void
+glibtop_init_sem_limits_s (glibtop *server)
+{
+ server->sysdeps.sem_limits = _glibtop_sysdeps_sem_limits;
+}
+
/* Provides information about sysv sem limits. */
void
diff --git a/sysdeps/osf1/shm_limits.c b/sysdeps/osf1/shm_limits.c
index 5cb55f23..94616d46 100644
--- a/sysdeps/osf1/shm_limits.c
+++ b/sysdeps/osf1/shm_limits.c
@@ -27,6 +27,14 @@ static unsigned long _glibtop_sysdeps_shm_limits =
(1 << GLIBTOP_IPC_SHMMAX) + (1 << GLIBTOP_IPC_SHMMIN) +
(1 << GLIBTOP_IPC_SHMMNI) + (1 << GLIBTOP_IPC_SHMSEG);
+/* Init function. */
+
+void
+glibtop_init_shm_limits_s (glibtop *server)
+{
+ server->sysdeps.shm_limits = _glibtop_sysdeps_shm_limits;
+}
+
/* Provides information about sysv ipc limits. */
void
diff --git a/sysdeps/osf1/swap.c b/sysdeps/osf1/swap.c
index 5f1b8c6a..da69799a 100644
--- a/sysdeps/osf1/swap.c
+++ b/sysdeps/osf1/swap.c
@@ -27,6 +27,14 @@ static unsigned long _glibtop_sysdeps_swap =
(1 << GLIBTOP_SWAP_TOTAL) + (1 << GLIBTOP_SWAP_USED) +
(1 << GLIBTOP_SWAP_FREE);
+/* Init function. */
+
+void
+glibtop_init_swap_s (glibtop *server)
+{
+ server->sysdeps.swap = _glibtop_sysdeps_swap;
+}
+
/* Provides information about swap usage. */
void
@@ -35,7 +43,7 @@ glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
struct tbl_swapinfo swapinfo;
int i;
- glibtop_init_s (&server, 0, 0);
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_SWAP, 0);
memset (buf, 0, sizeof (glibtop_swap));
diff --git a/sysdeps/osf1/uptime.c b/sysdeps/osf1/uptime.c
index d7f9e0af..9a310190 100644
--- a/sysdeps/osf1/uptime.c
+++ b/sysdeps/osf1/uptime.c
@@ -28,6 +28,14 @@
static unsigned long _glibtop_sysdeps_uptime =
(1 << GLIBTOP_UPTIME_UPTIME);
+/* Init function. */
+
+void
+glibtop_init_uptime_s (glibtop *server)
+{
+ server->sysdeps.uptime = _glibtop_sysdeps_uptime;
+}
+
/* Provides uptime and idle time. */
void
@@ -36,7 +44,7 @@ glibtop_get_uptime_s (glibtop *server, glibtop_uptime *buf)
struct tbl_sysinfo sysinfo;
int ret;
- glibtop_init_s (&server, 0, 0);
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_UPTIME, 0);
memset (buf, 0, sizeof (glibtop_uptime));