From a5e2b65182c5e73f723f2b49d07aabfbe54ad112 Mon Sep 17 00:00:00 2001 From: Sree Harsha Totakura Date: Fri, 26 Apr 2013 08:47:58 +0000 Subject: [PATCH] - signal termination to peers when controller crashes --- src/testbed/Makefile.am | 7 +++++++ src/testbed/gnunet-helper-testbed.c | 12 ++++++++++-- src/testbed/test_testbed_api_testbed_run.c | 21 ++++++++++++++++++--- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am index 3802cfebe..e95dd3fa1 100644 --- a/src/testbed/Makefile.am +++ b/src/testbed/Makefile.am @@ -144,6 +144,7 @@ check_PROGRAMS = \ test_testbed_api_testbed_run_topologysmallworld \ test_testbed_api_testbed_run_topologyfromfile \ test_testbed_api_testbed_run_topologyscalefree \ + test_testbed_api_testbed_run_waitforever \ #Can be used for manual debugging test_testbed_api_statistics if ENABLE_TEST_RUN @@ -319,6 +320,12 @@ test_testbed_api_testbed_run_topologyscalefree_LDADD = \ $(top_builddir)/src/util/libgnunetutil.la \ libgnunettestbed.la +test_testbed_api_testbed_run_waitforever_SOURCES = \ + test_testbed_api_testbed_run.c +test_testbed_api_testbed_run_waitforever_LDADD = \ + $(top_builddir)/src/util/libgnunetutil.la \ + libgnunettestbed.la + test_testbed_api_statistics_SOURCES = \ test_testbed_api_statistics.c test_testbed_api_statistics_LDADD = \ diff --git a/src/testbed/gnunet-helper-testbed.c b/src/testbed/gnunet-helper-testbed.c index bdd8911de..be9154fdc 100644 --- a/src/testbed/gnunet-helper-testbed.c +++ b/src/testbed/gnunet-helper-testbed.c @@ -29,7 +29,10 @@ * This helper monitors for three termination events. They are: (1)The * stdin of the helper is closed for reading; (2)the helper received * SIGTERM/SIGINT; (3)the testbed crashed. In case of events 1 and 2 - * the helper kills the testbed service. + * the helper kills the testbed service. When testbed crashed (event + * 3), the helper should send a SIGTERM to its own process group; this + * behaviour will help terminate any child processes (peers) testbed + * has started and prevents them from leaking and running forever. * * @author Sree Harsha Totakura */ @@ -294,7 +297,12 @@ child_death_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { GNUNET_OS_process_destroy (testbed); testbed = NULL; - shutdown_now (); + /* Send SIGTERM to our process group */ + if (0 != PLIBC_KILL (0, SIGTERM)) + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "signal"); + shutdown_now (); /* Couldn't send the signal, we shutdown frowning */ + } return; } LOG_DEBUG ("Child hasn't died. Resuming to monitor its status\n"); diff --git a/src/testbed/test_testbed_api_testbed_run.c b/src/testbed/test_testbed_api_testbed_run.c index 293e77baf..5c69732a3 100644 --- a/src/testbed/test_testbed_api_testbed_run.c +++ b/src/testbed/test_testbed_api_testbed_run.c @@ -51,13 +51,18 @@ static GNUNET_SCHEDULER_TaskIdentifier abort_task; /** * Current peer id */ -unsigned int peer_id; +static unsigned int peer_id; /** * Testing result */ static int result; +/** + * Should we wait forever after testbed is initialized? + */ +static int wait_forever; + /** * Shutdown nicely @@ -85,7 +90,7 @@ do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); abort_task = GNUNET_SCHEDULER_NO_TASK; - GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); + (void) GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); } @@ -107,6 +112,14 @@ test_master (void *cls, unsigned int num_peers, unsigned int links_failed) { result = GNUNET_OK; + if (GNUNET_YES == wait_forever) + { + GNUNET_SCHEDULER_cancel (abort_task); + abort_task = GNUNET_SCHEDULER_NO_TASK; + (void) GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, + &do_shutdown, NULL); + return; + } GNUNET_assert (NULL != peers[0]); op = GNUNET_TESTBED_peer_stop (NULL, peers[0], NULL, NULL); GNUNET_assert (NULL != op); @@ -206,7 +219,9 @@ main (int argc, char **argv) GNUNET_break (0); /* Windows with no .exe? */ } #endif - if (0 != strcmp ("run", testname)) + if (0 == strcmp ("waitforever", testname)) + wait_forever = GNUNET_YES; + if ( (GNUNET_YES != wait_forever) && (0 != strcmp ("run", testname)) ) { GNUNET_asprintf (&config_filename, "test_testbed_api_testbed_run_%s.conf", testname); -- 2.25.1