From: Andre Noll Date: Mon, 10 Sep 2007 21:10:19 +0000 (+0200) Subject: Fix afs_shutdown(). X-Git-Tag: v0.3.0~428 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=c8eeb1f82c5541c900191b840c90cc0585345bec;p=paraslash.git Fix afs_shutdown(). Unregister tasks as soon as we catch a terminating signal and call afs_shutdown() when sched() returns. --- diff --git a/afs.c b/afs.c index 21148f0e..d89406f3 100644 --- a/afs.c +++ b/afs.c @@ -524,11 +524,13 @@ static int setup_command_socket_or_die(void) } static int server_socket; +static struct command_task command_task_struct; +static struct signal_task signal_task_struct; -void loop(void) +static void unregister_tasks(void) { - for (;;) - sleep(1); + unregister_task(&command_task_struct.task); + unregister_task(&signal_task_struct.task); } static void afs_shutdown(enum osl_close_flags flags) @@ -563,13 +565,12 @@ static void signal_post_select(struct sched *s, struct task *t) t->ret = 1; if (st->signum == SIGUSR1) return; /* ignore SIGUSR1 */ - afs_shutdown(OSL_MARK_CLEAN); t->ret = -E_SIGNAL_CAUGHT; + unregister_tasks(); } static void register_signal_task(void) { - static struct signal_task signal_task_struct; struct signal_task *st = &signal_task_struct; st->fd = para_signal_init(); PARA_INFO_LOG("signal pipe: fd %d\n", st->fd); @@ -705,7 +706,6 @@ out: static void register_command_task(uint32_t cookie) { - static struct command_task command_task_struct; struct command_task *ct = &command_task_struct; ct->fd = setup_command_socket_or_die(); ct->cookie = cookie; @@ -800,8 +800,9 @@ __noreturn int afs_init(uint32_t cookie, int socket_fd) s.default_timeout.tv_sec = 0; s.default_timeout.tv_usec = 99 * 1000; ret = sched(&s); - assert(ret < 0); - PARA_EMERG_LOG("%s\n", PARA_STRERROR(-ret)); + if (ret < 0) + PARA_EMERG_LOG("%s\n", PARA_STRERROR(-ret)); + afs_shutdown(OSL_MARK_CLEAN); exit(EXIT_FAILURE); }