+ case SIGALRM:
+#ifdef DEBUG
+ Log_Subprocess(LOG_DEBUG, "Child got ALARM signal, exiting.");
+#endif
+ exit(1);
+ }
+}
+
+/**
+ * Read bytes from a pipe of a forked child process.
+ * In addition, this function makes sure that the child process is ignored
+ * after all data has been read or a fatal error occurred.
+ */
+GLOBAL size_t
+Proc_Read(PROC_STAT *proc, void *buffer, size_t buflen)
+{
+ ssize_t bytes_read = 0;
+
+ assert(buffer != NULL);
+ assert(buflen > 0);
+
+ bytes_read = read(proc->pipe_fd, buffer, buflen);
+ if (bytes_read < 0) {
+ if (errno == EAGAIN)
+ return 0;
+ Log(LOG_CRIT, "Can't read from child process %ld: %s",
+ proc->pid, strerror(errno));
+ Proc_Close(proc);
+ bytes_read = 0;
+ } else if (bytes_read == 0) {
+ /* EOF: clean up */
+ LogDebug("Child process %ld: EOF reached, closing pipe.",
+ proc->pid);
+ Proc_Close(proc);