The indentation in LibGTop was done with the following command:

find . -name \*.[ch] | xargs -i emacs -batch {} \
		-l /gnome/compile/libgtop/misc/format.el -f save-buffer

December 26, 1999
Martin
This commit is contained in:
Martin Baulig
1999-12-26 14:05:32 +00:00
parent d7f088bef0
commit f1a6e1ead8
272 changed files with 6300 additions and 5751 deletions
+16 -14
View File
@@ -1,3 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
@@ -31,20 +33,20 @@
void
glibtop_close_r (glibtop *server)
{
switch (server->method) {
case GLIBTOP_METHOD_UNIX:
case GLIBTOP_METHOD_INET:
glibtop_call_l (server, GLIBTOP_CMND_QUIT,
0, NULL, 0, NULL, NULL);
switch (server->method) {
case GLIBTOP_METHOD_UNIX:
case GLIBTOP_METHOD_INET:
glibtop_call_l (server, GLIBTOP_CMND_QUIT,
0, NULL, 0, NULL, NULL);
if (close (server->_priv->socket))
glibtop_warn_io ("close");
if (close (server->_priv->socket))
glibtop_warn_io ("close");
break;
case GLIBTOP_METHOD_PIPE:
kill (server->_priv->pid, SIGKILL);
close (server->_priv->input [0]);
close (server->_priv->output [1]);
break;
}
break;
case GLIBTOP_METHOD_PIPE:
kill (server->_priv->pid, SIGKILL);
close (server->_priv->input [0]);
close (server->_priv->output [1]);
break;
}
}
+33 -31
View File
@@ -1,3 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
@@ -33,51 +35,51 @@ glibtop_call_l (glibtop *server, unsigned command, size_t send_size,
const void *send_buf, size_t recv_size, void *recv_buf,
int *retval_ptr)
{
glibtop_command cmnd;
glibtop_response response;
int retval;
glibtop_command cmnd;
glibtop_response response;
int retval;
glibtop_init_r (&server, 0, 0);
glibtop_init_r (&server, 0, 0);
memset (&cmnd, 0, sizeof (glibtop_command));
memset (&cmnd, 0, sizeof (glibtop_command));
cmnd.command = command;
cmnd.command = command;
/* If send_size is less than _GLIBTOP_PARAM_SIZE (normally 16 Bytes), we
* send it together with command, so we only need one system call instead
* of two. */
/* If send_size is less than _GLIBTOP_PARAM_SIZE (normally 16 Bytes), we
* send it together with command, so we only need one system call instead
* of two. */
if (send_size <= _GLIBTOP_PARAM_SIZE) {
memcpy (cmnd.parameter, send_buf, send_size);
cmnd.size = send_size;
} else {
cmnd.data_size = send_size;
}
if (send_size <= _GLIBTOP_PARAM_SIZE) {
memcpy (cmnd.parameter, send_buf, send_size);
cmnd.size = send_size;
} else {
cmnd.data_size = send_size;
}
glibtop_write_l (server, sizeof (glibtop_command), &cmnd);
glibtop_write_l (server, sizeof (glibtop_command), &cmnd);
glibtop_read_l (server, sizeof (glibtop_response), &response);
glibtop_read_l (server, sizeof (glibtop_response), &response);
#ifdef DEBUG
fprintf (stderr, "RESPONSE: %lu - %d\n",
response.offset, response.data_size);
fprintf (stderr, "RESPONSE: %lu - %d\n",
response.offset, response.data_size);
#endif
glibtop_read_l (server, sizeof (int), &retval);
if (retval_ptr)
*retval_ptr = retval;
glibtop_read_l (server, sizeof (int), &retval);
if (retval_ptr)
*retval_ptr = retval;
if (recv_buf)
memcpy (recv_buf, ((char *) &response) + response.offset,
recv_size);
if (recv_buf)
memcpy (recv_buf, ((char *) &response) + response.offset,
recv_size);
if (response.data_size) {
void *ptr = glibtop_malloc_r (server, response.data_size);
if (response.data_size) {
void *ptr = glibtop_malloc_r (server, response.data_size);
glibtop_read_l (server, response.data_size, ptr);
glibtop_read_l (server, response.data_size, ptr);
return ptr;
}
return ptr;
}
return NULL;
return NULL;
}
+2
View File
@@ -1,3 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
+2
View File
@@ -1,3 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
+191 -189
View File
@@ -1,3 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
@@ -36,242 +38,242 @@ glibtop *glibtop_global_server = &_glibtop_global_server;
static void
_init_server (glibtop *server, const unsigned features)
{
char *command, *temp;
char *command, *temp;
/* Try to get server command, but don't override if already
* set via glibtop_set_parameter () */
/* Try to get server command, but don't override if already
* set via glibtop_set_parameter () */
if (server->server_command == NULL) {
const char *temp = getenv ("LIBGTOP_SERVER") ?
getenv ("LIBGTOP_SERVER") : LIBGTOP_SERVER;
if (server->server_command == NULL) {
const char *temp = getenv ("LIBGTOP_SERVER") ?
getenv ("LIBGTOP_SERVER") : LIBGTOP_SERVER;
server->server_command = glibtop_strdup_r (server, temp);
}
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";
if (server->server_rsh == NULL) {
const char *temp = getenv ("LIBGTOP_RSH") ?
getenv ("LIBGTOP_RSH") : "/usr/bin/ssh";
server->server_rsh = glibtop_strdup_r (server, temp);
}
server->server_rsh = glibtop_strdup_r (server, temp);
}
/* Try to get server method, but don't override if already
* set via glibtop_set_parameter () */
/* Try to get server method, but don't override if already
* set via glibtop_set_parameter () */
if (server->method) return;
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;
/* 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;
}
glibtop_error_r (server, "Unknown server method '%s'",
server->server_command+1);
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;
}
glibtop_free_r (server, command);
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);
}
void
glibtop_server_ref (glibtop *server)
{
if (server == NULL)
return;
if (server == NULL)
return;
server->refcount++;
server->refcount++;
}
void
glibtop_server_unref (glibtop *server)
{
if (server == NULL)
return;
if (server == NULL)
return;
if (!server->refcount) {
glibtop_warn_r (server, "Attempted to unref server "
"which refcount == 0");
return;
}
if (!server->refcount) {
glibtop_warn_r (server, "Attempted to unref server "
"which refcount == 0");
return;
}
server->refcount--;
server->refcount--;
}
glibtop *
glibtop_init_r (glibtop **server_ptr, unsigned long features, unsigned flags)
{
glibtop *server;
glibtop *server;
if (server_ptr == NULL)
return NULL;
if (server_ptr == NULL)
return NULL;
if (*server_ptr == NULL)
*server_ptr = glibtop_global_server;
if (*server_ptr == NULL)
*server_ptr = glibtop_global_server;
server = *server_ptr;
server = *server_ptr;
/* Should we do the initialization? */
/* 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);
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;
glibtop *server;
glibtop_init_func_t *init_fkt;
if (server_ptr == NULL)
return NULL;
if (server_ptr == NULL)
return NULL;
if (*server_ptr == NULL)
*server_ptr = glibtop_global_server;
if (*server_ptr == NULL)
*server_ptr = glibtop_global_server;
server = *server_ptr;
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->sysdeps.pointer_size = sizeof (void*)*8;
server->flags |= _GLIBTOP_INIT_STATE_SYSDEPS;
}
/* 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->sysdeps.pointer_size = sizeof (void*)*8;
server->flags |= _GLIBTOP_INIT_STATE_SYSDEPS;
}
return server;
}
+51 -49
View File
@@ -1,3 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
@@ -37,44 +39,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 *
@@ -82,36 +84,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);
}
+100 -98
View File
@@ -1,3 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
@@ -36,154 +38,154 @@ void
glibtop_open_l (glibtop *server, const char *program_name,
const unsigned long features, const unsigned flags)
{
int connect_type;
int connect_type;
if (!server->_priv)
server->_priv = glibtop_calloc_r
(server, 1, sizeof (glibtop_server_private));
if (!server->_priv)
server->_priv = glibtop_calloc_r
(server, 1, sizeof (glibtop_server_private));
server->name = program_name;
server->name = program_name;
/* It is important to set _GLIBTOP_INIT_STATE_OPEN here when we
* do recursive calls to glibtop_init_r (). */
/* It is important to set _GLIBTOP_INIT_STATE_OPEN here when we
* do recursive calls to glibtop_init_r (). */
server->flags |= _GLIBTOP_INIT_STATE_OPEN;
server->flags |= _GLIBTOP_INIT_STATE_OPEN;
server->error_method = GLIBTOP_ERROR_METHOD_DEFAULT;
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));
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:
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);
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->_priv->socket);
connect_type = glibtop_make_connection
(server->server_host, server->server_port,
&server->_priv->socket);
#ifdef DEBUG
fprintf (stderr, "Connect Type is %d.\n", connect_type);
fprintf (stderr, "Connect Type is %d.\n", connect_type);
#endif
server->flags |= _GLIBTOP_INIT_STATE_SERVER;
server->flags |= _GLIBTOP_INIT_STATE_SERVER;
server->features = -1;
break;
case GLIBTOP_METHOD_UNIX:
server->features = -1;
break;
case GLIBTOP_METHOD_UNIX:
#ifdef DEBUG
fprintf (stderr, "Connecting to Unix Domain Socket.\n");
fprintf (stderr, "Connecting to Unix Domain Socket.\n");
#endif
connect_type = glibtop_make_connection
("unix", 0, &server->_priv->socket);
connect_type = glibtop_make_connection
("unix", 0, &server->_priv->socket);
#ifdef DEBUG
fprintf (stderr, "Connect Type is %d.\n", connect_type);
fprintf (stderr, "Connect Type is %d.\n", connect_type);
#endif
server->flags |= _GLIBTOP_INIT_STATE_SERVER;
server->flags |= _GLIBTOP_INIT_STATE_SERVER;
server->features = -1;
break;
case GLIBTOP_METHOD_PIPE:
server->features = -1;
break;
case GLIBTOP_METHOD_PIPE:
#ifdef DEBUG
fprintf (stderr, "Opening pipe to server (%s).\n",
LIBGTOP_SERVER);
fprintf (stderr, "Opening pipe to server (%s).\n",
LIBGTOP_SERVER);
#endif
if (pipe (server->_priv->input) ||
pipe (server->_priv->output))
glibtop_error_io_r (server, "cannot make a pipe");
if (pipe (server->_priv->input) ||
pipe (server->_priv->output))
glibtop_error_io_r (server, "cannot make a pipe");
server->_priv->pid = fork ();
server->_priv->pid = fork ();
if (server->_priv->pid < 0) {
glibtop_error_io_r (server, "fork failed");
} else if (server->_priv->pid == 0) {
close (0); close (1);
close (server->_priv->input [0]);
close (server->_priv->output [1]);
dup2 (server->_priv->input [1], 1);
dup2 (server->_priv->output [0], 0);
execl (LIBGTOP_SERVER, "libgtop-server", NULL);
glibtop_error_io_r (server, "execl (%s)",
LIBGTOP_SERVER);
_exit (2);
}
close (server->_priv->input [1]);
close (server->_priv->output [0]);
server->flags |= _GLIBTOP_INIT_STATE_SERVER;
server->features = -1;
break;
if (server->_priv->pid < 0) {
glibtop_error_io_r (server, "fork failed");
} else if (server->_priv->pid == 0) {
close (0); close (1);
close (server->_priv->input [0]);
close (server->_priv->output [1]);
dup2 (server->_priv->input [1], 1);
dup2 (server->_priv->output [0], 0);
execl (LIBGTOP_SERVER, "libgtop-server", NULL);
glibtop_error_io_r (server, "execl (%s)",
LIBGTOP_SERVER);
_exit (2);
}
/* If the server has been started, ask it for its features. */
close (server->_priv->input [1]);
close (server->_priv->output [0]);
if (server->flags & _GLIBTOP_INIT_STATE_SERVER) {
char version [BUFSIZ], buffer [BUFSIZ];
glibtop_sysdeps sysdeps;
size_t size, nbytes;
server->flags |= _GLIBTOP_INIT_STATE_SERVER;
server->features = -1;
break;
}
/* First check whether the server version is correct. */
/* If the server has been started, ask it for its features. */
sprintf (version, LIBGTOP_VERSION_STRING,
LIBGTOP_VERSION, LIBGTOP_SERVER_VERSION,
sizeof (glibtop_command),
sizeof (glibtop_response),
sizeof (glibtop_union),
sizeof (glibtop_sysdeps));
if (server->flags & _GLIBTOP_INIT_STATE_SERVER) {
char version [BUFSIZ], buffer [BUFSIZ];
glibtop_sysdeps sysdeps;
size_t size, nbytes;
size = strlen (version) + 1;
/* 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);
glibtop_read_l (server, sizeof (nbytes), &nbytes);
if (nbytes != size)
glibtop_error_r (server,
"Requested %u bytes but got %u.",
size, nbytes);
if (nbytes != size)
glibtop_error_r (server,
"Requested %u bytes but got %u.",
size, nbytes);
glibtop_read_l (server, nbytes, buffer);
glibtop_read_l (server, nbytes, buffer);
if (memcmp (version, buffer, size))
glibtop_error_r (server, "server version is not %s",
LIBGTOP_VERSION);
if (memcmp (version, buffer, size))
glibtop_error_r (server, "server version is not %s",
LIBGTOP_VERSION);
/* Now ask it for its features. */
/* Now ask it for its features. */
glibtop_call_l (server, GLIBTOP_CMND_SYSDEPS, 0, NULL,
sizeof (glibtop_sysdeps), &sysdeps,
NULL);
glibtop_call_l (server, GLIBTOP_CMND_SYSDEPS, 0, NULL,
sizeof (glibtop_sysdeps), &sysdeps,
NULL);
server->features = sysdeps.features;
server->features = sysdeps.features;
memcpy (&server->sysdeps, &sysdeps, sizeof (glibtop_sysdeps));
memcpy (&server->sysdeps, &sysdeps, sizeof (glibtop_sysdeps));
#ifdef DEBUG
fprintf (stderr, "Server features are %lu.\n",
server->features);
fprintf (stderr, "Server features are %lu.\n",
server->features);
#endif
}
}
/* In any case, we call the open functions of our own sysdeps
* directory. */
/* In any case, we call the open functions of our own sysdeps
* directory. */
#ifdef DEBUG
fprintf (stderr, "Calling sysdeps open function.\n");
fprintf (stderr, "Calling sysdeps open function.\n");
#endif
glibtop_init_s (&server, features, flags);
glibtop_init_s (&server, features, flags);
}
+97 -95
View File
@@ -1,3 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
@@ -46,113 +48,113 @@ ssize_t
glibtop_get_parameter_l (glibtop *server, const unsigned parameter,
void *data_ptr, size_t data_size)
{
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_REMOTE_USER:
_write_data (server->server_user,
_strlen(server->server_user));
case GLIBTOP_PARAM_PATH_RSH:
_write_data (server->server_rsh,
_strlen(server->server_rsh));
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));
}
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_REMOTE_USER:
_write_data (server->server_user,
_strlen(server->server_user));
case GLIBTOP_PARAM_PATH_RSH:
_write_data (server->server_rsh,
_strlen(server->server_rsh));
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 -GLIBTOP_ERROR_NO_SUCH_PARAMETER;
}
int
glibtop_get_parameter_size_l (glibtop *server, const unsigned parameter)
{
switch (parameter) {
case GLIBTOP_PARAM_METHOD:
return sizeof (server->method);
case GLIBTOP_PARAM_FEATURES:
return sizeof (server->features);
case GLIBTOP_PARAM_COMMAND:
return _strlen(server->server_command);
case GLIBTOP_PARAM_HOST:
return _strlen(server->server_host);
case GLIBTOP_PARAM_PORT:
return sizeof (server->server_port);
case GLIBTOP_PARAM_REMOTE_USER:
return _strlen(server->server_user);
case GLIBTOP_PARAM_PATH_RSH:
return _strlen(server->server_rsh);
case GLIBTOP_PARAM_ERROR_METHOD:
return sizeof (server->error_method);
case GLIBTOP_PARAM_REQUIRED:
return sizeof (server->required);
}
switch (parameter) {
case GLIBTOP_PARAM_METHOD:
return sizeof (server->method);
case GLIBTOP_PARAM_FEATURES:
return sizeof (server->features);
case GLIBTOP_PARAM_COMMAND:
return _strlen(server->server_command);
case GLIBTOP_PARAM_HOST:
return _strlen(server->server_host);
case GLIBTOP_PARAM_PORT:
return sizeof (server->server_port);
case GLIBTOP_PARAM_REMOTE_USER:
return _strlen(server->server_user);
case GLIBTOP_PARAM_PATH_RSH:
return _strlen(server->server_rsh);
case GLIBTOP_PARAM_ERROR_METHOD:
return sizeof (server->error_method);
case GLIBTOP_PARAM_REQUIRED:
return sizeof (server->required);
}
return -GLIBTOP_ERROR_NO_SUCH_PARAMETER;
return -GLIBTOP_ERROR_NO_SUCH_PARAMETER;
}
int
glibtop_set_parameter_l (glibtop *server, const unsigned parameter,
const void *data_ptr, size_t data_size)
{
switch (parameter) {
case GLIBTOP_PARAM_METHOD:
_check_data (sizeof (server->method));
memcpy (&server->method, data_ptr, data_size);
break;
case GLIBTOP_PARAM_FEATURES:
return -GLIBTOP_ERROR_READONLY_VALUE;
break;
case GLIBTOP_PARAM_COMMAND:
if (server->server_command)
glibtop_free_r (server, server->server_command);
server->server_command = glibtop_strdup_r (server, data_ptr);
break;
case GLIBTOP_PARAM_HOST:
if (server->server_host)
glibtop_free_r (server, server->server_host);
server->server_host = glibtop_strdup_r (server, data_ptr);
break;
case GLIBTOP_PARAM_PORT:
_check_data (sizeof (server->server_port));
memcpy (&server->server_port, data_ptr, data_size);
break;
case GLIBTOP_PARAM_REMOTE_USER:
if (server->server_user)
glibtop_free_r (server, server->server_user);
server->server_user = glibtop_strdup_r (server, data_ptr);
break;
case GLIBTOP_PARAM_PATH_RSH:
if (server->server_rsh)
glibtop_free_r (server, server->server_rsh);
server->server_rsh = glibtop_strdup_r (server, data_ptr);
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;
default:
return -GLIBTOP_ERROR_NO_SUCH_PARAMETER;
}
switch (parameter) {
case GLIBTOP_PARAM_METHOD:
_check_data (sizeof (server->method));
memcpy (&server->method, data_ptr, data_size);
break;
case GLIBTOP_PARAM_FEATURES:
return -GLIBTOP_ERROR_READONLY_VALUE;
break;
case GLIBTOP_PARAM_COMMAND:
if (server->server_command)
glibtop_free_r (server, server->server_command);
server->server_command = glibtop_strdup_r (server, data_ptr);
break;
case GLIBTOP_PARAM_HOST:
if (server->server_host)
glibtop_free_r (server, server->server_host);
server->server_host = glibtop_strdup_r (server, data_ptr);
break;
case GLIBTOP_PARAM_PORT:
_check_data (sizeof (server->server_port));
memcpy (&server->server_port, data_ptr, data_size);
break;
case GLIBTOP_PARAM_REMOTE_USER:
if (server->server_user)
glibtop_free_r (server, server->server_user);
server->server_user = glibtop_strdup_r (server, data_ptr);
break;
case GLIBTOP_PARAM_PATH_RSH:
if (server->server_rsh)
glibtop_free_r (server, server->server_rsh);
server->server_rsh = glibtop_strdup_r (server, data_ptr);
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;
default:
return -GLIBTOP_ERROR_NO_SUCH_PARAMETER;
}
return 0;
return 0;
}
+33 -31
View File
@@ -1,3 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
@@ -28,49 +30,49 @@
static void
do_read (int s, void *ptr, size_t total_size)
{
int nread;
size_t already_read = 0, remaining = total_size;
char *tmp_ptr;
int nread;
size_t already_read = 0, remaining = total_size;
char *tmp_ptr;
while (already_read < total_size) {
nread = recv (s, ptr, remaining, 0);
while (already_read < total_size) {
nread = recv (s, ptr, remaining, 0);
if (nread == 0) {
close (s);
continue;
}
if (nread <= 0) {
glibtop_error_io ("recv");
return;
}
already_read += nread;
remaining -= nread;
/* (char *) ptr += nread; */
tmp_ptr = ptr;
tmp_ptr += nread;
ptr = tmp_ptr;
if (nread == 0) {
close (s);
continue;
}
if (nread <= 0) {
glibtop_error_io ("recv");
return;
}
already_read += nread;
remaining -= nread;
/* (char *) ptr += nread; */
tmp_ptr = ptr;
tmp_ptr += nread;
ptr = tmp_ptr;
}
}
void
glibtop_read_l (glibtop *server, size_t size, void *buf)
{
int ret = 0;
int ret = 0;
glibtop_init_r (&server, 0, 0);
glibtop_init_r (&server, 0, 0);
#ifdef DEBUG
fprintf (stderr, "LIBRARY: really reading %d bytes.\n", size);
fprintf (stderr, "LIBRARY: really reading %d bytes.\n", size);
#endif
if (server->_priv->socket) {
do_read (server->_priv->socket, buf, size);
} else {
ret = read (server->_priv->input [0], buf, size);
}
if (server->_priv->socket) {
do_read (server->_priv->socket, buf, size);
} else {
ret = read (server->_priv->input [0], buf, size);
}
if (ret < 0)
glibtop_error_io_r (server, _("read %d bytes"), size);
if (ret < 0)
glibtop_error_io_r (server, _("read %d bytes"), size);
}
+27 -25
View File
@@ -1,3 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
@@ -29,43 +31,43 @@
void *
glibtop_read_data_l (glibtop *server)
{
size_t size;
void *ptr;
int ret;
size_t size;
void *ptr;
int ret;
glibtop_init_r (&server, 0, 0);
glibtop_init_r (&server, 0, 0);
#ifdef DEBUG
fprintf (stderr, "LIBRARY: reading %d data bytes.\n", sizeof (size_t));
fprintf (stderr, "LIBRARY: reading %d data bytes.\n", sizeof (size_t));
#endif
if (server->_priv->socket) {
ret = recv (server->_priv->socket, (void *)&size,
sizeof (size_t), 0);
} else {
ret = read (server->_priv->input [0], (void *)&size,
sizeof (size_t));
}
if (server->_priv->socket) {
ret = recv (server->_priv->socket, (void *)&size,
sizeof (size_t), 0);
} else {
ret = read (server->_priv->input [0], (void *)&size,
sizeof (size_t));
}
if (ret < 0)
glibtop_error_io_r (server, _("read data size"));
if (ret < 0)
glibtop_error_io_r (server, _("read data size"));
#ifdef DEBUG
fprintf (stderr, "LIBRARY: really reading %d data bytes (ret = %d).\n", size, ret);
fprintf (stderr, "LIBRARY: really reading %d data bytes (ret = %d).\n", size, ret);
#endif
if (!size) return NULL;
if (!size) return NULL;
ptr = glibtop_malloc_r (server, size);
ptr = glibtop_malloc_r (server, size);
if (server->_priv->socket) {
ret = recv (server->_priv->socket, ptr, size, 0);
} else {
ret = read (server->_priv->input [0], ptr, size);
}
if (server->_priv->socket) {
ret = recv (server->_priv->socket, ptr, size, 0);
} else {
ret = read (server->_priv->input [0], ptr, size);
}
if (ret < 0)
glibtop_error_io_r (server, _("read data %d bytes"));
if (ret < 0)
glibtop_error_io_r (server, _("read data %d bytes"));
return ptr;
return ptr;
}
+24 -22
View File
@@ -1,3 +1,5 @@
/* -*- 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,66 +49,66 @@ GLIBTOP_SUID_PPP;
glibtop_init_func_t _glibtop_init_hook_s [] = {
#if !GLIBTOP_SUID_CPU
glibtop_init_cpu_s,
glibtop_init_cpu_s,
#endif
#if !GLIBTOP_SUID_MEM
glibtop_init_mem_s,
glibtop_init_mem_s,
#endif
#if !GLIBTOP_SUID_SWAP
glibtop_init_swap_s,
glibtop_init_swap_s,
#endif
#if !GLIBTOP_SUID_UPTIME
glibtop_init_uptime_s,
glibtop_init_uptime_s,
#endif
#if !GLIBTOP_SUID_LOADAVG
glibtop_init_loadavg_s,
glibtop_init_loadavg_s,
#endif
#if !GLIBTOP_SUID_SHM_LIMITS
glibtop_init_shm_limits_s,
glibtop_init_shm_limits_s,
#endif
#if !GLIBTOP_SUID_MSG_LIMITS
glibtop_init_msg_limits_s,
glibtop_init_msg_limits_s,
#endif
#if !GLIBTOP_SUID_SEM_LIMITS
glibtop_init_sem_limits_s,
glibtop_init_sem_limits_s,
#endif
#if !GLIBTOP_SUID_PROCLIST
glibtop_init_proclist_s,
glibtop_init_proclist_s,
#endif
#if !GLIBTOP_SUID_PROC_STATE
glibtop_init_proc_state_s,
glibtop_init_proc_state_s,
#endif
#if !GLIBTOP_SUID_PROC_UID
glibtop_init_proc_uid_s,
glibtop_init_proc_uid_s,
#endif
#if !GLIBTOP_SUID_PROC_MEM
glibtop_init_proc_mem_s,
glibtop_init_proc_mem_s,
#endif
#if !GLIBTOP_SUID_PROC_TIME
glibtop_init_proc_time_s,
glibtop_init_proc_time_s,
#endif
#if !GLIBTOP_SUID_PROC_SIGNAL
glibtop_init_proc_signal_s,
glibtop_init_proc_signal_s,
#endif
#if !GLIBTOP_SUID_PROC_KERNEL
glibtop_init_proc_kernel_s,
glibtop_init_proc_kernel_s,
#endif
#if !GLIBTOP_SUID_PROC_SEGMENT
glibtop_init_proc_segment_s,
glibtop_init_proc_segment_s,
#endif
#if !GLIBTOP_SUID_PROC_ARGS
glibtop_init_proc_args_s,
glibtop_init_proc_args_s,
#endif
#if !GLIBTOP_SUID_PROC_MAP
glibtop_init_proc_map_s,
glibtop_init_proc_map_s,
#endif
#if !GLIBTOP_SUID_NETLOAD
glibtop_init_netload_s,
glibtop_init_netload_s,
#endif
#if !GLIBTOP_SUID_PPP
glibtop_init_ppp_s,
glibtop_init_ppp_s,
#endif
NULL
NULL
};
/* Checks which features are implemented. */
@@ -114,5 +116,5 @@ glibtop_init_func_t _glibtop_init_hook_s [] = {
void
glibtop_get_sysdeps_r (glibtop *server, glibtop_sysdeps *buf)
{
memcpy (buf, &server->sysdeps, sizeof (glibtop_sysdeps));
memcpy (buf, &server->sysdeps, sizeof (glibtop_sysdeps));
}
+13 -11
View File
@@ -1,3 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
@@ -28,22 +30,22 @@
void
glibtop_write_l (glibtop *server, size_t size, void *buf)
{
int ret;
int ret;
glibtop_init_r (&server, 0, 0);
glibtop_init_r (&server, 0, 0);
if (size == 0) return;
if (size == 0) return;
#ifdef DEBUG
fprintf (stderr, "LIBRARY: really writing %d bytes.\n", size);
fprintf (stderr, "LIBRARY: really writing %d bytes.\n", size);
#endif
if (server->_priv->socket) {
ret = send (server->_priv->socket, buf, size, 0);
} else {
ret = write (server->_priv->output [1], buf, size);
}
if (server->_priv->socket) {
ret = send (server->_priv->socket, buf, size, 0);
} else {
ret = write (server->_priv->output [1], buf, size);
}
if (ret < 0)
glibtop_error_io_r (server, _("write %d bytes"), size);
if (ret < 0)
glibtop_error_io_r (server, _("write %d bytes"), size);
}