+/**
+ * Task triggered whenever we receive a SIGCHLD (child
+ * process died).
+ *
+ * @param cls closure, NULL if we need to self-restart
+ */
+static void
+child_death_task (void *cls)
+{
+ const struct GNUNET_DISK_FileHandle *pr;
+ char c[16];
+ enum GNUNET_OS_ProcessStatusType type;
+ unsigned long code;
+ int ret;
+
+ pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ);
+ child_death_task_id = NULL;
+ /* consume the signal */
+ GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof (c)));
+ LOG_DEBUG ("Got SIGCHLD\n");
+ if (NULL == testbed)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ GNUNET_break (GNUNET_SYSERR !=
+ (ret = GNUNET_OS_process_status (testbed, &type, &code)));
+ if (GNUNET_NO != ret)
+ {
+ GNUNET_OS_process_destroy (testbed);
+ testbed = NULL;
+ /* Send SIGTERM to our process group */
+ if (0 != PLIBC_KILL (0, GNUNET_TERM_SIG))
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "signal");
+ GNUNET_SCHEDULER_shutdown (); /* Couldn't send the signal, we shutdown frowning */
+ }
+ return;
+ }
+ LOG_DEBUG ("Child hasn't died. Resuming to monitor its status\n");
+ child_death_task_id =
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ pr, &child_death_task, NULL);
+}
+
+