X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=ngircd-alex.git;a=blobdiff_plain;f=src%2Fngircd%2Fproc.c;h=f5438834c1842fa3453b6cc6da62a817e3fd9042;hp=3eb3d8042edc0967bd19f1a7251a710850e4139d;hb=79be1c477e167892b12b77dcef1d298d9d017d3c;hpb=7b5e2fe38e7af696155e687924462c4b9fe951bc diff --git a/src/ngircd/proc.c b/src/ngircd/proc.c index 3eb3d804..f5438834 100644 --- a/src/ngircd/proc.c +++ b/src/ngircd/proc.c @@ -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- */