libgtop-GNOME-2-0-branch moved to HEAD.

2003-10-19  Carlos Perelló Marín <carlos@gnome.org>

	* libgtop-GNOME-2-0-branch moved to HEAD.
This commit is contained in:
Carlos Perelló Marín
2003-10-19 16:10:39 +00:00
committed by Carlos Perelló Marín
parent 5e28a55218
commit bae16b467f
148 changed files with 29273 additions and 26459 deletions

View File

@@ -5,7 +5,3 @@ Makefile.in
libgtop.la
*.lo
lib.c
structures.h
sysdeps-init.c
libgtop_server.la
test-backends

View File

@@ -1,55 +1,23 @@
LINK = $(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -o $@
if INODEDB
inodedb_SRCLIST = inodedb.c
inodedb_DEFS = -DSYSTEM_INODEDB=\"$(prefix)/var/libgtop/inodedb.db\"
else
inodedb_SRCLIST =
inodedb_DEFS =
endif
INCLUDES = @INCLUDES@
INCLUDES = @INCLUDES@ $(inodedb_DEFS)
lib_LTLIBRARIES = libgtop-2.0.la
noinst_PROGRAMS = test-backends
libgtop_2_0_la_SOURCES = init.c open.c close.c command.c read.c \
read_data.c write.c lib.c parameter.c \
sysdeps.c
lib_LTLIBRARIES = libgtop.la
libgtop_2_0_la_LDFLAGS = $(LT_VERSION_INFO)
libgtop_2_0_la_LIBADD = $(top_builddir)/sysdeps/common/libgtop_common-2.0.la $(top_builddir)/sysdeps/@sysdeps_dir@/libgtop_sysdeps-2.0.la $(sysdeps_suid_lib) $(INTLLIBS)
noinst_LTLIBRARIES = libgtop_server.la
BUILT_SOURCES = lib.c
libgtop_la_SOURCES = errors.c glibtop-backend-info.c \
glibtop-client.c glibtop-server.c \
glibtop-backend.c glibtop-client-private.h \
glibtop-server-private.h xmalloc.c error.c \
$(inodedb_SRCLIST) $(BUILT_SOURCES)
libgtop_server_la_SOURCES = error.c xmalloc.c
libgtop_la_LDFLAGS = $(LT_VERSION_INFO)
libgtop_la_LIBADD = $(GLIB_LIBS) $(XML_LIBS)
test_backends_SOURCES = \
test-backends.c
test_backends_LDADD = libgtop.la
glibtopdir = $(includedir)/glibtop
glibtop_HEADERS = structures.h
BUILT_SOURCES = lib.c structures.h
lib.c: lib.pl $(top_builddir)/config.h $(top_srcdir)/features.def $(top_srcdir)/scripts/c_types.pl
$(PERL) -I $(top_srcdir)/scripts $(srcdir)/lib.pl < $(top_srcdir)/features.def > lib-t
lib.c: lib.pl $(top_builddir)/config.h $(top_srcdir)/features.def
$(PERL) $(srcdir)/lib.pl < $(top_srcdir)/features.def > lib-t
mv lib-t lib.c
structures.h: structures.pl $(top_builddir)/config.h \
$(top_srcdir)/features.def $(top_srcdir)/structures.def
$(PERL) -I $(top_srcdir)/scripts $(srcdir)/structures.pl \
$(top_srcdir)/features.def $(top_srcdir)/structures.def \
structures.h > tmp-s
mv tmp-s structures.h
EXTRA_DIST = lib.pl
CLEANFILES = $(BUILT_SOURCES)
EXTRA_DIST = lib.pl structures.pl
CLEANFILES = lib.c

View File

@@ -1,5 +1,3 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
@@ -26,38 +24,27 @@
#include <glibtop.h>
#include <glibtop/open.h>
#include <glibtop/close.h>
#include <glibtop/backend.h>
#include <glibtop/command.h>
/* Closes server. */
static void
close_backend (gpointer value, gpointer user_data)
{
glibtop_backend *backend = (glibtop_backend *) value;
glibtop *server = (glibtop *) user_data;
/* should not happen ... */
if (!backend || !backend->_priv_module)
return;
if (backend->info && backend->info->close)
backend->info->close (server, backend);
/* Note that two or more servers may open the same backend. */
backend->_priv_module->refcount--;
if (!backend->_priv_module->refcount) {
g_module_close (backend->_priv_module->module);
g_free (backend->_priv_module);
}
g_free (backend);
}
void
glibtop_close_r (glibtop *server)
{
g_slist_foreach (server->_priv->backend_list, close_backend, server);
g_slist_free (server->_priv->backend_list);
server->_priv->backend_list = NULL;
switch (server->method) {
case GLIBTOP_METHOD_UNIX:
case GLIBTOP_METHOD_INET:
glibtop_call_l (server, GLIBTOP_CMND_QUIT,
0, NULL, 0, NULL);
if (close (server->socket))
glibtop_warn_io ("close");
break;
case GLIBTOP_METHOD_PIPE:
kill (server->pid, SIGKILL);
close (server->input [0]);
close (server->output [1]);
break;
}
}

View File

@@ -1,5 +1,3 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
@@ -28,20 +26,226 @@
#include <glibtop/sysdeps.h>
#include <glibtop/parameter.h>
void
glibtop_init_s (glibtop_server *server, unsigned long features, unsigned flags)
#ifndef DEFAULT_PORT
#define DEFAULT_PORT 42800
#endif
static glibtop _glibtop_global_server;
glibtop *glibtop_global_server = &_glibtop_global_server;
static void
_init_server (glibtop *server, const unsigned features)
{
/* Should we do the initialization? */
char *command, *temp;
if (flags & GLIBTOP_INIT_NO_INIT)
return server;
/* Try to get server command, but don't override if already
* set via glibtop_set_parameter () */
if ((server->flags & _GLIBTOP_INIT_STATE_SYSDEPS) == 0) {
server->info->sysdeps.pointer_size = sizeof (void*)*8;
if (server->server_command == NULL) {
const char *temp = getenv ("LIBGTOP_SERVER") ?
getenv ("LIBGTOP_SERVER") : LIBGTOP_SERVER;
server->server_command = glibtop_strdup_r (server, temp);
}
if (server->server_rsh == NULL) {
const char *temp = getenv ("LIBGTOP_RSH") ?
getenv ("LIBGTOP_RSH") : "/usr/bin/ssh";
server->flags |= _GLIBTOP_INIT_STATE_SYSDEPS;
}
server->server_rsh = glibtop_strdup_r (server, temp);
}
return server;
/* Try to get server method, but don't override if already
* set via glibtop_set_parameter () */
if (server->method) return;
/* If server->command doesn't start with a colon, then it is
* the full pathname of the server executable. */
if (server->server_command [0] != ':') {
if (features & glibtop_server_features) {
/* We really need the server. */
server->method = GLIBTOP_METHOD_PIPE;
} else {
/* Fine. No server is needed, so we call the
* sysdeps functions directly. */
server->method = GLIBTOP_METHOD_DIRECT;
}
return;
}
/* If the first character of 'server_command' is a colon,
* the first field is the method to connect to the server. */
/* Everything up to the next colon is the method. */
command = glibtop_strdup_r (server, server->server_command+1);
temp = strstr (command, ":");
if (temp) *temp = 0;
/* Dispatch method. */
if (!strcmp (command, "direct")) {
/* Use sysdeps dir instead of connecting to server
* even if using the server would be required on
* the current system. */
server->method = GLIBTOP_METHOD_DIRECT;
} else if (!strcmp (command, "inet")) {
server->method = GLIBTOP_METHOD_INET;
/* Connect to internet server. */
if (temp == NULL) {
/* If no value was set, we use 'localhost'. */
if (server->server_host == NULL)
server->server_host = glibtop_strdup_r
(server, "localhost");
} else {
char *temp2 = strstr (temp+1, ":");
if (temp2) *temp2 = 0;
/* Override default. */
if (server->server_host)
glibtop_free_r (server,
(char *) server->server_host);
server->server_host = glibtop_strdup_r
(server, temp+1);
temp = temp2;
}
if (temp == NULL) {
/* If no value was set, we use DEFAULT_PORT. */
if (server->server_port == 0)
server->server_port = DEFAULT_PORT;
} else {
char *temp2 = strstr (temp+1, ":");
if (temp2) *temp2 = 0;
if (sscanf (temp+1, "%ld", &server->server_port) != 1)
server->server_port = DEFAULT_PORT;
temp = temp2 ? temp2 + 1 : temp2;
}
} else if (!strcmp (command, "unix")) {
/* Connect to unix domain socket. */
server->method = GLIBTOP_METHOD_UNIX;
} else if (!strcmp (command, "pipe")) {
/* Open pipe to server. */
server->method = GLIBTOP_METHOD_PIPE;
} else {
glibtop_error_r (server, "Unknown server method '%s'",
server->server_command+1);
}
glibtop_free_r (server, command);
}
glibtop *
glibtop_init_r (glibtop **server_ptr, unsigned long features, unsigned flags)
{
glibtop *server;
if (server_ptr == NULL)
return NULL;
if (*server_ptr == NULL)
*server_ptr = glibtop_global_server;
server = *server_ptr;
/* Should we do the initialization? */
if (flags & GLIBTOP_INIT_NO_INIT)
return server;
/* Do the initialization, but only if not already initialized. */
if ((server->flags & _GLIBTOP_INIT_STATE_INIT) == 0) {
if (flags & GLIBTOP_FEATURES_EXCEPT)
features = ~features & GLIBTOP_SYSDEPS_ALL;
if (features == 0)
features = GLIBTOP_SYSDEPS_ALL;
if (flags & GLIBTOP_FEATURES_NO_SERVER) {
server->method = GLIBTOP_METHOD_DIRECT;
features = 0;
}
server->features = features;
_init_server (server, features);
server->flags |= _GLIBTOP_INIT_STATE_INIT;
switch (server->method) {
case GLIBTOP_METHOD_PIPE:
case GLIBTOP_METHOD_UNIX:
if (glibtop_server_features & features)
break;
server->method = GLIBTOP_METHOD_DIRECT;
break;
}
}
/* Should we open the server? */
if (flags & GLIBTOP_INIT_NO_OPEN)
return server;
/* Open server, but only if not already opened. */
if ((server->flags & _GLIBTOP_INIT_STATE_OPEN) == 0)
glibtop_open_l (glibtop_global_server, "glibtop",
features, flags);
return server;
}
glibtop *
glibtop_init_s (glibtop **server_ptr, unsigned long features, unsigned flags)
{
glibtop *server;
glibtop_init_func_t *init_fkt;
if (server_ptr == NULL)
return NULL;
if (*server_ptr == NULL)
*server_ptr = glibtop_global_server;
server = *server_ptr;
/* Should we do the initialization? */
if (flags & GLIBTOP_INIT_NO_INIT)
return server;
/* Do the initialization, but only if not already initialized. */
if ((server->flags & _GLIBTOP_INIT_STATE_SYSDEPS) == 0) {
glibtop_open_s (server, "glibtop", features, flags);
for (init_fkt = _glibtop_init_hook_s; *init_fkt; init_fkt++)
(*init_fkt) (server);
server->flags |= _GLIBTOP_INIT_STATE_SYSDEPS;
}
return server;
}

View File

@@ -1,5 +1,3 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
@@ -39,44 +37,44 @@ glibtop_inodedb *
glibtop_inodedb_open_s (glibtop *server, unsigned databases,
unsigned long cachesize)
{
glibtop_inodedb *inodedb;
char filename [BUFSIZ];
struct passwd *pwd;
struct stat statb;
glibtop_inodedb *inodedb;
char filename [BUFSIZ];
struct passwd *pwd;
struct stat statb;
if (!databases)
databases = GLIBTOP_INODEDB_ALL;
if (!databases)
databases = GLIBTOP_INODEDB_ALL;
inodedb = glibtop_calloc_r (server, 1, sizeof (glibtop_inodedb));
inodedb = glibtop_calloc_r (server, 1, sizeof (glibtop_inodedb));
if (stat (SYSTEM_INODEDB, &statb))
databases &= ~GLIBTOP_INODEDB_SYSTEM;
if (stat (SYSTEM_INODEDB, &statb))
databases &= ~GLIBTOP_INODEDB_SYSTEM;
if (databases & GLIBTOP_INODEDB_SYSTEM) {
inodedb->system_dbf = gdbm_open
(SYSTEM_INODEDB, 0, GDBM_READER, 0, 0);
if (!inodedb->system_dbf)
glibtop_error_io_r
(server, "gdbm_open (%s)", SYSTEM_INODEDB);
}
if (databases & GLIBTOP_INODEDB_SYSTEM) {
inodedb->system_dbf = gdbm_open
(SYSTEM_INODEDB, 0, GDBM_READER, 0, 0);
if (!inodedb->system_dbf)
glibtop_error_io_r
(server, "gdbm_open (%s)", SYSTEM_INODEDB);
}
pwd = getpwuid (getuid ());
if (!pwd) glibtop_error_io_r (server, "getpwuid");
pwd = getpwuid (getuid ());
if (!pwd) glibtop_error_io_r (server, "getpwuid");
sprintf (filename, "%s/var/libgtop/inodedb.db", pwd->pw_dir);
sprintf (filename, "%s/var/libgtop/inodedb.db", pwd->pw_dir);
if (stat (filename, &statb))
databases &= ~GLIBTOP_INODEDB_USER;
if (stat (filename, &statb))
databases &= ~GLIBTOP_INODEDB_USER;
if (databases & GLIBTOP_INODEDB_USER) {
inodedb->user_dbf = gdbm_open
(filename, 0, GDBM_READER, 0, 0);
if (!inodedb->user_dbf)
glibtop_error_io_r
(server, "gdbm_open (%s)", filename);
}
if (databases & GLIBTOP_INODEDB_USER) {
inodedb->user_dbf = gdbm_open
(filename, 0, GDBM_READER, 0, 0);
if (!inodedb->user_dbf)
glibtop_error_io_r
(server, "gdbm_open (%s)", filename);
}
return inodedb;
return inodedb;
}
const char *
@@ -84,36 +82,36 @@ glibtop_inodedb_lookup_s (glibtop *server,
glibtop_inodedb *inodedb,
u_int64_t device, u_int64_t inode)
{
glibtop_inodedb_key key;
datum d_key, d_content;
glibtop_inodedb_key key;
datum d_key, d_content;
d_key.dptr = (void *) &key;
d_key.dsize = sizeof (key);
d_key.dptr = (void *) &key;
d_key.dsize = sizeof (key);
key.device = device;
key.inode = inode;
key.device = device;
key.inode = inode;
if (inodedb->system_dbf) {
d_content = gdbm_fetch (inodedb->system_dbf, d_key);
if (d_content.dptr) return d_content.dptr;
}
if (inodedb->system_dbf) {
d_content = gdbm_fetch (inodedb->system_dbf, d_key);
if (d_content.dptr) return d_content.dptr;
}
if (inodedb->user_dbf) {
d_content = gdbm_fetch (inodedb->user_dbf, d_key);
if (d_content.dptr) return d_content.dptr;
}
if (inodedb->user_dbf) {
d_content = gdbm_fetch (inodedb->user_dbf, d_key);
if (d_content.dptr) return d_content.dptr;
}
return NULL;
return NULL;
}
void
glibtop_inodedb_close_s (glibtop *server, glibtop_inodedb *inodedb)
{
if (inodedb->system_dbf)
gdbm_close (inodedb->system_dbf);
if (inodedb->system_dbf)
gdbm_close (inodedb->system_dbf);
if (inodedb->user_dbf)
gdbm_close (inodedb->user_dbf);
if (inodedb->user_dbf)
gdbm_close (inodedb->user_dbf);
glibtop_free_r (server, inodedb);
glibtop_free_r (server, inodedb);
}

View File

@@ -1,13 +1,9 @@
#!/usr/bin/perl
require 'c_types.pl';
$[ = 1; # set array base to 1
$, = ' '; # set output field separator
$\ = "\n"; # set output record separator
$always_use_temp_storage = 1;
sub toupper {
local($_) = @_;
tr/a-z/A-Z/;
@@ -26,58 +22,55 @@ print '';
print '#include <glibtop.h>';
print '#include <glibtop/open.h>';
print '#include <glibtop/xmalloc.h>';
print '';
print '#include <glibtop/sysdeps.h>';
print '#include <glibtop/union.h>';
print '';
print '#include <glibtop/glibtop-client.h>';
print '';
print '#include <glibtop/call-vector.h>';
print '#include <glibtop-client-private.h>';
print '#include <glibtop/command.h>';
print '';
print '/* Some required fields are missing. */';
print '';
print '#if 0';
print '';
print 'static void';
print '_glibtop_missing_feature (glibtop_client *client, const char *feature,';
print '_glibtop_missing_feature (glibtop *server, const char *feature,';
print "\t\t\t const u_int64_t present, u_int64_t *required)";
print '{';
print "\tu_int64_t old_required = *required;\n";
print "\t/* Return if we have all required fields. */";
print "\tif ((~present & old_required) == 0)";
print "\t\treturn;\n";
print "\tswitch (client->_param.error_method) {";
print "\tswitch (server->error_method) {";
print "\tcase GLIBTOP_ERROR_METHOD_WARN_ONCE:";
print "\t\t*required &= present;";
print "\tcase GLIBTOP_ERROR_METHOD_WARN:";
print "\t\tglibtop_warn_r (client,";
print "\t\t\t\t\"glibtop_get_%s (): Client requested \"";
print "\t\t\t\t\"field mask %05lx, but only have %05lx.\",";
print "\t\tglibtop_warn_r (server,";
print "\t\t\t\t_(\"glibtop_get_%s (): Client requested \"";
print "\t\t\t\t \"field mask %05lx, but only have %05lx.\"),";
print "\t\t\t\t feature, (unsigned long) old_required,";
print "\t\t\t\t (unsigned long) present);";
print "\t\tbreak;";
print "\tcase GLIBTOP_ERROR_METHOD_ABORT:";
print "\t\tglibtop_error_r (client,";
print "\t\t\t\t\"glibtop_get_%s (): Client requested \"";
print "\t\t\t\t\"field mask %05lx, but only have %05lx.\",";
print "\t\tglibtop_error_r (server,";
print "\t\t\t\t _(\"glibtop_get_%s (): Client requested \"";
print "\t\t\t\t \"field mask %05lx, but only have %05lx.\"),";
print "\t\t\t\t feature, (unsigned long) old_required,";
print "\t\t\t\t (unsigned long) present);";
print "\t\tbreak;";
print "\t}";
print '}';
print '';
print '#endif';
print '';
print '/* Library functions. */';
print '';
$convert{'long'} = 'int64_t';
$convert{'ulong'} = 'u_int64_t';
$convert{'pid_t'} = 'pid_t';
$convert{'int'} = 'int';
$convert{'ushort'} = 'unsigned short';
$convert{'unsigned'} = 'unsigned';
while (<>) {
chop; # strip record separator
@@ -98,174 +91,143 @@ sub output {
$space = $feature;
$space =~ s/./ /g;
if ($retval eq 'retval') {
$retval_param = '&retval';
$call_prefix = '';
$call_prefix_space = '';
$prefix = 'retval = ';
$prefix_space = ' ';
$retval = 'int';
}
elsif ($retval !~ /^void$/) {
$retval_param = 'NULL';
$prefix = 'retval = ';
$prefix_space = ' ';
$call_prefix = 'retval = ';
$call_prefix_space = ' ';
print $retval;
if ($retval !~ /^void$/) {
$prefix = 'retval = ';
$prefix_space = ' ';
}
else {
$retval_param = 'NULL';
$call_prefix = '';
$call_prefix_space = '';
$prefix = '';
$prefix_space = '';
$prefix = '';
$prefix_space = '';
}
if ($retval =~ /^(array|pointer)\((.*)\)$/) {
$retval = ($2 eq 'string') ? 'char **' : "$2 *";
if ($param_def eq 'string') {
$call_param = ', ' . $line_fields[5];
$param_decl = ",\n " . $space . ' const char *' .
$line_fields[5];
$send_ptr = "\n\tconst void *send_ptr = " . $line_fields[5] . ';';
$send_size = "\n\tconst size_t send_size =\n\t\tstrlen (" .
$line_fields[5] . ') + 1;';
}
else {
$call_param = '';
$param_decl = '';
$send_size = '';
$send_ptr = '';
$nr_params = (@params = split(/:/, $param_def, 9999));
for ($param = 1; $param <= $nr_params; $param++) {
$list = $params[$param];
$type = $params[$param];
$type =~ s/\(.*//;
$list =~ s/^.*\(//;
$list =~ s/\)$//;
$count = (@fields = split(/,/, $list, 9999));
for ($field = 1; $field <= $count; $field++) {
if ($param_decl eq '') {
$param_decl = ",\n " . $space . ' ';
}
else {
$param_decl = $param_decl . ', ';
}
$param_decl = $param_decl . '' . $convert{$type} . ' ' .
$first_param_name = '';
$fields[$field];
$call_param = $call_param . ', ' . $fields[$field];
if ($send_ptr eq '') {
$send_ptr = "\n\tconst void *send_ptr = &" .
$call_param = '';
$param_decl = '';
$need_temp_len = 0;
$nr_params = (@params = split(/:/, $param_def, 9999));
for ($param = 1; $param <= $nr_params; $param++) {
$list = $params[$param];
$type = $params[$param];
$type =~ s/\(.*//;
$list =~ s/^.*\(//;
$list =~ s/\)$//;
$count = (@fields = split(/,/, $list, 9999));
for ($field = 1; $field <= $count; $field++) {
my $c_type = $typeinfo->{$type}->[1];
if ($first_param_name eq '') {
$first_param_name = $fields[$field];
$fields[$field] . ';';
}
if ($send_size eq '') {
$send_size = "\n\tconst size_t send_size =\n\t\t";
}
else {
$send_size = $send_size . ' + ';
}
$send_size = $send_size . 'sizeof (' . $fields[$field] . ')';
}
}
if ($typeinfo->{$type}->[2]) {
$need_temp_storage = 1;
}
if ($param_decl eq '') {
$param_decl = ",\n " . $space . ' ';
if ($send_size ne '') {
$send_size = $send_size . ';';
}
else {
$param_decl = $param_decl . ', ';
$send_size = "\n\tconst size_t send_size = 0;";
}
if ($send_ptr eq '') {
$send_ptr = "\n\tconst void *send_ptr = NULL;";
}
$param_decl = $param_decl . $c_type . ' ' . $fields[$field];
$call_param = $call_param . ', ' . $fields[$field];
}
}
$local_var_code = "\tGSList *list;\n\tint done = 0;\n\tGError *error = NULL;\n\n";
print 'glibtop_get_' . $feature . '_l (glibtop *server, glibtop_' .
$feature . ' *buf' . $param_decl . ')';
print '{' . $send_ptr . '' . $send_size;
if ($retval !~ /^void$/) {
$local_var_code .= sprintf ("\t%s retval = (%s) 0;\n",
$retval, $retval);
print "\t" . $retval . ' retval = (' . $retval . ') 0;';
}
print '';
print "\tglibtop_init_r (&server, (1 << GLIBTOP_SYSDEPS_" .
&toupper($feature) . '), 0);';
print '';
print "\t/* If neccessary, we ask the server for the requested";
print "\t * feature. If not, we call the sysdeps function. */";
print '';
print "\tif ((server->flags & _GLIBTOP_INIT_STATE_SERVER) &&";
print "\t (server->features & (1 << GLIBTOP_SYSDEPS_" .
&toupper($feature) . ')))';
print "\t{";
print "\t\t" . $prefix . 'glibtop_call_l (server, GLIBTOP_CMND_' .
&toupper($feature) . ',';
print "\t\t\t\t" . $prefix_space . 'send_size, send_ptr,';
print "\t\t\t\t" . $prefix_space . 'sizeof (glibtop_' . $feature .
'), buf);';
print "\t} else {";
if ($orig !~ /^@/) {
print '#if (!GLIBTOP_SUID_' . &toupper($feature) . ')';
}
print "\t\t" . $prefix . 'glibtop_get_' . $feature . '_s (server, buf' .
$call_param . ');';
if ($orig !~ /^@/) {
print '#else';
print "\t\terrno = ENOSYS;";
print "\t\tglibtop_error_io_r (server, \"glibtop_get_" . $feature .
"\");";
print '#endif';
}
$sysdeps_code = sprintf
("\tif (client->_priv->backend_list == NULL) {\n\t\tg_set_error (&error, GLIBTOP_ERROR, GLIBTOP_ERROR_NO_BACKEND_OPENED, G_STRLOC);\n\t\tglibtop_client_propagate_error (client, error);\n");
if ($line_fields[1] eq 'retval') {
$sysdeps_code .= sprintf
("\t\treturn -GLIBTOP_ERROR_NO_BACKEND_OPENED;\n");
} else {
$sysdeps_code .= sprintf
("\t\tgoto do_return;\n");
}
$sysdeps_code .= sprintf
("\t}\n\n");
print "\t}";
$sysdeps_code .= sprintf
("\tfor (list = client->_priv->backend_list; list; list = list->next) {\n\t\tglibtop_backend *backend = list->data;\n\t\tglibtop_call_vector *call_vector;\n\n\t\tcall_vector = glibtop_backend_get_call_vector (backend);\n\n\t\tif (call_vector && call_vector->%s) {\n\t\t\tglibtop_server *server = glibtop_backend_get_server (backend);\n\t\t\tvoid *closure = glibtop_backend_get_closure_data (backend);\n\n", $feature);
print '';
print "\t/* Make sure that all required fields are present. */";
print '';
if ($line_fields[3] eq '') {
$sysdeps_code .= sprintf
("\t\t\tretval = call_vector->%s (server, closure%s);\n",
$feature, $call_param);
} elsif ($line_fields[3] eq 'array') {
$sysdeps_code .= sprintf
("\t\t\tretval = call_vector->%s (server, closure, array%s);\n",
$feature, $call_param);
} elsif ($line_fields[3] =~ /^array/) {
$sysdeps_code .= sprintf
("\t\t\tretval = call_vector->%s (server, closure, array, buf%s);\n",
$feature, $call_param);
} else {
$sysdeps_code .= sprintf
("\t\t\tretval = call_vector->%s (server, closure, buf%s);\n",
$feature, $call_param);
}
print "\tif (buf->flags & server->required." . $feature . ')';
print "\t\t_glibtop_missing_feature (server, \"" . $feature .
$sysdeps_code .= sprintf
("\t\t\tdone = 1;\n\t\t\tglibtop_server_unref (server);\n\t\t\t\tbreak;\n\t\t}\n\t}\n");
"\", buf->flags,";
print "\t\t\t\t\t &server->required." . $feature . ');';
$sysdeps_code .= sprintf
("\n\tif (!done) {\n\t\tg_set_error (&error, GLIBTOP_ERROR, GLIBTOP_ERROR_NOT_IMPLEMENTED, G_STRLOC);\n\t\tglibtop_client_propagate_error (client, error);\n");
if ($line_fields[1] eq 'retval') {
$sysdeps_code .= sprintf
("\t\treturn -GLIBTOP_ERROR_NOT_IMPLEMENTED;\n");
} else {
$sysdeps_code .= sprintf
("\t\tgoto do_return;\n");
}
$sysdeps_code .= sprintf
("\t}\n\n");
if ($line_fields[1] eq 'retval') {
$sysdeps_code .= "\tif (retval < 0) {\n";
$sysdeps_code .= "\t\tg_set_error (&error, GLIBTOP_ERROR, -retval, G_STRLOC);\n";
$sysdeps_code .= "\t\tglibtop_client_propagate_error (client, error);\n";
$sysdeps_code .= "\t\tgoto do_return;\n";
$sysdeps_code .= "\t}\n\n";
}
$sysdeps_code .= "\tgoto check_missing;\n";
# $init_code = sprintf ("\tglibtop_init_r (&client, (1 << %s), 0);\n\n",
# "GLIBTOP_SYSDEPS_".&toupper($feature));
$init_code = '';
$total_code = sprintf ("%s%s\n", $init_code, $sysdeps_code);
$check_code = "check_missing:\n";
$check_code .= "\t/* Make sure that all required fields are present. */\n";
if (!(($line_fields[3] eq '') or ($line_fields[3] eq 'array'))) {
# $check_code .= "\tif (buf->flags & client->info->required." . $feature . ")\n";
# $check_code .= "\t\t_glibtop_missing_feature (client, \"" . $feature .
"\", buf->flags,\n\t\t\t\t\t &client->info->required." . $feature . ");\n";
}
$total_code .= $check_code."\tgoto do_return;\n\n";
$return_code = "do_return:\n";
if ($retval !~ /^void$/) {
$return_code .= "\treturn retval;\n";
} else {
$return_code .= "\treturn;\n";
print "\n\t/* Now we can return. */";
print "\n\treturn retval;";
}
$total_code .= $return_code;
$func_decl = $retval."\n";
if ($line_fields[3] eq '') {
$func_decl .= sprintf ("glibtop_get_%s_l (glibtop_client *client%s)\n",
$feature, $param_decl);
} elsif ($line_fields[3] eq 'array') {
$func_decl .= sprintf ("glibtop_get_%s_l (glibtop_client *client, glibtop_array *array%s)\n",
$feature, $param_decl);
} elsif ($line_fields[3] =~ /^array/) {
$func_decl .= sprintf ("glibtop_get_%s_l (glibtop_client *client, glibtop_array *array, %s *buf%s)\n",
$feature, 'glibtop_'.$feature, $param_decl);
} else {
$func_decl .= sprintf ("glibtop_get_%s_l (glibtop_client *client, %s *buf%s)\n",
$feature, 'glibtop_'.$feature, $param_decl);
}
$total_code = sprintf ("%s{\n%s\n%s\n%s}\n", $func_decl,
$local_var_code, $total_code);
print $total_code;
print '}';
print '';
}

View File

@@ -1,5 +1,3 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
@@ -25,20 +23,160 @@
#include <glibtop.h>
#include <glibtop/open.h>
#include <glibtop/backend.h>
#include <glibtop/version.h>
#include <glibtop/sysdeps.h>
#include <glibtop/command.h>
#include <glibtop/xmalloc.h>
#include <glibtop/gnuserv.h>
/* Opens pipe to gtop server. Returns 0 on success and -1 on error. */
void
glibtop_open_l (glibtop *server, const char *program_name,
const unsigned long features, const unsigned flags)
{
if ((server->flags & _GLIBTOP_INIT_STATE_SYSDEPS) == 0) {
glibtop_init_backends ();
int connect_type;
_glibtop_open_sysdeps (server, "glibtop", features, flags);
server->name = program_name;
server->_param.ncpu = server->info->ncpu;
server->_param.os_version_code = server->os_version_code;
/* It is important to set _GLIBTOP_INIT_STATE_OPEN here when we
* do recursive calls to glibtop_init_r (). */
server->flags |= _GLIBTOP_INIT_STATE_SYSDEPS;
}
server->flags |= _GLIBTOP_INIT_STATE_OPEN;
server->error_method = GLIBTOP_ERROR_METHOD_DEFAULT;
#ifdef DEBUG
fprintf (stderr, "SIZEOF: %u - %u - %u - %u - %u - %u\n",
sizeof (glibtop_command), sizeof (glibtop_response),
sizeof (glibtop_mountentry), sizeof (glibtop_union),
sizeof (glibtop_sysdeps), sizeof (glibtop_response_union));
#endif
switch (server->method) {
case GLIBTOP_METHOD_DIRECT:
server->features = 0;
break;
case GLIBTOP_METHOD_INET:
#ifdef DEBUG
fprintf (stderr, "Connecting to '%s' port %ld.\n",
server->server_host, server->server_port);
#endif
connect_type = glibtop_make_connection
(server->server_host, server->server_port,
&server->socket);
#ifdef DEBUG
fprintf (stderr, "Connect Type is %d.\n", connect_type);
#endif
server->flags |= _GLIBTOP_INIT_STATE_SERVER;
server->features = -1;
break;
case GLIBTOP_METHOD_UNIX:
#ifdef DEBUG
fprintf (stderr, "Connecting to Unix Domain Socket.\n");
#endif
connect_type = glibtop_make_connection
("unix", 0, &server->socket);
#ifdef DEBUG
fprintf (stderr, "Connect Type is %d.\n", connect_type);
#endif
server->flags |= _GLIBTOP_INIT_STATE_SERVER;
server->features = -1;
break;
case GLIBTOP_METHOD_PIPE:
#ifdef DEBUG
fprintf (stderr, "Opening pipe to server (%s).\n",
LIBGTOP_SERVER);
#endif
if (pipe (server->input) || pipe (server->output))
glibtop_error_io_r (server, "cannot make a pipe");
server->pid = fork ();
if (server->pid < 0) {
glibtop_error_io_r (server, "fork failed");
} else if (server->pid == 0) {
close (0); close (1);
close (server->input [0]); close (server->output [1]);
dup2 (server->input [1], 1);
dup2 (server->output [0], 0);
execl (LIBGTOP_SERVER, "libgtop-server", NULL);
glibtop_error_io_r (server, "execl (%s)",
LIBGTOP_SERVER);
_exit (2);
}
close (server->input [1]);
close (server->output [0]);
server->flags |= _GLIBTOP_INIT_STATE_SERVER;
server->features = -1;
break;
}
/* 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;
size_t 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);
server->features = sysdeps.features;
memcpy (&server->sysdeps, &sysdeps, sizeof (glibtop_sysdeps));
#ifdef DEBUG
fprintf (stderr, "Server features are %lu.\n",
server->features);
#endif
}
/* In any case, we call the open functions of our own sysdeps
* directory. */
#ifdef DEBUG
fprintf (stderr, "Calling sysdeps open function.\n");
#endif
glibtop_init_s (&server, features, flags);
}

View File

@@ -1,5 +1,3 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
@@ -24,12 +22,10 @@
*/
#include <glibtop.h>
#include <glibtop/xmalloc.h>
#include <glibtop/parameter.h>
#define _write_data(ptr,size) \
if ((data_ptr == NULL) || (data_size < size)) \
return -GLIBTOP_ERROR_SIZE_MISMATCH; \
if ((data_ptr == NULL) || (data_size < size)) return -size; \
if (ptr == NULL) { strcpy (data_ptr, ""); return 1; } \
memcpy (data_ptr, ptr, size); \
return size;
@@ -39,76 +35,64 @@
glibtop_warn_r (server, "glibtop_set_parameter (%d): " \
"Expected %lu bytes but got %lu.", \
parameter, size, data_size); \
return -GLIBTOP_ERROR_SIZE_MISMATCH; \
return; \
}
#define _strlen(ptr) (ptr ? strlen (ptr) : 0)
ssize_t
glibtop_get_parameter_l (glibtop_client *client, const unsigned parameter,
size_t
glibtop_get_parameter_l (glibtop *server, const unsigned parameter,
void *data_ptr, size_t data_size)
{
switch (parameter) {
case GLIBTOP_PARAM_ERROR_METHOD:
_write_data (&server->_param.error_method,
sizeof (server->_param.error_method));
case GLIBTOP_PARAM_FEATURES:
_write_data (&server->_param.features,
sizeof (server->_param.features));
case GLIBTOP_PARAM_NCPU:
_write_data (&server->_param.ncpu,
sizeof (server->_param.ncpu));
case GLIBTOP_PARAM_OS_VERSION_CODE:
_write_data (&server->_param.os_version_code,
sizeof (server->_param.os_version_code));
case GLIBTOP_PARAM_REQUIRED:
_write_data (&server->_param.required,
sizeof (server->_param.required));
}
switch (parameter) {
case GLIBTOP_PARAM_METHOD:
_write_data (&server->method,
sizeof (server->method));
case GLIBTOP_PARAM_FEATURES:
_write_data (&server->features,
sizeof (server->features));
case GLIBTOP_PARAM_COMMAND:
_write_data (server->server_command,
_strlen(server->server_command));
case GLIBTOP_PARAM_HOST:
_write_data (server->server_host,
_strlen(server->server_host));
case GLIBTOP_PARAM_PORT:
_write_data (&server->server_port,
sizeof (server->server_port));
case GLIBTOP_PARAM_ERROR_METHOD:
_write_data (&server->error_method,
sizeof (server->error_method));
case GLIBTOP_PARAM_REQUIRED:
_write_data (&server->required,
sizeof (server->required));
}
return -GLIBTOP_ERROR_NO_SUCH_PARAMETER;
return 0;
}
int
glibtop_get_parameter_size_l (glibtop_client *client, const unsigned parameter)
{
switch (parameter) {
case GLIBTOP_PARAM_ERROR_METHOD:
return sizeof (server->_param.error_method);
case GLIBTOP_PARAM_FEATURES:
return sizeof (server->_param.features);
case GLIBTOP_PARAM_NCPU:
return sizeof (server->_param.ncpu);
case GLIBTOP_PARAM_OS_VERSION_CODE:
return sizeof (server->_param.os_version_code);
case GLIBTOP_PARAM_REQUIRED:
return sizeof (server->_param.required);
}
return -GLIBTOP_ERROR_NO_SUCH_PARAMETER;
}
int
glibtop_set_parameter_l (glibtop_client *client, const unsigned parameter,
void
glibtop_set_parameter_l (glibtop *server, const unsigned parameter,
const void *data_ptr, size_t data_size)
{
switch (parameter) {
case GLIBTOP_PARAM_ERROR_METHOD:
_check_data (sizeof (server->_param.error_method));
memcpy (&server->_param.error_method, data_ptr, data_size);
break;
case GLIBTOP_PARAM_FEATURES:
case GLIBTOP_PARAM_NCPU:
case GLIBTOP_PARAM_OS_VERSION_CODE:
return -GLIBTOP_ERROR_READONLY_VALUE;
break;
case GLIBTOP_PARAM_REQUIRED:
_check_data (sizeof (server->_param.required));
memcpy (&server->_param.required, data_ptr, data_size);
break;
default:
return -GLIBTOP_ERROR_NO_SUCH_PARAMETER;
}
return 0;
switch (parameter) {
case GLIBTOP_PARAM_METHOD:
_check_data (sizeof (server->method));
memcpy (&server->method, data_ptr, data_size);
break;
case GLIBTOP_PARAM_FEATURES:
/* You should not be allowed to set this field. */
glibtop_warn_r (server, "glibtop_set_parameter (%d): " \
"Cannot modify read-only value.",
parameter);
break;
case GLIBTOP_PARAM_ERROR_METHOD:
_check_data (sizeof (server->error_method));
memcpy (&server->error_method, data_ptr, data_size);
break;
case GLIBTOP_PARAM_REQUIRED:
_check_data (sizeof (server->required));
memcpy (&server->required, data_ptr, data_size);
break;
}
}

View File

@@ -1,5 +1,3 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* Copyright (C) 1998-99 Martin Baulig
This file is part of LibGTop 1.0.
@@ -47,10 +45,74 @@ GLIBTOP_SUID_PROC_MAP +
GLIBTOP_SUID_NETLOAD +
GLIBTOP_SUID_PPP;
glibtop_init_func_t _glibtop_init_hook_s [] = {
#if !GLIBTOP_SUID_CPU
glibtop_init_cpu_s,
#endif
#if !GLIBTOP_SUID_MEM
glibtop_init_mem_s,
#endif
#if !GLIBTOP_SUID_SWAP
glibtop_init_swap_s,
#endif
#if !GLIBTOP_SUID_UPTIME
glibtop_init_uptime_s,
#endif
#if !GLIBTOP_SUID_LOADAVG
glibtop_init_loadavg_s,
#endif
#if !GLIBTOP_SUID_SHM_LIMITS
glibtop_init_shm_limits_s,
#endif
#if !GLIBTOP_SUID_MSG_LIMITS
glibtop_init_msg_limits_s,
#endif
#if !GLIBTOP_SUID_SEM_LIMITS
glibtop_init_sem_limits_s,
#endif
#if !GLIBTOP_SUID_PROCLIST
glibtop_init_proclist_s,
#endif
#if !GLIBTOP_SUID_PROC_STATE
glibtop_init_proc_state_s,
#endif
#if !GLIBTOP_SUID_PROC_UID
glibtop_init_proc_uid_s,
#endif
#if !GLIBTOP_SUID_PROC_MEM
glibtop_init_proc_mem_s,
#endif
#if !GLIBTOP_SUID_PROC_TIME
glibtop_init_proc_time_s,
#endif
#if !GLIBTOP_SUID_PROC_SIGNAL
glibtop_init_proc_signal_s,
#endif
#if !GLIBTOP_SUID_PROC_KERNEL
glibtop_init_proc_kernel_s,
#endif
#if !GLIBTOP_SUID_PROC_SEGMENT
glibtop_init_proc_segment_s,
#endif
#if !GLIBTOP_SUID_PROC_ARGS
glibtop_init_proc_args_s,
#endif
#if !GLIBTOP_SUID_PROC_MAP
glibtop_init_proc_map_s,
#endif
#if !GLIBTOP_SUID_NETLOAD
glibtop_init_netload_s,
#endif
#if !GLIBTOP_SUID_PPP
glibtop_init_ppp_s,
#endif
NULL
};
/* Checks which features are implemented. */
void
glibtop_get_sysdeps_r (glibtop *server, glibtop_sysdeps *buf)
{
memcpy (buf, &server->info->sysdeps, sizeof (glibtop_sysdeps));
memcpy (buf, &server->sysdeps, sizeof (glibtop_sysdeps));
}