X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=server.c;h=57f0c26ee36e046e4390157f49352bb0e7fccf70;hp=0cfac60722d825fddb4714dfba651eb8265e770a;hb=24758c5f;hpb=ff70d3f74c6116cf5b3c9a6708218788363efa7c;ds=sidebyside diff --git a/server.c b/server.c index 0cfac607..57f0c26e 100644 --- a/server.c +++ b/server.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1997-2011 Andre Noll + * Copyright (C) 1997-2013 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -14,10 +14,11 @@ * * * - The main programs: \ref server.c, \ref audiod.c, \ref client.c, - * \ref audioc.c, \ref afh.c + * \ref audioc.c, \ref afh.c, \ref play.c, * - Server: \ref server_command, \ref sender, * - Audio file selector: \ref audio_format_handler, \ref afs_table, - * - Client: \ref receiver, \ref receiver_node, \ref filter, \ref filter_node. + * - Client: \ref receiver, \ref receiver_node, \ref filter, + * \ref filter_node, \ref writer_node. * * * The gory details, listed by topic: @@ -26,6 +27,7 @@ * \ref ogg_afh.c, \ref aac_afh.c, \ref wma_afh.c, \ref spx_afh.c * - Decoders: \ref mp3dec_filter.c, \ref oggdec_filter.c, * \ref aacdec_filter.c, \ref wmadec_filter.c, spxdec_filter.c, + * \ref flacdec_filter.c, * - Volume normalizer: \ref compress_filter.c, * - Output: \ref alsa_write.c, \ref osx_write.c, \ref oss_write.c, * - http: \ref http_recv.c, \ref http_send.c, @@ -50,9 +52,10 @@ * - Spawning processes: \ref exec.c, * - Inter process communication: \ref ipc.c, * - Blob tables: \ref blob.c, - * - The error subssystem: \ref error.h. + * - The error subsystem: \ref error.h. * - Access control for paraslash senders: \ref acl.c, \ref acl.h. * - Internal crypto API: \ref crypt.h. + * - interactive sessions (libreadline): \ref interactive.c. * * Low-level data structures: * @@ -64,10 +67,8 @@ */ #include -#include #include #include -#include #include "para.h" #include "error.h" @@ -79,6 +80,7 @@ #include "server.h" #include "list.h" #include "send.h" +#include "sched.h" #include "vss.h" #include "config.h" #include "close_on_fork.h" @@ -86,12 +88,13 @@ #include "daemon.h" #include "ipc.h" #include "fd.h" -#include "sched.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; @@ -121,6 +124,7 @@ int mmd_mutex; /** The file containing user information (public key, permissions). */ static char *user_list_file = NULL; +static struct sched sched; /** The task responsible for server command handling. */ struct server_command_task { @@ -344,7 +348,7 @@ static void init_signal_task(void) para_install_sighandler(SIGCHLD); para_sigaction(SIGPIPE, SIG_IGN); add_close_on_fork_list(st->fd); - register_task(&st->task); + register_task(&sched, &st->task); } static void command_pre_select(struct sched *s, struct task *t) @@ -427,7 +431,7 @@ static void init_server_command_task(int argc, char **argv) goto err; add_close_on_fork_list(sct->listen_fd); /* child doesn't need the listener */ sprintf(sct->task.status, "server command task"); - register_task(&sct->task); + register_task(&sched, &sct->task); return; err: PARA_EMERG_LOG("%s\n", para_strerror(-ret)); @@ -488,13 +492,12 @@ static void server_init(int argc, char **argv) log_welcome("para_server"); init_ipc_or_die(); /* init mmd struct and mmd->lock */ /* make sure, the global now pointer is uptodate */ - gettimeofday(now, NULL); + clock_get_realtime(now); set_server_start_time(now); init_user_list(user_list_file); - init_server_command_task(argc, argv); /* become daemon */ if (conf.daemon_given) - daemonize(); + daemonize(true /* parent waits for SIGTERM */); PARA_NOTICE_LOG("initializing audio format handlers\n"); afh_init(); @@ -518,7 +521,10 @@ static void server_init(int argc, char **argv) init_signal_task(); para_unblock_signal(SIGCHLD); PARA_NOTICE_LOG("initializing virtual streaming system\n"); - init_vss_task(afs_socket); + init_vss_task(afs_socket, &sched); + init_server_command_task(argc, argv); + if (conf.daemon_given) + kill(getppid(), SIGTERM); PARA_NOTICE_LOG("server init complete\n"); } @@ -567,16 +573,13 @@ static int server_select(int max_fileno, fd_set *readfds, fd_set *writefds, int main(int argc, char *argv[]) { int ret; - static struct sched s = { - .default_timeout = { - .tv_sec = 1, - .tv_usec = 0 - }, - .select_function = server_select - }; + + sched.default_timeout.tv_sec = 1; + sched.select_function = server_select; + server_init(argc, argv); mutex_lock(mmd_mutex); - ret = schedule(&s); + ret = schedule(&sched); if (ret < 0) { PARA_EMERG_LOG("%s\n", para_strerror(-ret)); exit(EXIT_FAILURE);