X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=server.c;h=729ca1ac69d4f1f86a09359d315dc84e60e873cf;hb=5f04eea3b1c9a41417ed63e5348b2aabca5542fa;hp=e0d50f4f8689e1de283ef80f8341504bcf386d33;hpb=5459ae27b1efa26a1a47186c754a0e4cb486a278;p=paraslash.git diff --git a/server.c b/server.c index e0d50f4f..729ca1ac 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 @@ -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; /** @@ -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; @@ -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, @@ -643,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; } @@ -683,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); @@ -704,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();