diff options
Diffstat (limited to 'src/util/helper.c')
-rw-r--r-- | src/util/helper.c | 71 |
1 files changed, 28 insertions, 43 deletions
diff --git a/src/util/helper.c b/src/util/helper.c index 3ed1c7276..ecfe4ccfa 100644 --- a/src/util/helper.c +++ b/src/util/helper.c | |||
@@ -142,17 +142,17 @@ struct GNUNET_HELPER_Handle | |||
142 | /** | 142 | /** |
143 | * Task to read from the helper. | 143 | * Task to read from the helper. |
144 | */ | 144 | */ |
145 | struct GNUNET_SCHEDULER_Task * read_task; | 145 | struct GNUNET_SCHEDULER_Task *read_task; |
146 | 146 | ||
147 | /** | 147 | /** |
148 | * Task to read from the helper. | 148 | * Task to read from the helper. |
149 | */ | 149 | */ |
150 | struct GNUNET_SCHEDULER_Task * write_task; | 150 | struct GNUNET_SCHEDULER_Task *write_task; |
151 | 151 | ||
152 | /** | 152 | /** |
153 | * Restart task. | 153 | * Restart task. |
154 | */ | 154 | */ |
155 | struct GNUNET_SCHEDULER_Task * restart_task; | 155 | struct GNUNET_SCHEDULER_Task *restart_task; |
156 | 156 | ||
157 | /** | 157 | /** |
158 | * Does the helper support the use of a control pipe for signalling? | 158 | * Does the helper support the use of a control pipe for signalling? |
@@ -319,19 +319,10 @@ static void | |||
319 | helper_read (void *cls) | 319 | helper_read (void *cls) |
320 | { | 320 | { |
321 | struct GNUNET_HELPER_Handle *h = cls; | 321 | struct GNUNET_HELPER_Handle *h = cls; |
322 | const struct GNUNET_SCHEDULER_TaskContext *tc; | ||
323 | char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE] GNUNET_ALIGN; | 322 | char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE] GNUNET_ALIGN; |
324 | ssize_t t; | 323 | ssize_t t; |
325 | 324 | ||
326 | h->read_task = NULL; | 325 | h->read_task = NULL; |
327 | tc = GNUNET_SCHEDULER_get_task_context (); | ||
328 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
329 | { | ||
330 | /* try again */ | ||
331 | h->read_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | ||
332 | h->fh_from_helper, &helper_read, h); | ||
333 | return; | ||
334 | } | ||
335 | t = GNUNET_DISK_file_read (h->fh_from_helper, &buf, sizeof (buf)); | 326 | t = GNUNET_DISK_file_read (h->fh_from_helper, &buf, sizeof (buf)); |
336 | if (t < 0) | 327 | if (t < 0) |
337 | { | 328 | { |
@@ -348,9 +339,9 @@ helper_read (void *cls) | |||
348 | } | 339 | } |
349 | stop_helper (h, GNUNET_NO); | 340 | stop_helper (h, GNUNET_NO); |
350 | /* Restart the helper */ | 341 | /* Restart the helper */ |
351 | h->restart_task = GNUNET_SCHEDULER_add_delayed( | 342 | h->restart_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, |
352 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, | 343 | h->retry_back_off), |
353 | h->retry_back_off), &restart_task, h); | 344 | &restart_task, h); |
354 | return; | 345 | return; |
355 | } | 346 | } |
356 | if (0 == t) | 347 | if (0 == t) |
@@ -368,9 +359,10 @@ helper_read (void *cls) | |||
368 | } | 359 | } |
369 | stop_helper (h, GNUNET_NO); | 360 | stop_helper (h, GNUNET_NO); |
370 | /* Restart the helper */ | 361 | /* Restart the helper */ |
371 | h->restart_task = GNUNET_SCHEDULER_add_delayed( | 362 | h->restart_task |
372 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, | 363 | = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, |
373 | h->retry_back_off), &restart_task, h); | 364 | h->retry_back_off), |
365 | &restart_task, h); | ||
374 | return; | 366 | return; |
375 | } | 367 | } |
376 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 368 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -378,9 +370,13 @@ helper_read (void *cls) | |||
378 | (unsigned int) t, | 370 | (unsigned int) t, |
379 | h->binary_name); | 371 | h->binary_name); |
380 | h->read_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 372 | h->read_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, |
381 | h->fh_from_helper, &helper_read, h); | 373 | h->fh_from_helper, |
374 | &helper_read, h); | ||
382 | if (GNUNET_SYSERR == | 375 | if (GNUNET_SYSERR == |
383 | GNUNET_SERVER_mst_receive (h->mst, NULL, buf, t, GNUNET_NO, GNUNET_NO)) | 376 | GNUNET_SERVER_mst_receive (h->mst, |
377 | NULL, | ||
378 | buf, t, | ||
379 | GNUNET_NO, GNUNET_NO)) | ||
384 | { | 380 | { |
385 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 381 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
386 | _("Failed to parse inbound message from helper `%s'\n"), | 382 | _("Failed to parse inbound message from helper `%s'\n"), |
@@ -393,9 +389,9 @@ helper_read (void *cls) | |||
393 | } | 389 | } |
394 | stop_helper (h, GNUNET_NO); | 390 | stop_helper (h, GNUNET_NO); |
395 | /* Restart the helper */ | 391 | /* Restart the helper */ |
396 | h->restart_task = GNUNET_SCHEDULER_add_delayed( | 392 | h->restart_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, |
397 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, | 393 | h->retry_back_off), |
398 | h->retry_back_off), &restart_task, h); | 394 | &restart_task, h); |
399 | return; | 395 | return; |
400 | } | 396 | } |
401 | } | 397 | } |
@@ -416,9 +412,9 @@ start_helper (struct GNUNET_HELPER_Handle *h) | |||
416 | /* out of file descriptors? try again later... */ | 412 | /* out of file descriptors? try again later... */ |
417 | stop_helper (h, GNUNET_NO); | 413 | stop_helper (h, GNUNET_NO); |
418 | h->restart_task = | 414 | h->restart_task = |
419 | GNUNET_SCHEDULER_add_delayed( | 415 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, |
420 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, | 416 | h->retry_back_off), |
421 | h->retry_back_off), &restart_task, h); | 417 | &restart_task, h); |
422 | return; | 418 | return; |
423 | } | 419 | } |
424 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 420 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -437,9 +433,9 @@ start_helper (struct GNUNET_HELPER_Handle *h) | |||
437 | { | 433 | { |
438 | /* failed to start process? try again later... */ | 434 | /* failed to start process? try again later... */ |
439 | stop_helper (h, GNUNET_NO); | 435 | stop_helper (h, GNUNET_NO); |
440 | h->restart_task = GNUNET_SCHEDULER_add_delayed( | 436 | h->restart_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, |
441 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, | 437 | h->retry_back_off), |
442 | h->retry_back_off), &restart_task, h); | 438 | &restart_task, h); |
443 | return; | 439 | return; |
444 | } | 440 | } |
445 | GNUNET_DISK_pipe_close_end (h->helper_out, GNUNET_DISK_PIPE_END_WRITE); | 441 | GNUNET_DISK_pipe_close_end (h->helper_out, GNUNET_DISK_PIPE_END_WRITE); |
@@ -583,22 +579,11 @@ static void | |||
583 | helper_write (void *cls) | 579 | helper_write (void *cls) |
584 | { | 580 | { |
585 | struct GNUNET_HELPER_Handle *h = cls; | 581 | struct GNUNET_HELPER_Handle *h = cls; |
586 | const struct GNUNET_SCHEDULER_TaskContext *tc; | ||
587 | struct GNUNET_HELPER_SendHandle *sh; | 582 | struct GNUNET_HELPER_SendHandle *sh; |
588 | const char *buf; | 583 | const char *buf; |
589 | ssize_t t; | 584 | ssize_t t; |
590 | 585 | ||
591 | h->write_task = NULL; | 586 | h->write_task = NULL; |
592 | tc = GNUNET_SCHEDULER_get_task_context (); | ||
593 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
594 | { | ||
595 | /* try again */ | ||
596 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
597 | "Helper write triggered during shutdown, retrying\n"); | ||
598 | h->write_task = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, | ||
599 | h->fh_to_helper, &helper_write, h); | ||
600 | return; | ||
601 | } | ||
602 | if (NULL == (sh = h->sh_head)) | 587 | if (NULL == (sh = h->sh_head)) |
603 | { | 588 | { |
604 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 589 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -626,9 +611,9 @@ helper_write (void *cls) | |||
626 | "Stopping and restarting helper task!\n"); | 611 | "Stopping and restarting helper task!\n"); |
627 | stop_helper (h, GNUNET_NO); | 612 | stop_helper (h, GNUNET_NO); |
628 | /* Restart the helper */ | 613 | /* Restart the helper */ |
629 | h->restart_task = GNUNET_SCHEDULER_add_delayed( | 614 | h->restart_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, |
630 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, | 615 | h->retry_back_off), |
631 | h->retry_back_off), &restart_task, h); | 616 | &restart_task, h); |
632 | return; | 617 | return; |
633 | } | 618 | } |
634 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 619 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |