X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=server.c;h=fa19ce4225111e33ec7f192935f455c6cd5b2d76;hp=2595d9c4edaf649e9843150697855cbfe0c8d555;hb=d1e6b28f66e243516d01916f9125baee75dd98d6;hpb=f652ce6afe7f6fd0e42814505234cbf4321a736e diff --git a/server.c b/server.c index 2595d9c4..fa19ce42 100644 --- a/server.c +++ b/server.c @@ -1,75 +1,48 @@ /* - * Copyright (C) 1997-2013 Andre Noll + * Copyright (C) 1997-2014 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ /** \file server.c Paraslash's main server. */ - /** - * \mainpage Paraslash API Reference - * - * Starting points for getting an overview: - * + * \mainpage Main data structures: * - * - The main programs: \ref server.c, \ref audiod.c, \ref client.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, \ref writer_node. - * - * - * The gory details, listed by topic: + * - Audio file selector: \ref afs_info, \ref afs_table, + * - Audio format handler: \ref audio_format_handler, \ref afh_info + * - Receivers/filters/writers: \ref receiver, \ref receiver_node, + * \ref filter, \ref filter_node, \ref writer_node, \ref writer. * - * - Audio format handlers: \ref send_common.c \ref mp3_afh.c, - * \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, - * - udp: \ref udp_recv.c, \ref udp_send.c, - * - dccp: \ref dccp_recv.c, \ref dccp_send.c, - * - Audio file selector: \ref afs.c, \ref aft.c, \ref mood.c, - * - Afs structures: \ref afs_table, \ref audio_file_data, - * \ref afs_info \ref afh_info, - * - Afs tables: \ref aft.c, \ref mood.c, \ref playlist.c, - * \ref attribute.c, \ref score.c, - * - The virtual streaming system: \ref vss.c, \ref chunk_queue.c. + * Selected APIs: * - * Lower levels: - * - * - Scheduling: \ref sched.c, \ref sched.h, - * - Networking: \ref net.c, - * - File descriptors: \ref fd.c, - * - Signals: \ref signal.c, - * - Daemons: \ref daemon.c, - * - Strings: \ref string.c, \ref string.h, + * - Scheduling: \ref sched.h, + * - Buffer trees: \ref buffer_tree.h, + * - Sideband API: \ref sideband.h, + * - Crypto: \ref crypt.h, \ref crypt_backend.h, + * - Error subsystem: \ref error.h, \ref error2.c, + * - Inter process communication: \ref ipc.h, + * - Forward error correction: \ref fec.h, + * - Daemons: \ref daemon.h, + * - Mixer API: \ref mix.h, + * - Interactive sessions: \ref interactive.h, + * - File descriptors: \ref fd.h, + * - Signals: \ref signal.h, + * - Networking: \ref net.h, * - Time: \ref time.c, - * - Spawning processes: \ref exec.c, - * - Inter process communication: \ref ipc.c, - * - Blob tables: \ref blob.c, - * - 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: - * - * - Doubly linked lists: \ref list.h, - * - Ring buffer: \ref ringbuffer.c, \ref ringbuffer.h, - * - openssl: \ref crypt.c - * - libgcrypt: \ref gcrypt.c - * - Forward error correction: \ref fec.c. + * - Doubly linked lists: \ref list.h. */ +#include +#include #include -#include #include #include +#include +#include +#include +#include #include "para.h" #include "error.h" @@ -92,6 +65,7 @@ #include "signal.h" #include "user_list.h" #include "color.h" +#include "ggo.h" #include "version.h" __printf_2_3 void (*para_log)(int, const char*, ...) = daemon_log; @@ -237,13 +211,13 @@ void parse_config_or_die(int override) .print_errors = !conf.daemon_given }; server_cmdline_parser_config_file(cf, &conf, ¶ms); + daemon_set_loglevel(conf.loglevel_arg); conf.daemon_given = tmp; } if (conf.logfile_given) { daemon_set_logfile(conf.logfile_arg); daemon_open_log_or_die(); } - daemon_set_loglevel(conf.loglevel_arg); init_colors_or_die(); daemon_set_flag(DF_LOG_PID); daemon_set_flag(DF_LOG_LL); @@ -279,13 +253,13 @@ static void handle_sighup(void) kill(mmd->afs_pid, SIGHUP); } -static void signal_post_select(struct sched *s, __a_unused struct task *t) +static int signal_post_select(struct sched *s, __a_unused struct task *t) { int signum = para_next_signal(&s->rfds); switch (signum) { case 0: - return; + return 0; case SIGHUP: handle_sighup(); break; @@ -330,6 +304,7 @@ cleanup: shm_detach(mmd); exit(EXIT_FAILURE); } + return 0; } static void init_signal_task(void) @@ -358,7 +333,7 @@ static void command_pre_select(struct sched *s, struct task *t) para_fd_set(sct->listen_fd, &s->rfds, &s->max_fileno); } -static void command_post_select(struct sched *s, struct task *t) +static int command_post_select(struct sched *s, struct task *t) { struct server_command_task *sct = container_of(t, struct server_command_task, task); @@ -390,9 +365,12 @@ static void command_post_select(struct sched *s, struct task *t) goto out; } if (child_pid) { + /* avoid problems with non-fork-safe PRNGs */ + unsigned char buf[16]; + get_random_bytes_or_die(buf, sizeof(buf)); close(new_fd); /* parent keeps accepting connections */ - return; + return 0; } /* mmd might already have changed at this point */ free(chunk_table); @@ -406,10 +384,12 @@ static void command_post_select(struct sched *s, struct task *t) for (i = sct->argc - 1; i >= 0; i--) memset(sct->argv[i], 0, strlen(sct->argv[i])); sprintf(sct->argv[0], "para_server (serving %s)", peer_name); - return handle_connect(new_fd, peer_name); + handle_connect(new_fd, peer_name); + /* never reached*/ out: if (ret < 0) PARA_CRIT_LOG("%s\n", para_strerror(-ret)); + return 0; } static void init_server_command_task(int argc, char **argv) @@ -471,6 +451,15 @@ static int init_afs(int argc, char **argv) return afs_server_socket[0]; } +__noreturn static void print_help_and_die(void) +{ + struct ggo_help h = DEFINE_GGO_HELP(server); + bool d = conf.detailed_help_given; + + ggo_print_help(&h, d? GPH_STANDARD_FLAGS_DETAILED : GPH_STANDARD_FLAGS); + exit(0); +} + static void server_init(int argc, char **argv) { struct server_cmdline_parser_params params = { @@ -486,14 +475,17 @@ static void server_init(int argc, char **argv) init_random_seed_or_die(); /* parse command line options */ server_cmdline_parser_ext(argc, argv, &conf, ¶ms); - HANDLE_VERSION_FLAG("server", conf); + daemon_set_loglevel(conf.loglevel_arg); + version_handle_flag("server", conf.version_given); + if (conf.help_given || conf.detailed_help_given) + print_help_and_die(); drop_privileges_or_die(conf.user_arg, conf.group_arg); /* parse config file, open log and set defaults */ parse_config_or_die(0); 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); /* become daemon */