]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/proc.c
Refactor Resolve_Read() into generic Proc_Read() function
[ngircd-alex.git] / src / ngircd / proc.c
index 3eb3d8042edc0967bd19f1a7251a710850e4139d..f5438834c1842fa3453b6cc6da62a817e3fd9042 100644 (file)
@@ -116,4 +116,31 @@ Proc_GenericSignalHandler(int Signal)
        }
 }
 
+/**
+ * Read bytes from a pipe of a forked child process.
+ */
+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));
+               bytes_read = 0;
+       }
+#if DEBUG
+       else if (bytes_read == 0)
+               LogDebug("Can't read from child process %ld: EOF", proc->pid);
+#endif
+       Proc_Kill(proc);
+       return (size_t)bytes_read;
+}
+
 /* -eof- */