diff options
-rw-r--r-- | src/util/helper.c | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/src/util/helper.c b/src/util/helper.c index 9037660a8..a70d86f18 100644 --- a/src/util/helper.c +++ b/src/util/helper.c | |||
@@ -267,7 +267,8 @@ GNUNET_HELPER_wait (struct GNUNET_HELPER_Handle *h) | |||
267 | GNUNET_free (sh); | 267 | GNUNET_free (sh); |
268 | } | 268 | } |
269 | /* purge MST buffer */ | 269 | /* purge MST buffer */ |
270 | (void) GNUNET_SERVER_mst_receive (h->mst, NULL, NULL, 0, GNUNET_YES, GNUNET_NO); | 270 | if (NULL != h->mst) |
271 | (void) GNUNET_SERVER_mst_receive (h->mst, NULL, NULL, 0, GNUNET_YES, GNUNET_NO); | ||
271 | return ret; | 272 | return ret; |
272 | } | 273 | } |
273 | 274 | ||
@@ -439,10 +440,11 @@ start_helper (struct GNUNET_HELPER_Handle *h) | |||
439 | } | 440 | } |
440 | 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); |
441 | GNUNET_DISK_pipe_close_end (h->helper_in, GNUNET_DISK_PIPE_END_READ); | 442 | GNUNET_DISK_pipe_close_end (h->helper_in, GNUNET_DISK_PIPE_END_READ); |
442 | h->read_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 443 | if (NULL != h->mst) |
443 | h->fh_from_helper, | 444 | h->read_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, |
444 | &helper_read, | 445 | h->fh_from_helper, |
445 | h); | 446 | &helper_read, |
447 | h); | ||
446 | } | 448 | } |
447 | 449 | ||
448 | 450 | ||
@@ -490,7 +492,7 @@ GNUNET_HELPER_start (int with_control_pipe, | |||
490 | struct GNUNET_HELPER_Handle *h; | 492 | struct GNUNET_HELPER_Handle *h; |
491 | unsigned int c; | 493 | unsigned int c; |
492 | 494 | ||
493 | h = GNUNET_malloc (sizeof (struct GNUNET_HELPER_Handle)); | 495 | h = GNUNET_new (struct GNUNET_HELPER_Handle); |
494 | h->with_control_pipe = with_control_pipe; | 496 | h->with_control_pipe = with_control_pipe; |
495 | /* Lookup in libexec path only if we are starting gnunet helpers */ | 497 | /* Lookup in libexec path only if we are starting gnunet helpers */ |
496 | if (NULL != strstr (binary_name, "gnunet")) | 498 | if (NULL != strstr (binary_name, "gnunet")) |
@@ -503,7 +505,8 @@ GNUNET_HELPER_start (int with_control_pipe, | |||
503 | h->binary_argv[c] = GNUNET_strdup (binary_argv[c]); | 505 | h->binary_argv[c] = GNUNET_strdup (binary_argv[c]); |
504 | h->binary_argv[c] = NULL; | 506 | h->binary_argv[c] = NULL; |
505 | h->cb_cls = cb_cls; | 507 | h->cb_cls = cb_cls; |
506 | h->mst = GNUNET_SERVER_mst_create (cb, h->cb_cls); | 508 | if (NULL != cb) |
509 | h->mst = GNUNET_SERVER_mst_create (cb, h->cb_cls); | ||
507 | h->exp_cb = exp_cb; | 510 | h->exp_cb = exp_cb; |
508 | start_helper (h); | 511 | start_helper (h); |
509 | return h; | 512 | return h; |
@@ -537,7 +540,8 @@ GNUNET_HELPER_destroy (struct GNUNET_HELPER_Handle *h) | |||
537 | sh->cont (sh->cont_cls, GNUNET_SYSERR); | 540 | sh->cont (sh->cont_cls, GNUNET_SYSERR); |
538 | GNUNET_free (sh); | 541 | GNUNET_free (sh); |
539 | } | 542 | } |
540 | GNUNET_SERVER_mst_destroy (h->mst); | 543 | if (NULL != h->mst) |
544 | GNUNET_SERVER_mst_destroy (h->mst); | ||
541 | GNUNET_free (h->binary_name); | 545 | GNUNET_free (h->binary_name); |
542 | for (c = 0; h->binary_argv[c] != NULL; c++) | 546 | for (c = 0; h->binary_argv[c] != NULL; c++) |
543 | GNUNET_free (h->binary_argv[c]); | 547 | GNUNET_free (h->binary_argv[c]); |
@@ -582,19 +586,27 @@ helper_write (void *cls, | |||
582 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 586 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
583 | { | 587 | { |
584 | /* try again */ | 588 | /* try again */ |
585 | h->write_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 589 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
586 | h->fh_to_helper, &helper_write, h); | 590 | "Helper write triggered during shutdown, retrying\n"); |
591 | h->write_task = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, | ||
592 | h->fh_to_helper, &helper_write, h); | ||
587 | return; | 593 | return; |
588 | } | 594 | } |
589 | if (NULL == (sh = h->sh_head)) | 595 | if (NULL == (sh = h->sh_head)) |
596 | { | ||
597 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
598 | "Helper write had no work!\n"); | ||
590 | return; /* how did this happen? */ | 599 | return; /* how did this happen? */ |
600 | } | ||
591 | buf = (const char*) sh->msg; | 601 | buf = (const char*) sh->msg; |
592 | t = GNUNET_DISK_file_write (h->fh_to_helper, &buf[sh->wpos], ntohs (sh->msg->size) - sh->wpos); | 602 | t = GNUNET_DISK_file_write (h->fh_to_helper, |
593 | if (t <= 0) | 603 | &buf[sh->wpos], |
604 | ntohs (sh->msg->size) - sh->wpos); | ||
605 | if (-1 == t) | ||
594 | { | 606 | { |
595 | /* On write-error, restart the helper */ | 607 | /* On write-error, restart the helper */ |
596 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 608 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
597 | _("Error writing to `%s': %s\n"), | 609 | _("Error writing to `%s': %s\n"), |
598 | h->binary_name, | 610 | h->binary_name, |
599 | STRERROR (errno)); | 611 | STRERROR (errno)); |
600 | if (NULL != h->exp_cb) | 612 | if (NULL != h->exp_cb) |
@@ -603,6 +615,8 @@ helper_write (void *cls, | |||
603 | GNUNET_HELPER_stop (h, GNUNET_NO); | 615 | GNUNET_HELPER_stop (h, GNUNET_NO); |
604 | return; | 616 | return; |
605 | } | 617 | } |
618 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
619 | "Stopping and restarting helper task!\n"); | ||
606 | stop_helper (h, GNUNET_NO); | 620 | stop_helper (h, GNUNET_NO); |
607 | /* Restart the helper */ | 621 | /* Restart the helper */ |
608 | h->restart_task = | 622 | h->restart_task = |
@@ -610,6 +624,10 @@ helper_write (void *cls, | |||
610 | &restart_task, h); | 624 | &restart_task, h); |
611 | return; | 625 | return; |
612 | } | 626 | } |
627 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
628 | "Transmitted %u bytes to %s\n", | ||
629 | (unsigned int) t, | ||
630 | h->binary_name); | ||
613 | sh->wpos += t; | 631 | sh->wpos += t; |
614 | if (sh->wpos == ntohs (sh->msg->size)) | 632 | if (sh->wpos == ntohs (sh->msg->size)) |
615 | { | 633 | { |