diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2013-02-12 16:48:10 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2013-02-12 16:48:10 +0000 |
commit | 2bf2b354ad536d1c743097313837b6c14b321815 (patch) | |
tree | 74340ac03972d3e265059d6639c532f03449a820 /src/util | |
parent | c616caf93688874d0f315209793e6f9c9b22a7cc (diff) | |
download | gnunet-2bf2b354ad536d1c743097313837b6c14b321815.tar.gz gnunet-2bf2b354ad536d1c743097313837b6c14b321815.zip |
stop helpers by closing stdin
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/helper.c | 60 |
1 files changed, 49 insertions, 11 deletions
diff --git a/src/util/helper.c b/src/util/helper.c index 0810fe180..d7a3cb271 100644 --- a/src/util/helper.c +++ b/src/util/helper.c | |||
@@ -165,15 +165,26 @@ struct GNUNET_HELPER_Handle | |||
165 | * Stop the helper process, we're closing down or had an error. | 165 | * Stop the helper process, we're closing down or had an error. |
166 | * | 166 | * |
167 | * @param h handle to the helper process | 167 | * @param h handle to the helper process |
168 | * @param soft_kill if GNUNET_YES, signals termination by closing the helper's | ||
169 | * stdin; GNUNET_NO to signal termination by sending SIGTERM to helper | ||
168 | */ | 170 | */ |
169 | static void | 171 | static void |
170 | stop_helper (struct GNUNET_HELPER_Handle *h) | 172 | stop_helper (struct GNUNET_HELPER_Handle *h, int soft_kill) |
171 | { | 173 | { |
172 | struct GNUNET_HELPER_SendHandle *sh; | 174 | struct GNUNET_HELPER_SendHandle *sh; |
173 | 175 | ||
174 | if (NULL != h->helper_proc) | 176 | if (NULL != h->helper_proc) |
175 | { | 177 | { |
176 | GNUNET_break (0 == GNUNET_OS_process_kill (h->helper_proc, SIGTERM)); | 178 | if (GNUNET_YES == soft_kill) |
179 | { | ||
180 | /* soft-kill only possible with pipes */ | ||
181 | GNUNET_assert (NULL != h->helper_in); | ||
182 | GNUNET_DISK_pipe_close (h->helper_in); | ||
183 | h->helper_in = NULL; | ||
184 | h->fh_to_helper = NULL; | ||
185 | } | ||
186 | else | ||
187 | GNUNET_break (0 == GNUNET_OS_process_kill (h->helper_proc, SIGTERM)); | ||
177 | GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (h->helper_proc)); | 188 | GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (h->helper_proc)); |
178 | GNUNET_OS_process_destroy (h->helper_proc); | 189 | GNUNET_OS_process_destroy (h->helper_proc); |
179 | h->helper_proc = NULL; | 190 | h->helper_proc = NULL; |
@@ -266,7 +277,7 @@ helper_read (void *cls, | |||
266 | GNUNET_HELPER_stop (h); | 277 | GNUNET_HELPER_stop (h); |
267 | return; | 278 | return; |
268 | } | 279 | } |
269 | stop_helper (h); | 280 | stop_helper (h, GNUNET_NO); |
270 | /* Restart the helper */ | 281 | /* Restart the helper */ |
271 | h->restart_task = | 282 | h->restart_task = |
272 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &restart_task, h); | 283 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &restart_task, h); |
@@ -285,7 +296,7 @@ helper_read (void *cls, | |||
285 | GNUNET_HELPER_stop (h); | 296 | GNUNET_HELPER_stop (h); |
286 | return; | 297 | return; |
287 | } | 298 | } |
288 | stop_helper (h); | 299 | stop_helper (h, GNUNET_NO); |
289 | /* Restart the helper */ | 300 | /* Restart the helper */ |
290 | h->restart_task = | 301 | h->restart_task = |
291 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 302 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
@@ -310,7 +321,7 @@ helper_read (void *cls, | |||
310 | GNUNET_HELPER_stop (h); | 321 | GNUNET_HELPER_stop (h); |
311 | return; | 322 | return; |
312 | } | 323 | } |
313 | stop_helper (h); | 324 | stop_helper (h, GNUNET_NO); |
314 | /* Restart the helper */ | 325 | /* Restart the helper */ |
315 | h->restart_task = | 326 | h->restart_task = |
316 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 327 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
@@ -333,7 +344,7 @@ start_helper (struct GNUNET_HELPER_Handle *h) | |||
333 | if ( (h->helper_in == NULL) || (h->helper_out == NULL)) | 344 | if ( (h->helper_in == NULL) || (h->helper_out == NULL)) |
334 | { | 345 | { |
335 | /* out of file descriptors? try again later... */ | 346 | /* out of file descriptors? try again later... */ |
336 | stop_helper (h); | 347 | stop_helper (h, GNUNET_NO); |
337 | h->restart_task = | 348 | h->restart_task = |
338 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 349 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
339 | &restart_task, h); | 350 | &restart_task, h); |
@@ -354,7 +365,7 @@ start_helper (struct GNUNET_HELPER_Handle *h) | |||
354 | if (NULL == h->helper_proc) | 365 | if (NULL == h->helper_proc) |
355 | { | 366 | { |
356 | /* failed to start process? try again later... */ | 367 | /* failed to start process? try again later... */ |
357 | stop_helper (h); | 368 | stop_helper (h, GNUNET_NO); |
358 | h->restart_task = | 369 | h->restart_task = |
359 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 370 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
360 | &restart_task, h); | 371 | &restart_task, h); |
@@ -437,9 +448,11 @@ GNUNET_HELPER_start (int with_control_pipe, | |||
437 | * @brief Kills the helper, closes the pipe and frees the h | 448 | * @brief Kills the helper, closes the pipe and frees the h |
438 | * | 449 | * |
439 | * @param h h to helper to stop | 450 | * @param h h to helper to stop |
451 | * @param soft_kill if GNUNET_YES, signals termination by closing the helper's | ||
452 | * stdin; GNUNET_NO to signal termination by sending SIGTERM to helper | ||
440 | */ | 453 | */ |
441 | void | 454 | static void |
442 | GNUNET_HELPER_stop (struct GNUNET_HELPER_Handle *h) | 455 | kill_helper (struct GNUNET_HELPER_Handle *h, int soft_kill) |
443 | { | 456 | { |
444 | struct GNUNET_HELPER_SendHandle *sh; | 457 | struct GNUNET_HELPER_SendHandle *sh; |
445 | unsigned int c; | 458 | unsigned int c; |
@@ -455,7 +468,7 @@ GNUNET_HELPER_stop (struct GNUNET_HELPER_Handle *h) | |||
455 | sh->cont (sh->cont_cls, GNUNET_SYSERR); | 468 | sh->cont (sh->cont_cls, GNUNET_SYSERR); |
456 | GNUNET_free (sh); | 469 | GNUNET_free (sh); |
457 | } | 470 | } |
458 | stop_helper (h); | 471 | stop_helper (h, soft_kill); |
459 | GNUNET_SERVER_mst_destroy (h->mst); | 472 | GNUNET_SERVER_mst_destroy (h->mst); |
460 | GNUNET_free (h->binary_name); | 473 | GNUNET_free (h->binary_name); |
461 | for (c = 0; h->binary_argv[c] != NULL; c++) | 474 | for (c = 0; h->binary_argv[c] != NULL; c++) |
@@ -466,6 +479,31 @@ GNUNET_HELPER_stop (struct GNUNET_HELPER_Handle *h) | |||
466 | 479 | ||
467 | 480 | ||
468 | /** | 481 | /** |
482 | * Kills the helper, closes the pipe and frees the handle | ||
483 | * | ||
484 | * @param h handle to helper to stop | ||
485 | */ | ||
486 | void | ||
487 | GNUNET_HELPER_stop (struct GNUNET_HELPER_Handle *h) | ||
488 | { | ||
489 | kill_helper (h, GNUNET_NO); | ||
490 | } | ||
491 | |||
492 | |||
493 | /** | ||
494 | * Kills the helper by closing its stdin (the helper is expected to catch the | ||
495 | * resulting SIGPIPE and shutdown), closes the pipe and frees the handle | ||
496 | * | ||
497 | * @param h handle to helper to stop | ||
498 | */ | ||
499 | void | ||
500 | GNUNET_HELPER_soft_stop (struct GNUNET_HELPER_Handle *h) | ||
501 | { | ||
502 | kill_helper (h, GNUNET_YES); | ||
503 | } | ||
504 | |||
505 | |||
506 | /** | ||
469 | * Write to the helper-process | 507 | * Write to the helper-process |
470 | * | 508 | * |
471 | * @param cls handle to the helper process | 509 | * @param cls handle to the helper process |
@@ -505,7 +543,7 @@ helper_write (void *cls, | |||
505 | GNUNET_HELPER_stop (h); | 543 | GNUNET_HELPER_stop (h); |
506 | return; | 544 | return; |
507 | } | 545 | } |
508 | stop_helper (h); | 546 | stop_helper (h, GNUNET_NO); |
509 | /* Restart the helper */ | 547 | /* Restart the helper */ |
510 | h->restart_task = | 548 | h->restart_task = |
511 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 549 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |