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.
This commit is contained in:
Martin Baulig
1998-08-07 12:59:00 +00:00
committed by Martin Baulig
parent 3b4e0378f9
commit a510ed1271
35 changed files with 473 additions and 65 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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' \

View File

@@ -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

View File

@@ -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;

View File

@@ -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

View File

@@ -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);

View File

@@ -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@"

View File

@@ -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

View File

@@ -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

View File

@@ -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");
}
}
}

View File

@@ -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

88
src/daemon/server.c Normal file
View File

@@ -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);
}

View File

@@ -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 "

View File

@@ -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.h>
#include <glibtop/error.h>
#include <glibtop/version.h>
#include <glibtop/global.h>
void
glibtop_send_version (glibtop *server, int fd)
{
char buffer [BUFSIZ];
size_t size;
__BEGIN_DECLS
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;
extern void glibtop_output __P((size_t, const void *));
fprintf (stderr, "SERVER ID: |%s|\n", buffer);
__END_DECLS
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");
}
#endif
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");
}
}

View File

@@ -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

View File

@@ -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

View File

@@ -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
};

View File

@@ -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));

View File

@@ -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));

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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)

View File

@@ -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));
}

View File

@@ -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));

View File

@@ -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));

View File

@@ -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));

View File

@@ -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));

View File

@@ -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));

View File

@@ -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));

View File

@@ -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));

View File

@@ -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

View File

@@ -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

View File

@@ -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));

View File

@@ -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));