* - 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.
*/
#include <signal.h>
-#include <dirent.h>
#include <sys/time.h>
#include <regex.h>
#include <osl.h>
#include "signal.h"
#include "user_list.h"
#include "color.h"
+#include "version.h"
+
+__printf_2_3 void (*para_log)(int, const char*, ...) = daemon_log;
/** Define the array of error lists needed by para_server. */
INIT_SERVER_ERRLISTS;
exit(EXIT_FAILURE);
}
-static int init_afs(void)
+static int init_afs(int argc, char **argv)
{
int ret, afs_server_socket[2];
pid_t afs_pid;
if (afs_pid < 0)
exit(EXIT_FAILURE);
if (afs_pid == 0) { /* child (afs) */
+ int i;
+ for (i = argc - 1; i >= 0; i--)
+ memset(argv[i], 0, strlen(argv[i]));
+ sprintf(argv[0], "para_server (afs)");
close(afs_server_socket[0]);
afs_init(afs_socket_cookie, afs_server_socket[1]);
}
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 = {
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);
/* become daemon */
if (conf.daemon_given)
- daemonize();
+ daemonize(true /* parent waits for SIGTERM */);
PARA_NOTICE_LOG("initializing audio format handlers\n");
afh_init();
*/
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();
+ afs_socket = init_afs(argc, argv);
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);
+ if (conf.daemon_given)
+ kill(getppid(), SIGTERM);
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;
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,