X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Futil%2Fhelper.c;h=d4d26ba5138b70cb4b649216c503c22afd376c28;hb=f491ac4fab469421986f77df0bbf79fefc417786;hp=c47b201c575832cb33bfd62a2ba72affaa27c473;hpb=1ac29e62ba9db3cac4d382a6ab629d6249cf58ad;p=oweals%2Fgnunet.git diff --git a/src/util/helper.c b/src/util/helper.c index c47b201c5..d4d26ba51 100644 --- a/src/util/helper.c +++ b/src/util/helper.c @@ -152,7 +152,7 @@ stop_helper (struct GNUNET_HELPER_Handle *h) if (NULL != h->helper_proc) { - GNUNET_OS_process_kill (h->helper_proc, SIGKILL); + GNUNET_OS_process_kill (h->helper_proc, SIGTERM); GNUNET_OS_process_wait (h->helper_proc); GNUNET_OS_process_close (h->helper_proc); h->helper_proc = NULL; @@ -218,7 +218,7 @@ static void helper_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tsdkctx) { - struct GNUNET_HELPER_Handle*h = cls; + struct GNUNET_HELPER_Handle *h = cls; char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE]; ssize_t t; @@ -231,7 +231,7 @@ helper_read (void *cls, return; } t = GNUNET_DISK_file_read (h->fh_from_helper, &buf, sizeof (buf)); - if (t <= 0) + if (t < 0) { /* On read-error, restart the helper */ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, @@ -245,6 +245,20 @@ helper_read (void *cls, &restart_task, h); return; } + if (0 == t) + { + /* this happens if the helper is shut down via a + signal, so it is not a "hard" error */ + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + _("Got 0 bytes from helper `%s' (EOF)\n"), + h->binary_name); + stop_helper (h); + /* Restart the helper */ + h->restart_task = + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, + &restart_task, h); + return; + } if (GNUNET_SYSERR == GNUNET_SERVER_mst_receive (h->mst, NULL, buf, t, GNUNET_NO, GNUNET_NO)) { @@ -285,10 +299,8 @@ start_helper (struct GNUNET_HELPER_Handle *h) } h->fh_from_helper = GNUNET_DISK_pipe_handle (h->helper_out, GNUNET_DISK_PIPE_END_READ); - GNUNET_DISK_pipe_close_end (h->helper_out, GNUNET_DISK_PIPE_END_WRITE); h->fh_to_helper = GNUNET_DISK_pipe_handle (h->helper_in, GNUNET_DISK_PIPE_END_WRITE); - GNUNET_DISK_pipe_close_end (h->helper_in, GNUNET_DISK_PIPE_END_READ); h->helper_proc = GNUNET_OS_start_process_vap (h->helper_in, h->helper_out, h->binary_name, @@ -302,6 +314,8 @@ start_helper (struct GNUNET_HELPER_Handle *h) &restart_task, h); return; } + GNUNET_DISK_pipe_close_end (h->helper_out, GNUNET_DISK_PIPE_END_WRITE); + GNUNET_DISK_pipe_close_end (h->helper_in, GNUNET_DISK_PIPE_END_READ); h->read_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, h->fh_from_helper, &helper_read,