server: Define server command task structure in main().
authorAndre Noll <maan@tuebingen.mpg.de>
Sun, 6 Aug 2017 21:39:02 +0000 (23:39 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Tue, 13 Mar 2018 02:28:10 +0000 (03:28 +0100)
This way it does not need to be static, and we can look at the
contents after schedule() returns.

Preparatory patch for shutting down cleanly on exit.

server.c

index e9c1f12..13082e7 100644 (file)
--- a/server.c
+++ b/server.c
@@ -410,11 +410,10 @@ out:
        return 0;
 }
 
-static void init_server_command_task(int argc, char **argv)
+static void init_server_command_task(struct server_command_task *sct,
+               int argc, char **argv)
 {
        int ret;
-       static struct server_command_task server_command_task_struct,
-               *sct = &server_command_task_struct;
 
        PARA_NOTICE_LOG("initializing tcp command socket\n");
        sct->argc = argc;
@@ -493,7 +492,7 @@ static void handle_help_flags(void)
        exit(EXIT_SUCCESS);
 }
 
-static void server_init(int argc, char **argv)
+static void server_init(int argc, char **argv, struct server_command_task *sct)
 {
        int ret, afs_socket, daemon_pipe = -1;
        char *errctx;
@@ -539,7 +538,7 @@ static void server_init(int argc, char **argv)
        para_unblock_signal(SIGCHLD);
        PARA_NOTICE_LOG("initializing virtual streaming system\n");
        vss_init(afs_socket, &sched);
-       init_server_command_task(argc, argv);
+       init_server_command_task(sct, argc, argv);
        if (daemon_pipe >= 0) {
                if (write(daemon_pipe, "\0", 1) < 0) {
                        PARA_EMERG_LOG("daemon_pipe: %s", strerror(errno));
@@ -602,11 +601,13 @@ static int server_select(int max_fileno, fd_set *readfds, fd_set *writefds,
 int main(int argc, char *argv[])
 {
        int ret;
+       struct server_command_task server_command_task_struct,
+               *sct = &server_command_task_struct;
 
        sched.default_timeout.tv_sec = 1;
        sched.select_function = server_select;
 
-       server_init(argc, argv);
+       server_init(argc, argv, sct);
        mutex_lock(mmd_mutex);
        ret = schedule(&sched);
        sched_shutdown(&sched);