From ef693a93bc715cbe453371de711cf102c1ddb83f Mon Sep 17 00:00:00 2001 From: Martin Baulig Date: Tue, 14 Jul 1998 08:36:23 +0000 Subject: [PATCH] Doing correct server initialization using `glibtop_set_parameter_l' and 1998-07-14 Martin Baulig * src/daemon/gnuserv.c: Doing correct server initialization using `glibtop_set_parameter_l' and `glibtop_init_r'. * src/daemon/main.c: Removed call to `glibtop_init_r'. * lib/open.c (glibtop_open_l): We now call the open function of the sysdeps directory (glibtop_open_r) for server method `GLIBTOP_METHOD_DIRECT'. * sysdeps/{linux, sun4, stub}/open.c: No longer `memset' server to zero. --- ChangeLog | 12 ++++++++++++ lib/open.c | 6 ++++++ src/daemon/gnuserv.c | 31 ++++++++++++++++++++++++++++++- src/daemon/main.c | 10 ---------- sysdeps/linux/open.c | 1 - sysdeps/stub/open.c | 1 - sysdeps/sun4/open.c | 1 - 7 files changed, 48 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 09523fc9..5baabd99 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,17 @@ 1998-07-14 Martin Baulig + * src/daemon/gnuserv.c: Doing correct server initialization + using `glibtop_set_parameter_l' and `glibtop_init_r'. + + * src/daemon/main.c: Removed call to `glibtop_init_r'. + + * lib/open.c (glibtop_open_l): We now call the open function + of the sysdeps directory (glibtop_open_r) for server method + `GLIBTOP_METHOD_DIRECT'. + + * sysdeps/{linux, sun4, stub}/open.c: No longer `memset' + server to zero. + * src/daemon/slave.c: New file. * src/daemon/*.c: Done some more work on the daemon. diff --git a/lib/open.c b/lib/open.c index 783744ab..7bf1126b 100644 --- a/lib/open.c +++ b/lib/open.c @@ -43,6 +43,12 @@ glibtop_open_l (glibtop *server, const char *program_name, server->flags |= _GLIBTOP_INIT_STATE_OPEN; switch (server->method) { + case GLIBTOP_METHOD_DIRECT: + fprintf (stderr, "Calling sysdeps open function.\n"); + + glibtop_open_r (server, program_name, features, flags); + + break; case GLIBTOP_METHOD_INET: fprintf (stderr, "Connecting to '%s' port %ld.\n", server->server_host, server->server_port); diff --git a/src/daemon/gnuserv.c b/src/daemon/gnuserv.c index 18bff88c..cebe4431 100644 --- a/src/daemon/gnuserv.c +++ b/src/daemon/gnuserv.c @@ -35,6 +35,8 @@ #include #include +#include + #include "server_config.h" #include @@ -483,11 +485,13 @@ handle_signal (int sig) int main (int argc, char *argv []) { + glibtop *server = glibtop_global_server; + int ils = -1; /* internet domain listen socket */ int uls = -1; /* unix domain listen socket */ pid_t pid; - glibtop_init_r (&glibtop_global_server, 0, GLIBTOP_OPEN_NO_OVERRIDE); + glibtop_init_r (&glibtop_global_server, 0, GLIBTOP_INIT_NO_INIT); /* Fork a child. * @@ -504,6 +508,8 @@ main (int argc, char *argv []) glibtop_error_io ("fork failed"); else if (pid == 0) { /* We are the child. */ + + const unsigned method = GLIBTOP_METHOD_DIRECT; /* Temporarily drop our priviledges. */ @@ -523,8 +529,22 @@ main (int argc, char *argv []) /* get a unix domain socket to listen on. */ uls = unix_init (); #endif + + 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)); + + glibtop_init_r (&server, 0, 0); + } else { /* We are the parent. */ + + const unsigned method = GLIBTOP_METHOD_UNIX; + + const unsigned long features = GLIBTOP_SYSDEPS_ALL; /* If we are root, completely switch to SERVER_UID and * SERVER_GID. Otherwise we completely drop any priviledges. @@ -575,6 +595,15 @@ main (int argc, char *argv []) /* get a internet domain socket to listen on. */ ils = internet_init (); #endif + + glibtop_set_parameter_l (server, GLIBTOP_PARAM_METHOD, + &method, sizeof (method)); + + glibtop_set_parameter_l (server, GLIBTOP_PARAM_FEATURES, + &features, sizeof (features)); + + glibtop_init_r (&server, 0, 0); + } while (1) { diff --git a/src/daemon/main.c b/src/daemon/main.c index 6351e33e..a7d97f43 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -117,19 +117,9 @@ handle_parent_connection (int s) glibtop_response _resp, *resp = &_resp; glibtop_command _cmnd, *cmnd = &_cmnd; char parameter [BUFSIZ]; - unsigned method; pid_t pid; void *ptr; - 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))) { diff --git a/sysdeps/linux/open.c b/sysdeps/linux/open.c index f893c171..cf44cc3d 100644 --- a/sysdeps/linux/open.c +++ b/sysdeps/linux/open.c @@ -54,7 +54,6 @@ void glibtop_open_r (glibtop *server, const char *program_name, const unsigned long features, const unsigned flags) { - memset (server, 0, sizeof (glibtop)); server->name = program_name; set_linux_version (); diff --git a/sysdeps/stub/open.c b/sysdeps/stub/open.c index 7219ab1e..a45a6a60 100644 --- a/sysdeps/stub/open.c +++ b/sysdeps/stub/open.c @@ -27,6 +27,5 @@ void glibtop_open_r (glibtop *server, const char *program_name, const unsigned long features, const unsigned flags) { - memset (server, 0, sizeof (glibtop)); server->name = program_name; } diff --git a/sysdeps/sun4/open.c b/sysdeps/sun4/open.c index 4e5cc6bd..7f68913c 100644 --- a/sysdeps/sun4/open.c +++ b/sysdeps/sun4/open.c @@ -64,7 +64,6 @@ glibtop_open_r (glibtop *server, const char *program_name, /* !!! WE ARE ROOT HERE - CHANGE WITH CAUTION !!! */ - memset (server, 0, sizeof (glibtop)); server->name = program_name; server->machine.uid = getuid ();