X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=server.c;h=5da384d8a935f9e02f830b7aadf079c2701145fe;hb=e3a7e12639c34fd86d48a072beb48add8c498d09;hp=6370cefd086d8351f91e25c411142ba8fea4f65a;hpb=52cb435d3d628d27fa781b31519470eb5ef70a4a;p=paraslash.git diff --git a/server.c b/server.c index 6370cefd..5da384d8 100644 --- a/server.c +++ b/server.c @@ -2,31 +2,6 @@ /** \file server.c Paraslash's main server. */ -/** - * \mainpage Main data structures and selected APIs: - * - * - Senders: \ref sender, - * - 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. - * - 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, - * - 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, - * - Doubly linked lists: \ref list.h. - */ - #include #include #include @@ -49,8 +24,8 @@ #include "net.h" #include "server.h" #include "list.h" -#include "send.h" #include "sched.h" +#include "send.h" #include "vss.h" #include "config.h" #include "close_on_fork.h" @@ -110,7 +85,7 @@ static struct signal_task *signal_task; /** The process id of the audio file selector process. */ pid_t afs_pid = 0; -/* The the main server process (parent of afs and the command handlers). */ +/* The main server process (parent of afs and the command handlers). */ static pid_t server_pid; /** @@ -275,14 +250,14 @@ static void handle_sighup(void) kill(afs_pid, SIGHUP); } -static int signal_post_select(struct sched *s, __a_unused void *context) +static int signal_post_monitor(struct sched *s, __a_unused void *context) { int ret, signum; ret = task_get_notification(signal_task->task); if (ret < 0) return ret; - signum = para_next_signal(&s->rfds); + signum = para_next_signal(); switch (signum) { case 0: return 0; @@ -298,14 +273,14 @@ static int signal_post_select(struct sched *s, __a_unused void *context) if (pid != afs_pid) continue; PARA_EMERG_LOG("fatal: afs died\n"); - kill(0, SIGTERM); - goto cleanup; + goto genocide; } break; /* die on sigint/sigterm. Kill all children too. */ case SIGINT: case SIGTERM: PARA_EMERG_LOG("terminating on signal %d\n", signum); +genocide: kill(0, SIGTERM); /* * We must wait for all of our children to die. For the afs @@ -320,7 +295,6 @@ static int signal_post_select(struct sched *s, __a_unused void *context) while (wait(NULL) != -1 || errno != ECHILD) ; /* still at least one child alive */ mutex_lock(mmd_mutex); -cleanup: free(mmd->afd.afhi.chunk_table); task_notify_all(s, E_DEADLY_SIGNAL); return -E_DEADLY_SIGNAL; @@ -339,20 +313,20 @@ static void init_signal_task(void) add_close_on_fork_list(signal_task->fd); signal_task->task = task_register(&(struct task_info) { .name = "signal", - .pre_select = signal_pre_select, - .post_select = signal_post_select, + .pre_monitor = signal_pre_monitor, + .post_monitor = signal_post_monitor, .context = signal_task, }, &sched); } -static void command_pre_select(struct sched *s, void *context) +static void command_pre_monitor(struct sched *s, void *context) { unsigned n; struct server_command_task *sct = context; for (n = 0; n < sct->num_listen_fds; n++) - para_fd_set(sct->listen_fds[n], &s->rfds, &s->max_fileno); + sched_monitor_readfd(sct->listen_fds[n], s); } static int command_task_accept(unsigned listen_idx, struct sched *s, @@ -363,7 +337,7 @@ static int command_task_accept(unsigned listen_idx, struct sched *s, pid_t child_pid; uint32_t *chunk_table; - ret = para_accept(sct->listen_fds[listen_idx], &s->rfds, NULL, 0, &new_fd); + ret = para_accept(sct->listen_fds[listen_idx], NULL, 0, &new_fd); if (ret <= 0) goto out; mmd->num_connects++; @@ -409,7 +383,7 @@ static int command_task_accept(unsigned listen_idx, struct sched *s, /* * After we return, the scheduler calls server_select() with a minimal * timeout value, because the remaining tasks have a notification - * pending. Next it calls the ->post_select method of these tasks, + * pending. Next it calls the ->post_monitor method of these tasks, * which will return negative in view of the notification. This causes * schedule() to return as there are no more runnable tasks. * @@ -425,7 +399,7 @@ out: return 0; } -static int command_post_select(struct sched *s, void *context) +static int command_post_monitor(struct sched *s, void *context) { struct server_command_task *sct = context; unsigned n; @@ -433,15 +407,16 @@ static int command_post_select(struct sched *s, void *context) ret = task_get_notification(sct->task); if (ret < 0) - return ret; + goto fail; for (n = 0; n < sct->num_listen_fds; n++) { ret = command_task_accept(n, s, sct); - if (ret < 0) { - free(sct->listen_fds); - return ret; - } + if (ret < 0) + goto fail; } return 0; +fail: + free(sct->listen_fds); + return ret; } static void init_server_command_task(struct server_command_task *sct, @@ -484,8 +459,8 @@ static void init_server_command_task(struct server_command_task *sct, sct->task = task_register(&(struct task_info) { .name = "server command", - .pre_select = command_pre_select, - .post_select = command_post_select, + .pre_monitor = command_pre_monitor, + .post_monitor = command_post_monitor, .context = sct, }, &sched); /* @@ -583,9 +558,6 @@ static void server_init(int argc, char **argv, struct server_command_task *sct) init_ipc_or_die(); /* init mmd struct, mmd and log mutex */ daemon_set_start_time(); daemon_set_hooks(pre_log_hook, post_log_hook); - PARA_NOTICE_LOG("initializing audio format handlers\n"); - afh_init(); - /* * Although afs uses its own signal handling we must ignore SIGUSR1 * _before_ the afs child process gets born by init_afs() below. It's @@ -646,13 +618,13 @@ out: } static int server_select(int max_fileno, fd_set *readfds, fd_set *writefds, - struct timeval *timeout_tv) + int timeout) { int ret; status_refresh(); mutex_unlock(mmd_mutex); - ret = para_select(max_fileno + 1, readfds, writefds, timeout_tv); + ret = para_select(max_fileno + 1, readfds, writefds, timeout); mutex_lock(mmd_mutex); return ret; } @@ -686,7 +658,7 @@ int main(int argc, char *argv[]) struct server_command_task server_command_task_struct, *sct = &server_command_task_struct; - sched.default_timeout.tv_sec = 1; + sched.default_timeout = 1000; sched.select_function = server_select; server_init(argc, argv, sct); @@ -707,12 +679,13 @@ int main(int argc, char *argv[]) deplete_close_on_fork_list(); if (ret < 0) PARA_EMERG_LOG("%s\n", para_strerror(-ret)); + vss_shutdown(); } else { + vss_shutdown(); alarm(ALARM_TIMEOUT); close_listed_fds(); ret = handle_connect(sct->child_fd); } - vss_shutdown(); shm_detach(mmd); user_list_deplete(); free_lpr();