From f738653d179ec2f52e8d588fdd7396aaf39dcc7d Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 8 Dec 2009 13:46:21 +0000 Subject: [PATCH] fix --- src/arm/gnunet-service-arm.c | 86 +++++++++++++++++++++++++----------- 1 file changed, 59 insertions(+), 27 deletions(-) diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c index 834b36620..01f7f5b8a 100644 --- a/src/arm/gnunet-service-arm.c +++ b/src/arm/gnunet-service-arm.c @@ -685,6 +685,52 @@ handle_stop (void *cls, } +/** + * Remove all entries for tasks that are not running + * (pid = 0) from the running list (they will no longer + * be restarted since we are shutting down). + */ +static void +clean_up_running () +{ + struct ServiceList *pos; + struct ServiceList *next; + struct ServiceList *prev; + + pos = running; + prev = NULL; + while (NULL != pos) + { + next = pos->next; + if (pos->pid == 0) + { + if (prev == NULL) + running = next; + else + prev->next = next; + free_entry (pos); + } + pos = next; + } +} + + +/** + * We are done with everything. Stop remaining + * tasks, signal handler and the server. + */ +static void +do_shutdown () +{ + GNUNET_SERVER_destroy (server); + server = NULL; + GNUNET_SIGNAL_handler_uninstall (shc_chld); + shc_chld = NULL; + GNUNET_SCHEDULER_cancel (sched, child_death_task); + child_death_task = GNUNET_SCHEDULER_NO_TASK; +} + + /** * Task run for shutdown. * @@ -695,16 +741,12 @@ static void shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct ServiceList *pos; - struct ServiceList *next; - struct ServiceList *prev; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Stopping all services\n")); in_shutdown = GNUNET_YES; pos = running; - prev = NULL; while (NULL != pos) { - next = pos->next; if (pos->pid != 0) { #if DEBUG_ARM @@ -713,27 +755,11 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) #endif if (0 != PLIBC_KILL (pos->pid, SIGTERM)) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); - prev = pos; - } - else - { - if (prev == NULL) - running = next; - else - prev->next = next; - free_entry (pos); } - pos = next; + pos = pos->next; } if (running == NULL) - { - GNUNET_SERVER_destroy (server); - server = NULL; - GNUNET_SIGNAL_handler_uninstall (shc_chld); - shc_chld = NULL; - GNUNET_SCHEDULER_cancel (sched, child_death_task); - child_death_task = GNUNET_SCHEDULER_NO_TASK; - } + do_shutdown (); } @@ -751,7 +777,12 @@ delayed_restart_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) child_restart_task = GNUNET_SCHEDULER_NO_TASK; if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) - return; + { + clean_up_running (); + if (NULL == running) + do_shutdown (); + return; + } lowestRestartDelay = GNUNET_TIME_UNIT_FOREVER_REL; /* check for services that need to be restarted due to @@ -805,7 +836,7 @@ maint_child_death (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) char c; child_death_task = GNUNET_SCHEDULER_NO_TASK; - if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) + if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) { child_death_task = GNUNET_SCHEDULER_add_read_file (sched, GNUNET_TIME_UNIT_FOREVER_REL, pr, @@ -879,9 +910,10 @@ maint_child_death (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) if (GNUNET_SCHEDULER_NO_TASK != child_restart_task) GNUNET_SCHEDULER_cancel (sched, child_restart_task); child_restart_task - = GNUNET_SCHEDULER_add_now (sched, - &delayed_restart_task, - NULL); + = GNUNET_SCHEDULER_add_with_priority (sched, + GNUNET_SCHEDULER_PRIORITY_IDLE, + &delayed_restart_task, + NULL); } #if DEBUG_ARM else -- 2.25.1