From 553da9baaee28de37ac70af6e59549cabdd18373 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 13 Jan 2017 13:23:38 +0100 Subject: [PATCH] implement -T option for gnunet-arm (#4854) --- src/arm/gnunet-arm.c | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/arm/gnunet-arm.c b/src/arm/gnunet-arm.c index 3b024ea93..b6f4d99a8 100644 --- a/src/arm/gnunet-arm.c +++ b/src/arm/gnunet-arm.c @@ -110,10 +110,14 @@ static unsigned int phase; /** * User defined timestamp for completing operations. - * FIXME: to be implemented! */ static struct GNUNET_TIME_Relative timeout; +/** + * Task to be run on timeout. + */ +static struct GNUNET_SCHEDULER_Task *timeout_task; + /** * Do we want to give our stdout to gnunet-service-arm? */ @@ -191,6 +195,11 @@ shutdown_task (void *cls) GNUNET_ARM_monitor_stop (m); m = NULL; } + if (NULL != timeout_task) + { + GNUNET_SCHEDULER_cancel (timeout_task); + timeout_task = NULL; + } if ((GNUNET_YES == end) && (GNUNET_YES == delete)) delete_files (); GNUNET_CONFIGURATION_destroy (cfg); @@ -682,6 +691,18 @@ srv_status (void *cls, } +/** + * Task run on timeout (if -T is given). + */ +static void +timeout_task_cb (void *cls) +{ + timeout_task = NULL; + ret = 2; + GNUNET_SCHEDULER_shutdown (); +} + + /** * Main function that will be run by the scheduler. * @@ -739,6 +760,10 @@ run (void *cls, NULL); GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); + if (0 != timeout.rel_value_us) + timeout_task = GNUNET_SCHEDULER_add_delayed (timeout, + &timeout_task_cb, + NULL); } @@ -747,7 +772,7 @@ run (void *cls, * * @param argc number of arguments from the command line * @param argv command line arguments - * @return 0 ok, 1 on error + * @return 0 ok, 1 on error, 2 on timeout */ int main (int argc, char *const *argv) @@ -793,10 +818,10 @@ main (int argc, char *const *argv) gettext_noop ("Control services and the Automated Restart Manager (ARM)"), options, &run, NULL)) - { - GNUNET_free ((void *) argv); - return ret; - } + { + GNUNET_free ((void *) argv); + return ret; + } GNUNET_free ((void*) argv); return 1; } -- 2.25.1