Basically did some work on the new daemon. Things are still unstable.

1998-07-13  Martin Baulig  <martin@home-of-linux.org>

	* glibtop.h: Fixed invocation of `glibtop_close_r'.

	* sysdeps/linux/procstate.c: Added missing `fclose'.

	* include/glibtop/gnuserv.h (UNIX_DOMAIN_SOCKETS): Defining.

	* include/glibtop/open.h (GLIBTOP_METHOD_UNIX): Added.

	* lib/init.c: Added new method `GLIBTOP_METHOD_UNIX'.

	* lib/open.c: Added support for Unix Domain Sockets.

	* lib/close.c: Now closing inet and unix connections.

	* lib/parameter.c (glibtop_set_parameter_l): You can now
	set the `method' and `features' fields.

	* src/daemon/server_config.h: New file.

	* src/daemon/{gnuserv.c, main.c}: More work on the server.
This commit is contained in:
Martin Baulig
1998-07-13 00:39:46 +00:00
committed by Martin Baulig
parent f30dfecaf7
commit 3477d30dc5
14 changed files with 572 additions and 275 deletions

View File

@@ -21,15 +21,19 @@
#include <glibtop/gnuserv.h>
#include <glibtop/command.h>
#include <glibtop/version.h>
#include <glibtop/xmalloc.h>
#include <glibtop/union.h>
#include <glibtop/open.h>
#include <glibtop/union.h>
#include <glibtop/xmalloc.h>
#include <glibtop/version.h>
#include <glibtop/command.h>
#include <glibtop/parameter.h>
#include <fcntl.h>
#include <locale.h>
#undef REAL_DEBUG
#define PARENT_DEBUG
#if defined(HAVE_GETDTABLESIZE)
#define GET_MAX_FDS() getdtablesize()
#else
@@ -46,7 +50,7 @@ do_output (int s, glibtop_response *response, off_t offset,
size_t data_size, const void *data)
{
#ifdef REAL_DEBUG
fprintf (stderr, "Really writing %d bytes at offset %d.\n",
fprintf (stderr, "Really writing %d bytes at offset %lu.\n",
sizeof (glibtop_response), offset);
#endif
@@ -66,31 +70,201 @@ do_output (int s, glibtop_response *response, off_t offset,
}
}
static void
static int
do_read (int s, void *ptr, size_t total_size)
{
int nread;
size_t already_read = 0, remaining = total_size;
while (already_read < total_size) {
nread = recv (s, ptr, remaining, 0);
if (s)
nread = recv (s, ptr, remaining, 0);
else
nread = read (0, ptr, remaining);
if ((already_read == 0) && (nread == 0)) {
glibtop_warn ("pid %d received eof.", getpid ());
return 0;
}
if (nread <= 0) {
glibtop_error_io ("recv");
return;
glibtop_warn_io ("recv");
return 0;
}
already_read += nread;
remaining -= nread;
(char *) ptr += nread;
#ifdef REAL_DEBUG
fprintf (stderr, "READ (%d): %d - %d - %d\n",
nread, already_read, remaining, total_size);
#endif
}
return already_read;
}
void
handle_parent_connection (glibtop *server, int s)
{
pid_t pid;
char parameter [BUFSIZ];
struct timeval tv;
glibtop_response response;
glibtop_command cmnd;
unsigned method;
int null = 0;
void *ptr;
tv.tv_sec = 5;
tv.tv_usec = 0;
method = GLIBTOP_METHOD_UNIX;
glibtop_set_parameter_l (server, GLIBTOP_PARAM_METHOD,
&method, sizeof (method));
glibtop_set_parameter_l (server, GLIBTOP_PARAM_FEATURES,
&glibtop_server_features,
sizeof (glibtop_server_features));
fprintf (stderr, "Parent features = %lu\n", glibtop_server_features);
while (do_read (s, &cmnd, sizeof (glibtop_command))) {
#ifdef PARENT_DEBUG
fprintf (stderr, "Parent (%d) received command %d from client.\n",
getpid (), cmnd.command);
#endif
if (cmnd.data_size >= BUFSIZ) {
glibtop_warn ("Client sent %d bytes, but buffer is %d", cmnd.size, BUFSIZ);
return;
}
memset (parameter, 0, sizeof (parameter));
if (cmnd.data_size) {
#ifdef PARENT_DEBUG
fprintf (stderr, "Client has %d bytes of data.\n", cmnd.data_size);
#endif
do_read (s, parameter, cmnd.data_size);
} else if (cmnd.size) {
memcpy (parameter, cmnd.parameter, cmnd.size);
}
switch (cmnd.command) {
case GLIBTOP_CMND_QUIT:
do_output (s, &response, 0, 0, NULL);
fprintf (stderr, "Sending QUIT command (%d).\n",
server->socket);
glibtop_call_l (server, GLIBTOP_CMND_QUIT,
0, NULL, 0, NULL);
fprintf (stderr, "Done sending QUIT command (%d).\n",
server->socket);
close (server->socket);
return;
case GLIBTOP_CMND_SYSDEPS:
response.u.sysdeps.features = GLIBTOP_SYSDEPS_ALL;
do_output (s, &response, _offset_union (sysdeps), 0, NULL);
break;
case GLIBTOP_CMND_CPU:
glibtop_get_cpu_l (server, &response.u.data.cpu);
do_output (s, &response, _offset_data (cpu), 0, NULL);
break;
case GLIBTOP_CMND_MEM:
glibtop_get_mem_l (server, &response.u.data.mem);
do_output (s, &response, _offset_data (mem), 0, NULL);
break;
case GLIBTOP_CMND_SWAP:
glibtop_get_swap_l (server, &response.u.data.swap);
do_output (s, &response, _offset_data (swap), 0, NULL);
break;
case GLIBTOP_CMND_UPTIME:
glibtop_get_uptime_l (server, &response.u.data.uptime);
do_output (s, &response, _offset_data (uptime), 0, NULL);
break;
case GLIBTOP_CMND_LOADAVG:
glibtop_get_loadavg_l (server, &response.u.data.loadavg);
do_output (s, &response, _offset_data (loadavg), 0, NULL);
break;
case GLIBTOP_CMND_SHM_LIMITS:
glibtop_get_shm_limits_l (server, &response.u.data.shm_limits);
do_output (s, &response, _offset_data (shm_limits), 0, NULL);
break;
case GLIBTOP_CMND_MSG_LIMITS:
glibtop_get_msg_limits_l (server, &response.u.data.msg_limits);
do_output (s, &response, _offset_data (msg_limits), 0, NULL);
break;
case GLIBTOP_CMND_SEM_LIMITS:
glibtop_get_sem_limits_l (server, &response.u.data.sem_limits);
do_output (s, &response, _offset_data (sem_limits), 0, NULL);
break;
case GLIBTOP_CMND_PROCLIST:
ptr = glibtop_get_proclist_l (server, &response.u.data.proclist);
do_output (s, &response, _offset_data (proclist),
response.u.data.proclist.total, ptr);
glibtop_free_r (server, ptr);
break;
case GLIBTOP_CMND_PROC_STATE:
memcpy (&pid, parameter, sizeof (pid_t));
glibtop_get_proc_state_l
(server, &response.u.data.proc_state, pid);
do_output (s, &response, _offset_data (proc_state), 0, NULL);
break;
case GLIBTOP_CMND_PROC_UID:
memcpy (&pid, parameter, sizeof (pid_t));
glibtop_get_proc_uid_l
(server, &response.u.data.proc_uid, pid);
do_output (s, &response, _offset_data (proc_uid), 0, NULL);
break;
case GLIBTOP_CMND_PROC_MEM:
memcpy (&pid, parameter, sizeof (pid_t));
glibtop_get_proc_mem_l
(server, &response.u.data.proc_mem, pid);
do_output (s, &response, _offset_data (proc_mem), 0, NULL);
break;
case GLIBTOP_CMND_PROC_TIME:
memcpy (&pid, parameter, sizeof (pid_t));
glibtop_get_proc_time_l
(server, &response.u.data.proc_time, pid);
do_output (s, &response, _offset_data (proc_time), 0, NULL);
break;
case GLIBTOP_CMND_PROC_SIGNAL:
memcpy (&pid, parameter, sizeof (pid_t));
glibtop_get_proc_signal_l
(server, &response.u.data.proc_signal, pid);
do_output (s, &response, _offset_data (proc_signal), 0, NULL);
break;
case GLIBTOP_CMND_PROC_KERNEL:
memcpy (&pid, parameter, sizeof (pid_t));
glibtop_get_proc_kernel_l
(server, &response.u.data.proc_kernel, pid);
do_output (s, &response, _offset_data (proc_kernel), 0, NULL);
break;
case GLIBTOP_CMND_PROC_SEGMENT:
memcpy (&pid, parameter, sizeof (pid_t));
glibtop_get_proc_segment_l
(server, &response.u.data.proc_segment, pid);
do_output (s, &response, _offset_data (proc_segment), 0, NULL);
break;
default:
glibtop_warn_r (server,
"Parent received unknown command %u",
cmnd.command);
break;
}
}
}
void
handle_socket_connection (glibtop *server, int s)
handle_child_connection (glibtop *server, int s)
{
pid_t pid;
char parameter [BUFSIZ];
@@ -102,11 +276,10 @@ handle_socket_connection (glibtop *server, int s)
tv.tv_sec = 5;
tv.tv_usec = 0;
while(1) {
do_read (s, &cmnd, sizeof (glibtop_command));
#ifdef REAL_DEBUG
fprintf (stderr, "Received command %d from client.\n", cmnd.command);
while (do_read (s, &cmnd, sizeof (glibtop_command))) {
#ifdef CHILD_DEBUG
fprintf (stderr, "Child (%d - %d) received command "
"%d from client.\n", getpid (), s, cmnd.command);
#endif
if (cmnd.data_size >= BUFSIZ) {
@@ -117,7 +290,7 @@ handle_socket_connection (glibtop *server, int s)
memset (parameter, 0, sizeof (parameter));
if (cmnd.data_size) {
#ifdef REAL_DEBUG
#ifdef CHILD_DEBUG
fprintf (stderr, "Client has %d bytes of data.\n", cmnd.data_size);
#endif
@@ -128,8 +301,14 @@ handle_socket_connection (glibtop *server, int s)
}
switch (cmnd.command) {
case GLIBTOP_CMND_QUIT:
do_output (s, &response, 0, 0, NULL);
fprintf (stderr, "Child received QUIT command.\n");
return;
case GLIBTOP_CMND_SYSDEPS:
response.u.sysdeps.features = GLIBTOP_SYSDEPS_ALL;
response.u.sysdeps.features = glibtop_server_features;
do_output (s, &response, _offset_union (sysdeps), 0, NULL);
break;
case GLIBTOP_CMND_CPU:
@@ -213,6 +392,12 @@ handle_socket_connection (glibtop *server, int s)
(server, &response.u.data.proc_segment, pid);
do_output (s, &response, _offset_data (proc_segment), 0, NULL);
break;
default:
glibtop_warn_r (server,
"Child received unknown command %u",
cmnd.command);
break;
}
}
}