Convert lots of fprintf(stderr, ...) to glibtop_debug*().

This commit is contained in:
Benoit Dejean
2015-06-21 22:39:11 +02:00
parent 887092a05d
commit 172f0a50ba
10 changed files with 22 additions and 65 deletions

View File

@@ -45,7 +45,7 @@ glibtop_call_l (glibtop *server, unsigned command, size_t send_size,
#ifdef LIBGTOP_ENABLE_DEBUG #ifdef LIBGTOP_ENABLE_DEBUG
g_assert(command >= GLIBTOP_CMND_QUIT && command < GLIBTOP_MAX_CMND); g_assert(command >= GLIBTOP_CMND_QUIT && command < GLIBTOP_MAX_CMND);
switch (command) { switch (command) {
#define DEBUG_CALL(CMD) case (CMD): glibtop_warn_r(server, "CALL: command %s sending %lu bytes", #CMD, (unsigned long)send_size); break #define DEBUG_CALL(CMD) case (CMD): glibtop_debug("CALL: command %s sending %lu bytes", #CMD, (unsigned long)send_size); break
DEBUG_CALL(GLIBTOP_CMND_QUIT); DEBUG_CALL(GLIBTOP_CMND_QUIT);
DEBUG_CALL(GLIBTOP_CMND_SYSDEPS); DEBUG_CALL(GLIBTOP_CMND_SYSDEPS);
DEBUG_CALL(GLIBTOP_CMND_CPU); DEBUG_CALL(GLIBTOP_CMND_CPU);
@@ -91,10 +91,8 @@ glibtop_call_l (glibtop *server, unsigned command, size_t send_size,
glibtop_read_l (server, sizeof (glibtop_response), &response); glibtop_read_l (server, sizeof (glibtop_response), &response);
#ifdef LIBGTOP_ENABLE_DEBUG glibtop_debug ("RESPONSE: offset=%lu - data_size=%lu",
fprintf (stderr, "RESPONSE: offset=%lu - data_size=%lu\n",
response.offset, response.data_size); response.offset, response.data_size);
#endif
if (recv_buf) if (recv_buf)
memcpy (recv_buf, ((char *) &response) + response.offset, memcpy (recv_buf, ((char *) &response) + response.offset,

View File

@@ -47,56 +47,44 @@ glibtop_open_l (glibtop *server, const char *program_name,
server->error_method = GLIBTOP_ERROR_METHOD_DEFAULT; server->error_method = GLIBTOP_ERROR_METHOD_DEFAULT;
#ifdef LIBGTOP_ENABLE_DEBUG glibtop_debug ("SIZEOF: %u - %u - %u - %u - %u - %u",
fprintf (stderr, "SIZEOF: %u - %u - %u - %u - %u - %u\n",
sizeof (glibtop_command), sizeof (glibtop_response), sizeof (glibtop_command), sizeof (glibtop_response),
sizeof (glibtop_mountentry), sizeof (glibtop_union), sizeof (glibtop_mountentry), sizeof (glibtop_union),
sizeof (glibtop_sysdeps), sizeof (glibtop_response_union)); sizeof (glibtop_sysdeps), sizeof (glibtop_response_union));
#endif
switch (server->method) { switch (server->method) {
case GLIBTOP_METHOD_DIRECT: case GLIBTOP_METHOD_DIRECT:
server->features = 0; server->features = 0;
break; break;
case GLIBTOP_METHOD_INET: case GLIBTOP_METHOD_INET:
#ifdef LIBGTOP_ENABLE_DEBUG glibtop_debug ("Connecting to '%s' port %ld.",
fprintf (stderr, "Connecting to '%s' port %ld.\n",
server->server_host, server->server_port); server->server_host, server->server_port);
#endif
connect_type = glibtop_make_connection connect_type = glibtop_make_connection
(server->server_host, server->server_port, (server->server_host, server->server_port,
&server->socket); &server->socket);
#ifdef LIBGTOP_ENABLE_DEBUG glibtop_debug ("Connect Type is %d.", 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; server->features = -1;
break; break;
case GLIBTOP_METHOD_UNIX: case GLIBTOP_METHOD_UNIX:
#ifdef LIBGTOP_ENABLE_DEBUG glibtop_debug ("Connecting to Unix Domain Socket.");
fprintf (stderr, "Connecting to Unix Domain Socket.\n");
#endif
connect_type = glibtop_make_connection connect_type = glibtop_make_connection
("unix", 0, &server->socket); ("unix", 0, &server->socket);
#ifdef LIBGTOP_ENABLE_DEBUG glibtop_debug ("Connect Type is %d.", 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; server->features = -1;
break; break;
case GLIBTOP_METHOD_PIPE: case GLIBTOP_METHOD_PIPE:
#ifdef LIBGTOP_ENABLE_DEBUG glibtop_debug ("Opening pipe to server (%s).",
fprintf (stderr, "Opening pipe to server (%s).\n",
server->server_command); server->server_command);
#endif
if (pipe (server->input) || pipe (server->output)) if (pipe (server->input) || pipe (server->output))
glibtop_error_io_r (server, "cannot make a pipe"); glibtop_error_io_r (server, "cannot make a pipe");
@@ -165,18 +153,14 @@ glibtop_open_l (glibtop *server, const char *program_name,
memcpy (&server->sysdeps, &sysdeps, sizeof (glibtop_sysdeps)); memcpy (&server->sysdeps, &sysdeps, sizeof (glibtop_sysdeps));
#ifdef LIBGTOP_ENABLE_DEBUG glibtop_debug ("Server features are %lu.",
fprintf (stderr, "Server features are %lu.\n",
server->features); server->features);
#endif
} }
/* In any case, we call the open functions of our own sysdeps /* In any case, we call the open functions of our own sysdeps
* directory. */ * directory. */
#ifdef LIBGTOP_ENABLE_DEBUG glibtop_debug ("Calling sysdeps open function.");
fprintf (stderr, "Calling sysdeps open function.\n");
#endif
glibtop_init_s (&server, features, flags); glibtop_init_s (&server, features, flags);
} }

View File

@@ -33,9 +33,7 @@ glibtop_read_l (glibtop *server, size_t size, void *buf)
int fd; int fd;
glibtop_init_r (&server, 0, 0); glibtop_init_r (&server, 0, 0);
#ifdef LIBGTOP_ENABLE_DEBUG glibtop_debug("LIBRARY: really reading %d bytes.", (int)size);
glibtop_warn_r(server, "LIBRARY: really reading %d bytes.\n", (int)size);
#endif
fd = server->socket ? server->socket : server->input[0]; fd = server->socket ? server->socket : server->input[0];

View File

@@ -36,10 +36,8 @@ glibtop_read_data_l (glibtop *server)
glibtop_init_r (&server, 0, 0); glibtop_init_r (&server, 0, 0);
#ifdef LIBGTOP_ENABLE_DEBUG glibtop_debug ("LIBRARY: reading %lu data bytes.",
fprintf (stderr, "LIBRARY: reading %lu data bytes.\n",
(unsigned long) sizeof (size_t)); (unsigned long) sizeof (size_t));
#endif
if (server->socket) { if (server->socket) {
ret = recv (server->socket, &size, sizeof (size_t), 0); ret = recv (server->socket, &size, sizeof (size_t), 0);
@@ -50,10 +48,8 @@ glibtop_read_data_l (glibtop *server)
if (ret < 0) if (ret < 0)
glibtop_error_io_r (server, _("read data size")); glibtop_error_io_r (server, _("read data size"));
#ifdef LIBGTOP_ENABLE_DEBUG glibtop_debug ("LIBRARY: really reading %lu data bytes (ret = %d).",
fprintf (stderr, "LIBRARY: really reading %lu data bytes (ret = %d).\n",
(unsigned long) size, ret); (unsigned long) size, ret);
#endif
if (!size) return NULL; if (!size) return NULL;

View File

@@ -37,9 +37,7 @@ glibtop_write_l (glibtop *server, size_t size, void *buf)
if (size == 0) return; if (size == 0) return;
#ifdef LIBGTOP_ENABLE_DEBUG glibtop_debug("LIBRARY: really writing %d bytes.", (int)size);
fprintf (stderr, "LIBRARY: really writing %d bytes.\n", (int)size);
#endif
fd = server->socket ? server->socket : server->output[1]; fd = server->socket ? server->socket : server->output[1];

View File

@@ -27,10 +27,8 @@ void
do_output (int s, glibtop_response *resp, off_t offset, do_output (int s, glibtop_response *resp, off_t offset,
size_t data_size, const void *data) size_t data_size, const void *data)
{ {
#ifdef LIBGTOP_ENABLE_DEBUG glibtop_debug ("Really writing %d bytes at offset %lu.",
fprintf (stderr, "Really writing %d bytes at offset %lu.\n",
sizeof (glibtop_response), offset); sizeof (glibtop_response), offset);
#endif
resp->offset = offset; resp->offset = offset;
resp->data_size = data_size; resp->data_size = data_size;
@@ -44,9 +42,7 @@ do_output (int s, glibtop_response *resp, off_t offset,
} }
if (resp->data_size) { if (resp->data_size) {
#ifdef LIBGTOP_ENABLE_DEBUG glibtop_debug ("Writing %d bytes of data.", resp->data_size);
fprintf (stderr, "Writing %d bytes of data.\n", resp->data_size);
#endif
if (s == 0) { if (s == 0) {
if (write (1, data, resp->data_size) < 0) if (write (1, data, resp->data_size) < 0)
@@ -88,10 +84,8 @@ do_read (int s, void *ptr, size_t total_size)
tmp_ptr += nread; tmp_ptr += nread;
ptr = tmp_ptr; ptr = tmp_ptr;
#ifdef LIBGTOP_ENABLE_DEBUG glibtop_debug ("READ (%d): %d - %d - %d",
fprintf (stderr, "READ (%d): %d - %d - %d\n",
nread, already_read, remaining, total_size); nread, already_read, remaining, total_size);
#endif
} }
return already_read; return already_read;

View File

@@ -26,9 +26,6 @@
#ifndef PARENT_DEBUG #ifndef PARENT_DEBUG
#define PARENT_DEBUG 1 #define PARENT_DEBUG 1
#endif #endif
#ifndef LIBGTOP_ENABLE_DEBUG
#define LIBGTOP_ENABLE_DEBUG 1
#endif
#endif #endif
void void

View File

@@ -41,10 +41,8 @@ handle_slave_connection (int input, int output)
glibtop_send_version (glibtop_global_server, output); glibtop_send_version (glibtop_global_server, output);
while (do_read (input, cmnd, sizeof (glibtop_command))) { while (do_read (input, cmnd, sizeof (glibtop_command))) {
#ifdef LIBGTOP_ENABLE_DEBUG glibtop_debug ("Slave %d received command "
fprintf (stderr, "Slave %d received command " "%llu from client.", getpid (), cmnd->command);
"%llu from client.\n", getpid (), cmnd->command);
#endif
if (cmnd->data_size >= BUFSIZ) if (cmnd->data_size >= BUFSIZ)
glibtop_error ("Client sent %llu bytes, " glibtop_error ("Client sent %llu bytes, "
@@ -56,10 +54,8 @@ handle_slave_connection (int input, int output)
memset (parameter, 0, sizeof (parameter)); memset (parameter, 0, sizeof (parameter));
if (cmnd->data_size) { if (cmnd->data_size) {
#ifdef LIBGTOP_ENABLE_DEBUG glibtop_debug ("Client has %llu bytes of data.",
fprintf (stderr, "Client has %llu bytes of data.\n",
cmnd->data_size); cmnd->data_size);
#endif
do_read (input, parameter, cmnd->data_size); do_read (input, parameter, cmnd->data_size);

View File

@@ -42,9 +42,7 @@ glibtop_send_version (glibtop *server, int fd)
size = strlen (buffer) + 1; size = strlen (buffer) + 1;
#ifdef LIBGTOP_ENABLE_DEBUG glibtop_debug ("SERVER ID: |%s|", buffer);
fprintf (stderr, "SERVER ID: |%s|\n", buffer);
#endif
if (fd == 0) { if (fd == 0) {
if (write (1, (const void *) &size, sizeof (size)) < 0) if (write (1, (const void *) &size, sizeof (size)) < 0)

View File

@@ -56,9 +56,7 @@ glibtop_open_p (glibtop *server, const char *program_name,
const unsigned flags) const unsigned flags)
{ {
char errbuf[_POSIX2_LINE_MAX]; char errbuf[_POSIX2_LINE_MAX];
#ifdef LIBGTOP_ENABLE_DEBUG glibtop_debug ("glibtop_open_p ()");
fprintf (stderr, "DEBUG (%d): glibtop_open_p ()\n", getpid ());
#endif
/* !!! WE ARE ROOT HERE - CHANGE WITH CAUTION !!! */ /* !!! WE ARE ROOT HERE - CHANGE WITH CAUTION !!! */
server->machine.uid = getuid (); server->machine.uid = getuid ();