testsuite: Introduce a new test for para_server.
[paraslash.git] / server.c
index e8dddf5bc27a80238436811b7d2b46680cddb3d7..1e45eb3616a858091f98f42079d94251963a43ed 100644 (file)
--- a/server.c
+++ b/server.c
  *     - Blob tables: \ref blob.c,
  *     - The error subssystem: \ref error.h.
  *     - Access control for paraslash senders: \ref acl.c, \ref acl.h.
+ *     - Internal crypto API: \ref crypt.h.
  *
  * Low-level data structures:
  *
  *     - Doubly linked lists: \ref list.h,
  *     - Ring buffer: \ref ringbuffer.c, \ref ringbuffer.h,
- *     - Crypto: \ref crypt.c, \ref crypt.h.
+ *     - openssl: \ref crypt.c
+ *     - libgcrypt: \ref gcrypt.c
  *     - Forward error correction: \ref fec.c.
  */
 
@@ -460,12 +462,6 @@ static int init_afs(void)
        return afs_server_socket[0];
 }
 
-__noreturn static void tmp_sigchld_handler(__a_unused int s)
-{
-       PARA_EMERG_LOG("caught early SIGCHLD\n");
-       exit(EXIT_FAILURE);
-}
-
 static void server_init(int argc, char **argv)
 {
        struct server_cmdline_parser_params params = {
@@ -489,8 +485,9 @@ static void server_init(int argc, char **argv)
        init_ipc_or_die(); /* init mmd struct and mmd->lock */
        /* make sure, the global now pointer is uptodate */
        gettimeofday(now, NULL);
-       server_uptime(UPTIME_SET); /* reset server uptime */
+       set_server_start_time(now);
        init_user_list(user_list_file);
+       init_server_command_task(argc, argv);
        /* become daemon */
        if (conf.daemon_given)
                daemonize();
@@ -506,24 +503,25 @@ static void server_init(int argc, char **argv)
         */
        para_sigaction(SIGUSR1, SIG_IGN);
        /*
-        * We have to install a SIGCHLD handler before the afs process is being
-        * forked off. Otherwise, para_server does not notice if afs dies before
-        * the SIGCHLD handler has been installed by init_signal_task() below.
+        * We have to block SIGCHLD before the afs process is being forked off.
+        * Otherwise, para_server does not notice if afs dies before the
+        * SIGCHLD handler has been installed for the parent process by
+        * init_signal_task() below.
         */
-       para_sigaction(SIGCHLD, tmp_sigchld_handler);
+       para_block_signal(SIGCHLD);
        PARA_NOTICE_LOG("initializing the audio file selector\n");
        afs_socket = init_afs();
        init_signal_task();
+       para_unblock_signal(SIGCHLD);
        PARA_NOTICE_LOG("initializing virtual streaming system\n");
        init_vss_task(afs_socket);
-       init_server_command_task(argc, argv);
        PARA_NOTICE_LOG("server init complete\n");
 }
 
 static void status_refresh(void)
 {
        static int prev_uptime = -1, prev_events = -1;
-       int uptime = server_uptime(UPTIME_GET), ret = 1;
+       int uptime = get_server_uptime(now);
 
        if (prev_events != mmd->events)
                goto out;
@@ -538,11 +536,8 @@ out:
        prev_uptime = uptime;
        prev_events = mmd->events;
        mmd->vss_status_flags = mmd->new_vss_status_flags;
-       if (ret) {
-               PARA_DEBUG_LOG("%d events, forcing status update\n",
-                       mmd->events);
-               killpg(0, SIGUSR1);
-       }
+       PARA_DEBUG_LOG("%d events, forcing status update\n", mmd->events);
+       killpg(0, SIGUSR1);
 }
 
 static int server_select(int max_fileno, fd_set *readfds, fd_set *writefds,