commit 79be1c477e167892b12b77dcef1d298d9d017d3c from: Alexander Barton date: Sun Jul 11 14:58:30 2010 UTC Refactor Resolve_Read() into generic Proc_Read() function commit - 7b5e2fe38e7af696155e687924462c4b9fe951bc commit + 79be1c477e167892b12b77dcef1d298d9d017d3c blob - f4efff1655002f5687b44b8beb9f9cb38c90fbf2 blob + f059d917b25f4443f900b6d531a0d7643e2c45de --- src/ngircd/conn.c +++ src/ngircd/conn.c @@ -1952,7 +1952,7 @@ cb_Connect_to_Server(int fd, UNUSED short events) } /* Read result from pipe */ - len = Resolve_Read(&Conf_Server[i].res_stat, dest_addrs, sizeof(dest_addrs)); + len = Proc_Read(&Conf_Server[i].res_stat, dest_addrs, sizeof(dest_addrs)); if (len == 0) return; @@ -2005,7 +2005,7 @@ cb_Read_Resolver_Result( int r_fd, UNUSED short events } /* Read result from pipe */ - len = Resolve_Read(&My_Connections[i].proc_stat, readbuf, sizeof readbuf -1); + len = Proc_Read(&My_Connections[i].proc_stat, readbuf, sizeof readbuf -1); if (len == 0) return; blob - 3eb3d8042edc0967bd19f1a7251a710850e4139d blob + f5438834c1842fa3453b6cc6da62a817e3fd9042 --- src/ngircd/proc.c +++ 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- */ blob - a7bff4f39b79cd5b31e270d524d1f27a89190c5a blob + 40a2c292cf178130921e5542e3218a9a6b925a8b --- src/ngircd/proc.h +++ src/ngircd/proc.h @@ -32,6 +32,8 @@ GLOBAL void Proc_Kill PARAMS((PROC_STAT *proc)); GLOBAL void Proc_GenericSignalHandler PARAMS((int Signal)); +GLOBAL size_t Proc_Read PARAMS((PROC_STAT *proc, void *buffer, size_t buflen)); + #endif /* -eof- */ blob - 26ad103cf58deb6eaf2fbb064563408917f2d969 blob + d121b0a938dfb6c07dedbd7836a42e9abeecff28 --- src/ngircd/resolve.c +++ src/ngircd/resolve.c @@ -460,34 +460,6 @@ Do_ResolveName( const char *Host, int w_fd ) array_free(&IpAddrs); } /* Do_ResolveName */ - - -/** - * Read result of resolver sub-process from pipe - */ -GLOBAL size_t -Resolve_Read( PROC_STAT *s, void* readbuf, size_t buflen) -{ - ssize_t bytes_read; - - assert(buflen > 0); - - /* Read result from pipe */ - bytes_read = read(Proc_GetPipeFd(s), readbuf, buflen); - if (bytes_read < 0) { - if (errno == EAGAIN) - return 0; - Log( LOG_CRIT, "Resolver: Can't read result: %s!", strerror(errno)); - bytes_read = 0; - } -#ifdef DEBUG - else if (bytes_read == 0) - Log( LOG_DEBUG, "Resolver: Can't read result: EOF"); -#endif - Proc_Kill(s); - return (size_t)bytes_read; -} - /* -eof- */ blob - 9759a2c4e43150ab8d196d984a0b0a9d08d38c77 blob + 044ceec1e123ba096f66e6b8935fb28d0b52f535 --- src/ngircd/resolve.h +++ src/ngircd/resolve.h @@ -18,7 +18,6 @@ GLOBAL bool Resolve_Addr PARAMS((PROC_STAT * s, const int identsock, void (*cbfunc) (int, short))); GLOBAL bool Resolve_Name PARAMS((PROC_STAT * s, const char *Host, void (*cbfunc) (int, short))); -GLOBAL size_t Resolve_Read PARAMS((PROC_STAT * s, void *buf, size_t buflen)); #endif