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.
This commit is contained in:
Martin Baulig
1998-06-02 16:20:15 +00:00
parent 6f179a3141
commit 7f39d62371
6 changed files with 120 additions and 81 deletions

View File

@@ -188,6 +188,7 @@ sysdeps/osf1/Makefile
sysdeps/linux/Makefile
src/Makefile
src/server/Makefile
src/proxy/Makefile
lib/Makefile
examples/Makefile
support/Makefile

View File

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

View File

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

View File

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

View File

@@ -21,6 +21,8 @@
#include <glibtop.h>
#include <glibtop/open.h>
#include <glibtop/sysdeps.h>
#include <glibtop/command.h>
#include <glibtop/xmalloc.h>
/* Opens pipe to gtop server. Returns 0 on success and -1 on error. */
@@ -32,11 +34,16 @@ 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;
/* Is the user allowed to override the server ? */
if ((flags & GLIBTOP_OPEN_NO_OVERRIDE) == 0) {
/* Try to get data from environment. */
temp = getenv ("LIBGTOP_SERVER") ?
@@ -71,7 +78,6 @@ glibtop_open (glibtop *server, const char *program_name,
} else {
server_user = NULL;
}
} else {
server_host = NULL;
server_user = NULL;
@@ -83,23 +89,28 @@ glibtop_open (glibtop *server, const char *program_name,
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"));
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);
}

View File

@@ -21,15 +21,25 @@
#include <glibtop/union.h>
#include <glibtop/sysdeps.h>
#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. */