From 7f39d62371933fab64a352845379a1ad158d77b8 Mon Sep 17 00:00:00 2001 From: Martin Baulig Date: Tue, 2 Jun 1998 16:20:15 +0000 Subject: [PATCH] tells `glibtop_open' to use the default server and not to check the * include/glibtop/open.h (GLIBTOP_OPEN_NO_OVERRIDE): tells `glibtop_open' to use the default server and not to check the environment variables. * include/glibtop/sysdeps.h (_glibtop_sysdeps): renamed 'dummy' member to 'features'. * include/glibtop/command.h (GLIBTOP_CMND_SYSDEPS): added definition here. --- configure.in | 1 + include/glibtop/command.h | 36 ++++++----- include/glibtop/open.h | 2 +- include/glibtop/sysdeps.h | 4 +- lib/open.c | 130 ++++++++++++++++++++++---------------- sysdeps/common/sysdeps.c | 28 +++++--- 6 files changed, 120 insertions(+), 81 deletions(-) diff --git a/configure.in b/configure.in index 878b7f14..ded551cc 100644 --- a/configure.in +++ b/configure.in @@ -188,6 +188,7 @@ sysdeps/osf1/Makefile sysdeps/linux/Makefile src/Makefile src/server/Makefile +src/proxy/Makefile lib/Makefile examples/Makefile support/Makefile diff --git a/include/glibtop/command.h b/include/glibtop/command.h index daf31227..ce83c618 100644 --- a/include/glibtop/command.h +++ b/include/glibtop/command.h @@ -28,25 +28,27 @@ __BEGIN_DECLS #define GLIBTOP_CMND_QUIT 0 -#define GLIBTOP_CMND_CPU 1 -#define GLIBTOP_CMND_MEM 2 -#define GLIBTOP_CMND_SWAP 3 -#define GLIBTOP_CMND_UPTIME 4 -#define GLIBTOP_CMND_LOADAVG 5 -#define GLIBTOP_CMND_SHM_LIMITS 6 -#define GLIBTOP_CMND_MSG_LIMITS 7 -#define GLIBTOP_CMND_SEM_LIMITS 8 -#define GLIBTOP_CMND_PROCLIST 9 +#define GLIBTOP_CMND_SYSDEPS 1 -#define GLIBTOP_CMND_PROC_STATE 10 -#define GLIBTOP_CMND_PROC_UID 11 -#define GLIBTOP_CMND_PROC_MEM 12 -#define GLIBTOP_CMND_PROC_TIME 13 -#define GLIBTOP_CMND_PROC_SIGNAL 14 -#define GLIBTOP_CMND_PROC_KERNEL 15 -#define GLIBTOP_CMND_PROC_SEGMENT 16 +#define GLIBTOP_CMND_CPU 2 +#define GLIBTOP_CMND_MEM 3 +#define GLIBTOP_CMND_SWAP 4 +#define GLIBTOP_CMND_UPTIME 5 +#define GLIBTOP_CMND_LOADAVG 6 +#define GLIBTOP_CMND_SHM_LIMITS 7 +#define GLIBTOP_CMND_MSG_LIMITS 8 +#define GLIBTOP_CMND_SEM_LIMITS 9 +#define GLIBTOP_CMND_PROCLIST 10 -#define GLIBTOP_MAX_CMND 17 +#define GLIBTOP_CMND_PROC_STATE 11 +#define GLIBTOP_CMND_PROC_UID 12 +#define GLIBTOP_CMND_PROC_MEM 13 +#define GLIBTOP_CMND_PROC_TIME 14 +#define GLIBTOP_CMND_PROC_SIGNAL 15 +#define GLIBTOP_CMND_PROC_KERNEL 16 +#define GLIBTOP_CMND_PROC_SEGMENT 17 + +#define GLIBTOP_MAX_CMND 18 typedef struct _glibtop_command glibtop_command; diff --git a/include/glibtop/open.h b/include/glibtop/open.h index 9a1dbe05..83674a55 100644 --- a/include/glibtop/open.h +++ b/include/glibtop/open.h @@ -26,7 +26,7 @@ __BEGIN_DECLS -#define GLIBTOP_OPEN_IMMEDIATE 1 +#define GLIBTOP_OPEN_NO_OVERRIDE 1 extern void glibtop_open __P((glibtop *, const char *, const unsigned long, const unsigned)); diff --git a/include/glibtop/sysdeps.h b/include/glibtop/sysdeps.h index b8dd8f98..8bbcba2b 100644 --- a/include/glibtop/sysdeps.h +++ b/include/glibtop/sysdeps.h @@ -47,12 +47,14 @@ __BEGIN_DECLS #define GLIBTOP_MAX_SYSDEPS 17 +#define GLIBTOP_SYSDEPS_ALL ((1 << GLIBTOP_MAX_SYSDEPS) - 1) + typedef struct _glibtop_sysdeps glibtop_sysdeps; struct _glibtop_sysdeps { unsigned long flags, - dummy, /* dummy field */ + features, /* server features */ cpu, /* glibtop_cpu */ mem, /* glibtop_mem */ swap, /* glibtop_swap */ diff --git a/lib/open.c b/lib/open.c index 7dbe3131..0bc6f9fd 100644 --- a/lib/open.c +++ b/lib/open.c @@ -21,6 +21,8 @@ #include #include +#include +#include #include /* Opens pipe to gtop server. Returns 0 on success and -1 on error. */ @@ -32,74 +34,83 @@ glibtop_open (glibtop *server, const char *program_name, char version [BUFSIZ], buffer [BUFSIZ]; char *server_command, *server_rsh, *temp; char *server_host, *server_user; + glibtop_sysdeps sysdeps; memset (server, 0, sizeof (glibtop)); server->name = program_name; - /* Try to get data from environment. */ + /* Is the user allowed to override the server ? */ - temp = getenv ("LIBGTOP_SERVER") ? - getenv ("LIBGTOP_SERVER") : GTOP_SERVER; + if ((flags & GLIBTOP_OPEN_NO_OVERRIDE) == 0) { - server_command = glibtop_malloc__r (server, strlen (temp) + 1); - - strcpy (server_command, temp); - - temp = getenv ("LIBGTOP_RSH") ? - getenv ("LIBGTOP_RSH") : "rsh"; - - server_rsh = glibtop_malloc__r (server, strlen (temp) + 1); - - strcpy (server_rsh, temp); - - /* Extract host and user information. */ - - temp = strstr (server_command, ":"); - - if (temp) { - *temp = 0; - server_host = server_command; - server_command = temp+1; - - temp = strstr (server_host, "@"); - - if (temp) { - *temp = 0; - server_user = server_host; - server_host = temp+1; - } else { - server_user = NULL; - } - - } else { - server_host = NULL; - server_user = NULL; + /* Try to get data from environment. */ + + temp = getenv ("LIBGTOP_SERVER") ? + getenv ("LIBGTOP_SERVER") : GTOP_SERVER; + + server_command = glibtop_malloc__r (server, strlen (temp) + 1); + + strcpy (server_command, temp); + + temp = getenv ("LIBGTOP_RSH") ? + getenv ("LIBGTOP_RSH") : "rsh"; + + server_rsh = glibtop_malloc__r (server, strlen (temp) + 1); + + strcpy (server_rsh, temp); + + /* Extract host and user information. */ + + temp = strstr (server_command, ":"); + + if (temp) { + *temp = 0; + server_host = server_command; + server_command = temp+1; + + temp = strstr (server_host, "@"); + + if (temp) { + *temp = 0; + server_user = server_host; + server_host = temp+1; + } else { + server_user = NULL; + } + } else { + server_host = NULL; + server_user = NULL; + } + + /* Store everything in `server'. */ + + server->server_command = server_command; + server->server_host = server_host; + server->server_user = server_user; + server->server_rsh = server_rsh; } - - /* Store everything in `server'. */ - - server->server_command = server_command; - server->server_host = server_host; - server->server_user = server_user; - server->server_rsh = server_rsh; - + /* Get server features. */ - - if (server->server_host) - glibtop_error__r (server, _("Remote server not yet supported by library\n")); - - server->features = glibtop_server_features; + + if (server->server_host == NULL) { + server->features = glibtop_server_features; + + if (server->features == 0) + return; + } /* Fork and exec server. */ if (pipe (server->input) || pipe (server->output)) - glibtop_error__r (server, _("cannot make a pipe: %s\n"), strerror (errno)); + glibtop_error__r (server, _("cannot make a pipe: %s\n"), + strerror (errno)); server->pid = fork (); if (server->pid < 0) { - glibtop_error__r (server, _("%s: fork failed: %s\n"), strerror (errno)); + glibtop_error__r (server, _("%s: fork failed: %s\n"), + strerror (errno)); } else if (server->pid == 0) { close (0); close (1); /* close (2); */ close (server->input [0]); close (server->output [1]); @@ -108,20 +119,22 @@ glibtop_open (glibtop *server, const char *program_name, if (server_host) { if (server_user) { - execl (server->server_rsh, "gtop_server", "-l", + execl (server->server_rsh, "-l", server->server_user, server->server_host, server->server_command, NULL); } else { - execl (server->server_rsh, "gtop_server", + execl (server->server_rsh, server->server_host, server_command, NULL); } } else { - execl (server->server_command, "gtop_server", NULL); + execl (server->server_command, NULL); } _exit (2); } + fprintf (stderr, "PID: %d\n", server->pid); + close (server->input [1]); close (server->output [0]); @@ -131,4 +144,13 @@ glibtop_open (glibtop *server, const char *program_name, if (memcmp (version, buffer, strlen (version))) glibtop_error__r (server, _("server version is not %s"), VERSION); + + fprintf (stderr, "Calling GLITOP_CMND_SYSDEPS ...\n"); + + glibtop_call__l (server, GLIBTOP_CMND_SYSDEPS, 0, NULL, + sizeof (glibtop_sysdeps), &sysdeps); + + server->features = sysdeps.features; + + fprintf (stderr, "Features: %lu\n", server->features); } diff --git a/sysdeps/common/sysdeps.c b/sysdeps/common/sysdeps.c index cbb961ab..883097e5 100644 --- a/sysdeps/common/sysdeps.c +++ b/sysdeps/common/sysdeps.c @@ -21,15 +21,25 @@ #include #include +#define BIT_MASK(feature) (feature ? (1 << feature) : feature) + const unsigned long glibtop_server_features = -(1 << GLIBTOP_SUID_CPU) + (1 << GLIBTOP_SUID_MEM) + -(1 << GLIBTOP_SUID_SWAP) + (1 << GLIBTOP_SUID_UPTIME) + -(1 << GLIBTOP_SUID_LOADAVG) + (1 << GLIBTOP_SUID_SHM_LIMITS) + -(1 << GLIBTOP_SUID_MSG_LIMITS) + (1 << GLIBTOP_SUID_SEM_LIMITS) + -(1 << GLIBTOP_SUID_PROCLIST) + (1 << GLIBTOP_SUID_PROC_STATE) + -(1 << GLIBTOP_SUID_PROC_UID) + (1 << GLIBTOP_SUID_PROC_MEM) + -(1 << GLIBTOP_SUID_PROC_TIME) + (1 << GLIBTOP_SUID_PROC_SIGNAL) + -(1 << GLIBTOP_SUID_PROC_KERNEL) + (1 << GLIBTOP_SUID_PROC_SEGMENT); +BIT_MASK(GLIBTOP_SUID_CPU) + +BIT_MASK(GLIBTOP_SUID_MEM) + +BIT_MASK(GLIBTOP_SUID_SWAP) + +BIT_MASK(GLIBTOP_SUID_UPTIME) + +BIT_MASK(GLIBTOP_SUID_LOADAVG) + +BIT_MASK(GLIBTOP_SUID_SHM_LIMITS) + +BIT_MASK(GLIBTOP_SUID_MSG_LIMITS) + +BIT_MASK(GLIBTOP_SUID_SEM_LIMITS) + +BIT_MASK(GLIBTOP_SUID_PROCLIST) + +BIT_MASK(GLIBTOP_SUID_PROC_STATE) + +BIT_MASK(GLIBTOP_SUID_PROC_UID) + +BIT_MASK(GLIBTOP_SUID_PROC_MEM) + +BIT_MASK(GLIBTOP_SUID_PROC_TIME) + +BIT_MASK(GLIBTOP_SUID_PROC_SIGNAL) + +BIT_MASK(GLIBTOP_SUID_PROC_KERNEL) + +BIT_MASK(GLIBTOP_SUID_PROC_SEGMENT); /* Checks which features are implemented. */ @@ -40,6 +50,8 @@ glibtop_get_sysdeps__r (glibtop *server, glibtop_sysdeps *buf) memset (buf, 0, sizeof (glibtop_sysdeps)); + buf->features = glibtop_server_features; + /* Call all system dependent functions to check which values * they return. */