diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-12-27 13:12:27 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-12-27 13:12:27 +0000 |
commit | 757758f550b09e431ab6e1e6ba7681d71ce3599f (patch) | |
tree | ec8d72b1e74ca741124336b6bc79ff1d8bbbc7d2 | |
parent | c2fd39a9681e72dc37f8a11ee1a60287c70dbcc2 (diff) | |
download | gnunet-757758f550b09e431ab6e1e6ba7681d71ce3599f.tar.gz gnunet-757758f550b09e431ab6e1e6ba7681d71ce3599f.zip |
- fix crash when controller dies
-rw-r--r-- | src/testbed/testbed_api_testbed.c | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/src/testbed/testbed_api_testbed.c b/src/testbed/testbed_api_testbed.c index 3bc92bc2b..02127538c 100644 --- a/src/testbed/testbed_api_testbed.c +++ b/src/testbed/testbed_api_testbed.c | |||
@@ -339,6 +339,15 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
339 | GNUNET_assert (NULL == rc->peers); | 339 | GNUNET_assert (NULL == rc->peers); |
340 | GNUNET_assert (NULL == rc->hc_handles); | 340 | GNUNET_assert (NULL == rc->hc_handles); |
341 | GNUNET_assert (RC_PEERS_DESTROYED == rc->state); | 341 | GNUNET_assert (RC_PEERS_DESTROYED == rc->state); |
342 | if (NULL != rc->dll_op_head) | ||
343 | { /* cancel our pending operations */ | ||
344 | while (NULL != (dll_op = rc->dll_op_head)) | ||
345 | { | ||
346 | GNUNET_TESTBED_operation_done (dll_op->op); | ||
347 | GNUNET_CONTAINER_DLL_remove (rc->dll_op_head, rc->dll_op_tail, dll_op); | ||
348 | GNUNET_free (dll_op); | ||
349 | } | ||
350 | } | ||
342 | if (NULL != rc->c) | 351 | if (NULL != rc->c) |
343 | GNUNET_TESTBED_controller_disconnect (rc->c); | 352 | GNUNET_TESTBED_controller_disconnect (rc->c); |
344 | if (NULL != rc->cproc) | 353 | if (NULL != rc->cproc) |
@@ -348,17 +357,6 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
348 | for (hid = 0; hid < rc->num_hosts; hid++) | 357 | for (hid = 0; hid < rc->num_hosts; hid++) |
349 | GNUNET_TESTBED_host_destroy (rc->hosts[hid]); | 358 | GNUNET_TESTBED_host_destroy (rc->hosts[hid]); |
350 | GNUNET_free_non_null (rc->hosts); | 359 | GNUNET_free_non_null (rc->hosts); |
351 | if (NULL != rc->dll_op_head) | ||
352 | { | ||
353 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
354 | _("Some operations are still pending. Cancelling them\n")); | ||
355 | while (NULL != (dll_op = rc->dll_op_head)) | ||
356 | { | ||
357 | GNUNET_TESTBED_operation_done (dll_op->op); | ||
358 | GNUNET_CONTAINER_DLL_remove (rc->dll_op_head, rc->dll_op_tail, dll_op); | ||
359 | GNUNET_free (dll_op); | ||
360 | } | ||
361 | } | ||
362 | if (NULL != rc->cfg) | 360 | if (NULL != rc->cfg) |
363 | GNUNET_CONFIGURATION_destroy (rc->cfg); | 361 | GNUNET_CONFIGURATION_destroy (rc->cfg); |
364 | GNUNET_free_non_null (rc->topo_file); | 362 | GNUNET_free_non_null (rc->topo_file); |
@@ -401,6 +399,7 @@ shutdown_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
401 | { | 399 | { |
402 | struct RunContext *rc = cls; | 400 | struct RunContext *rc = cls; |
403 | struct DLLOperation *dll_op; | 401 | struct DLLOperation *dll_op; |
402 | int all_peers_destroyed; | ||
404 | unsigned int peer; | 403 | unsigned int peer; |
405 | unsigned int nhost; | 404 | unsigned int nhost; |
406 | 405 | ||
@@ -440,6 +439,8 @@ shutdown_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
440 | /* Check if some peers are stopped */ | 439 | /* Check if some peers are stopped */ |
441 | for (peer = 0; peer < rc->num_peers; peer++) | 440 | for (peer = 0; peer < rc->num_peers; peer++) |
442 | { | 441 | { |
442 | if (NULL == rc->peers[peer]) | ||
443 | continue; | ||
443 | if (PS_STOPPED != rc->peers[peer]->state) | 444 | if (PS_STOPPED != rc->peers[peer]->state) |
444 | break; | 445 | break; |
445 | } | 446 | } |
@@ -447,19 +448,24 @@ shutdown_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
447 | { | 448 | { |
448 | /* All peers are stopped */ | 449 | /* All peers are stopped */ |
449 | rc->state = RC_PEERS_STOPPED; | 450 | rc->state = RC_PEERS_STOPPED; |
451 | all_peers_destroyed = GNUNET_YES; | ||
450 | for (peer = 0; peer < rc->num_peers; peer++) | 452 | for (peer = 0; peer < rc->num_peers; peer++) |
451 | { | 453 | { |
454 | if (NULL == rc->peers[peer]) | ||
455 | continue; | ||
456 | all_peers_destroyed = GNUNET_NO; | ||
452 | dll_op = GNUNET_malloc (sizeof (struct DLLOperation)); | 457 | dll_op = GNUNET_malloc (sizeof (struct DLLOperation)); |
453 | dll_op->op = GNUNET_TESTBED_peer_destroy (rc->peers[peer]); | 458 | dll_op->op = GNUNET_TESTBED_peer_destroy (rc->peers[peer]); |
454 | GNUNET_CONTAINER_DLL_insert_tail (rc->dll_op_head, rc->dll_op_tail, | 459 | GNUNET_CONTAINER_DLL_insert_tail (rc->dll_op_head, rc->dll_op_tail, |
455 | dll_op); | 460 | dll_op); |
456 | } | 461 | } |
457 | return; | 462 | if (all_peers_destroyed == GNUNET_NO) |
463 | return; | ||
458 | } | 464 | } |
459 | /* Some peers are stopped */ | 465 | /* Some peers are stopped */ |
460 | for (peer = 0; peer < rc->num_peers; peer++) | 466 | for (peer = 0; peer < rc->num_peers; peer++) |
461 | { | 467 | { |
462 | if (PS_STARTED != rc->peers[peer]->state) | 468 | if ((NULL == rc->peers[peer]) || (PS_STARTED != rc->peers[peer]->state)) |
463 | { | 469 | { |
464 | rc->peer_count++; | 470 | rc->peer_count++; |
465 | continue; | 471 | continue; |
@@ -472,7 +478,9 @@ shutdown_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
472 | } | 478 | } |
473 | if (rc->peer_count != rc->num_peers) | 479 | if (rc->peer_count != rc->num_peers) |
474 | return; | 480 | return; |
475 | } | 481 | GNUNET_free (rc->peers); |
482 | rc->peers = NULL; | ||
483 | } | ||
476 | } | 484 | } |
477 | rc->state = RC_PEERS_DESTROYED; /* No peers are present so we consider the | 485 | rc->state = RC_PEERS_DESTROYED; /* No peers are present so we consider the |
478 | * state where all peers are destroyed */ | 486 | * state where all peers are destroyed */ |
@@ -805,7 +813,8 @@ controller_status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
805 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Testbed startup failed\n"); | 813 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Testbed startup failed\n"); |
806 | return; | 814 | return; |
807 | default: | 815 | default: |
808 | shutdown_now (rc); | 816 | rc->cproc = NULL; |
817 | shutdown_now (rc); | ||
809 | return; | 818 | return; |
810 | } | 819 | } |
811 | } | 820 | } |