NEWS update.
[paraslash.git] / server.c
index 73986f6df3bf00d080bd7b9e2f12f4efa2e9a5f1..90dfc1f58962f69355775fd87e4c08f8253efeac 100644 (file)
--- a/server.c
+++ b/server.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1997-2007 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 1997-2008 Andre Noll <maan@systemlinux.org>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
@@ -51,6 +51,7 @@
  *     - The object storage layer: \ref osl.c,
  *     - Blob tables: \ref blob.c,
  *     - The error subssystem: \ref error.h.
+ *     - Access control for paraslash senders: \ref acl.c, \ref acl.h.
  *
  * Low-level data structures:
  *
 #include "vss.h"
 #include "config.h"
 #include "close_on_fork.h"
+#include "list.h"
 #include "send.h"
 #include "net.h"
 #include "daemon.h"
 #include "ipc.h"
 #include "fd.h"
-#include "list.h"
 #include "sched.h"
 #include "signal.h"
 #include "user_list.h"
@@ -204,7 +205,7 @@ static void shm_init(void)
        mmd->sender_cmd_data.cmd_num = -1;
        return;
 err_out:
-       PARA_EMERG_LOG("%s", para_strerror(-ret));
+       PARA_EMERG_LOG("%s\n", para_strerror(-ret));
        exit(EXIT_FAILURE);
 }
 
@@ -262,12 +263,6 @@ static void parse_config(int override)
                server_cmdline_parser_config_file(cf, &conf, &params);
                conf.daemon_given = tmp;
        }
-       /* logfile */
-       if (!conf.logfile_given && conf.daemon_given) {
-               ret = -1;
-               PARA_EMERG_LOG("%s", "daemon, but no log file\n");
-               goto out;
-       }
        if (conf.logfile_given)
                logfile = open_log(conf.logfile_arg);
        ret = 1;
@@ -324,25 +319,30 @@ err:
 
 static void init_random_seed(void)
 {
-       int fd, ret = -1;
        unsigned int seed;
-       size_t len = sizeof(unsigned int);
+       int fd, ret = para_open("/dev/urandom", O_RDONLY, 0);
 
-       fd = open("/dev/urandom", O_RDONLY);
-       if (fd < 0)
+       if (ret < 0)
+               goto err;
+       fd = ret;
+       ret = read(fd, &seed, sizeof(seed));
+       if (ret < 0) {
+               ret = -ERRNO_TO_PARA_ERROR(errno);
                goto out;
-       ret = -2;
-       if (read(fd, &seed, len) != len)
+       }
+       if (ret != sizeof(seed)) {
+               ret = -ERRNO_TO_PARA_ERROR(EIO);
                goto out;
+       }
        srandom(seed);
        ret = 1;
 out:
-       if (fd >= 0)
-               close(fd);
-       if (ret > 0)
+       close(fd);
+       if (ret >= 0)
                return;
-       PARA_EMERG_LOG("can not seed pseudo random generator (ret = %d)\n",
-               ret);
+err:
+       PARA_EMERG_LOG("can not seed pseudo random number generator: %s\n",
+               para_strerror(-ret));
        exit(EXIT_FAILURE);
 }
 
@@ -375,7 +375,6 @@ static void init_afs(void)
                (unsigned) afs_socket_cookie);
 }
 
-
 static unsigned server_init(int argc, char **argv)
 {
        /* connector's address information */
@@ -398,11 +397,11 @@ static unsigned server_init(int argc, char **argv)
        PARA_NOTICE_LOG("initializing audio format handlers\n");
        afh_init();
        PARA_NOTICE_LOG("initializing virtual streaming system\n");
-       vss_init();
        mmd->server_pid = getpid();
        setup_signal_handling();
        PARA_NOTICE_LOG("initializing the audio file selector\n");
        init_afs();
+       vss_init();
        mmd_lock();
        /* init network socket */
        PARA_NOTICE_LOG("initializing tcp command socket\n");
@@ -416,7 +415,7 @@ static unsigned server_init(int argc, char **argv)
  */
 static void handle_sighup(void)
 {
-       PARA_NOTICE_LOG("%s", "SIGHUP\n");
+       PARA_NOTICE_LOG("SIGHUP\n");
        close_log(logfile); /* gets reopened if necessary by parse_config */
        logfile = NULL;
        parse_config(1); /* reopens log */
@@ -479,8 +478,6 @@ repeat:
        timeout = vss_preselect(&rfds, &wfds, &max_fileno);
        status_refresh();
        for (i = 0; senders[i].name; i++) {
-               if (senders[i].status != SENDER_ON)
-                       continue;
                if (!senders[i].pre_select)
                        continue;
                senders[i].pre_select(&max_fileno, &rfds, &wfds);
@@ -492,8 +489,6 @@ repeat:
        if (ret < 0)
                goto repeat;
        for (i = 0; senders[i].name; i++) {
-               if (senders[i].status != SENDER_ON)
-                       continue;
                if (!senders[i].post_select)
                        continue;
                senders[i].post_select(&rfds, &wfds);
@@ -553,7 +548,7 @@ genocide:
        random();
        chld_pid = fork();
        if (chld_pid < 0) {
-               PARA_CRIT_LOG("%s", "fork failed\n");
+               PARA_CRIT_LOG("fork failed\n");
                goto repeat;
        }
        if (chld_pid) {