diff options
author | grothoff <grothoff@140774ce-b5e7-0310-ab8b-a85725594a96> | 2012-12-06 13:53:33 +0000 |
---|---|---|
committer | grothoff <grothoff@140774ce-b5e7-0310-ab8b-a85725594a96> | 2012-12-06 13:53:33 +0000 |
commit | 8c20f003bbf1fad7947d36baabbfcc75abe0a85c (patch) | |
tree | 09ecd26d65c0d5c639df6a8c285b6ccbc06d37ad /src | |
parent | bf9de52835cf7bef19de6317e2b350d7a990b2b8 (diff) |
-improving shutdown behavior
git-svn-id: https://gnunet.org/svn/gnunet@25296 140774ce-b5e7-0310-ab8b-a85725594a96
Diffstat (limited to 'src')
-rw-r--r-- | src/arm/gnunet-arm.c | 91 | ||||
-rw-r--r-- | src/consensus/gnunet-consensus.c | 42 | ||||
-rw-r--r-- | src/util/client.c | 13 | ||||
-rw-r--r-- | src/util/speedup.c | 5 |
4 files changed, 85 insertions, 66 deletions
diff --git a/src/arm/gnunet-arm.c b/src/arm/gnunet-arm.c index a37a78a26a..ca4193837e 100644 --- a/src/arm/gnunet-arm.c +++ b/src/arm/gnunet-arm.c @@ -128,12 +128,12 @@ static struct GNUNET_TIME_Relative timeout; /** * Do we want to give our stdout to gnunet-service-arm? */ -static unsigned int no_stdout = 0; +static unsigned int no_stdout; /** * Do we want to give our stderr to gnunet-service-arm? */ -static unsigned int no_stderr = 0; +static unsigned int no_stderr; /** @@ -206,8 +206,7 @@ confirm_cb (void *cls, FPRINTF (stderr, "%s", _("Unknown response code from ARM.\n")); break; } - GNUNET_SCHEDULER_add_continuation (&cps_loop, NULL, - GNUNET_SCHEDULER_REASON_PREREQ_DONE); + GNUNET_SCHEDULER_add_now (&cps_loop, NULL); } @@ -237,6 +236,50 @@ list_cb (void *cls, int result, unsigned int count, const char *const*list) /** + * Attempts to delete configuration file and SERVICEHOME + * on arm shutdown provided the end and delete options + * were specified when gnunet-arm was run. + */ +static void +delete_files () +{ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Will attempt to remove configuration file %s and service directory %s\n", + config_file, dir); + + if (UNLINK (config_file) != 0) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + _("Failed to remove configuration file %s\n"), config_file); + } + + if (GNUNET_DISK_directory_remove (dir) != GNUNET_OK) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + _("Failed to remove servicehome directory %s\n"), dir); + + } +} + + +/** + * Main continuation-passing-style loop. Runs the various + * jobs that we've been asked to do in order. + * + * @param cls closure, unused + * @param tc context, unused + */ +static void +shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + GNUNET_ARM_disconnect (h); + h = NULL; + if ((end == GNUNET_YES) && (delete == GNUNET_YES)) + delete_files (); +} + + +/** * Main function that will be run by the scheduler. * * @param cls closure @@ -264,35 +307,9 @@ run (void *cls, char *const *args, const char *cfgfile, ret = 1; return; } - GNUNET_SCHEDULER_add_continuation (&cps_loop, NULL, - GNUNET_SCHEDULER_REASON_PREREQ_DONE); -} - - -/** - * Attempts to delete configuration file and SERVICEHOME - * on arm shutdown provided the end and delete options - * were specified when gnunet-arm was run. - */ -static void -delete_files () -{ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Will attempt to remove configuration file %s and service directory %s\n", - config_file, dir); - - if (UNLINK (config_file) != 0) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Failed to remove configuration file %s\n"), config_file); - } - - if (GNUNET_DISK_directory_remove (dir) != GNUNET_OK) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Failed to remove servicehome directory %s\n"), dir); - - } + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, + &shutdown_task, NULL); + GNUNET_SCHEDULER_add_now (&cps_loop, NULL); } @@ -306,6 +323,10 @@ delete_files () static void cps_loop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { + if (NULL == h) + return; + if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) + return; while (1) { switch (phase++) @@ -393,9 +414,7 @@ cps_loop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) } /* Fall through */ default: /* last phase */ - GNUNET_ARM_disconnect (h); - if ((end == GNUNET_YES) && (delete == GNUNET_YES)) - delete_files (); + GNUNET_SCHEDULER_shutdown (); return; } } diff --git a/src/consensus/gnunet-consensus.c b/src/consensus/gnunet-consensus.c index 12d0965e94..bc518657e3 100644 --- a/src/consensus/gnunet-consensus.c +++ b/src/consensus/gnunet-consensus.c @@ -48,12 +48,6 @@ static struct GNUNET_DISK_FileHandle *stdin_fh; */ static GNUNET_SCHEDULER_TaskIdentifier stdin_tid = GNUNET_SCHEDULER_NO_TASK; -/** - * Element currently being sent to the service - */ -static struct GNUNET_CONSENSUS_Element *element; - - static void stdin_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); @@ -76,23 +70,22 @@ conclude_cb (void *cls, } - static void insert_done_cb (void *cls, int success) { + struct GNUNET_CONSENSUS_Element *element = cls; + + GNUNET_free (element); if (GNUNET_YES != success) { printf ("insert failed\n"); GNUNET_SCHEDULER_shutdown (); + return; } - - GNUNET_free (element); - GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == stdin_tid); - stdin_tid = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, stdin_fh, - &stdin_cb, NULL); + &stdin_cb, NULL); } @@ -107,10 +100,12 @@ stdin_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { char buf[1024]; char *ret; - ret = fgets (buf, 1024, stdin); + struct GNUNET_CONSENSUS_Element *element; stdin_tid = GNUNET_SCHEDULER_NO_TASK; - + if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) + return; /* we're done here */ + ret = fgets (buf, 1024, stdin); if (NULL == ret) { if (feof (stdin)) @@ -118,10 +113,6 @@ stdin_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) printf ("concluding ...\n"); GNUNET_CONSENSUS_conclude (consensus, GNUNET_TIME_UNIT_FOREVER_REL, conclude_cb, NULL); } - else - { - GNUNET_SCHEDULER_shutdown (); - } return; } @@ -131,11 +122,11 @@ stdin_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) element->type = 0; element->size = strlen(buf) + 1; element->data = &element[1]; - strcpy((char *) &element[1], buf); - - GNUNET_CONSENSUS_insert (consensus, element, insert_done_cb, NULL); + strcpy ((char *) &element[1], buf); + GNUNET_CONSENSUS_insert (consensus, element, &insert_done_cb, element); } + /** * Called when a new element was received from another peer, or an error occured. * @@ -157,6 +148,7 @@ cb (void *cls, return GNUNET_YES; } + /** * Function run on shutdown to clean up. * @@ -166,14 +158,12 @@ cb (void *cls, static void shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "shutting down\n"); - if (NULL == consensus) + if (NULL != consensus) { - return; + GNUNET_CONSENSUS_destroy (consensus); + consensus = NULL; } - - GNUNET_CONSENSUS_destroy (consensus); } diff --git a/src/util/client.c b/src/util/client.c index 81c696a7b6..69380c9b03 100644 --- a/src/util/client.c +++ b/src/util/client.c @@ -943,8 +943,16 @@ client_delayed_retry (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_CLIENT_TransmitHandle *th = cls; struct GNUNET_TIME_Relative delay; - + th->reconnect_task = GNUNET_SCHEDULER_NO_TASK; + if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) + { + /* give up, was shutdown */ + th->client->th = NULL; + th->notify (th->notify_cls, 0, NULL); + GNUNET_free (th); + return; + } th->client->connection = do_connect (th->client->service_name, th->client->cfg, th->client->attempts++); th->client->first_message = GNUNET_YES; @@ -1006,7 +1014,8 @@ client_notify (void *cls, size_t size, void *buf) delay = GNUNET_TIME_absolute_get_remaining (th->timeout); delay.rel_value /= 2; if ((GNUNET_YES != th->auto_retry) || (0 == --th->attempts_left) || - (delay.rel_value < 1)) + (delay.rel_value < 1)|| + (0 != (GNUNET_SCHEDULER_get_reason() & GNUNET_SCHEDULER_REASON_SHUTDOWN))) { LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmission failed %u times, giving up.\n", diff --git a/src/util/speedup.c b/src/util/speedup.c index 0a005c035c..e5f71d063b 100644 --- a/src/util/speedup.c +++ b/src/util/speedup.c @@ -83,8 +83,9 @@ GNUNET_SPEEDUP_stop_ ( ) GNUNET_SCHEDULER_cancel (speedup_task); speedup_task = GNUNET_SCHEDULER_NO_TASK; } - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Stopped execution speed up\n"); + if ((0 != interval.rel_value) && (0 != delta.rel_value)) + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Stopped execution speed up\n"); } |