repo: ngircd action: commit revision: path_from: revision_from: 79be1c477e167892b12b77dcef1d298d9d017d3c: path_to: revision_to:
commit 79be1c477e167892b12b77dcef1d298d9d017d3c Author: Alexander BartonDate: Sun Jul 11 16:58:30 2010 +0200 Refactor Resolve_Read() into generic Proc_Read() function diff --git a/src/ngircd/conn.c b/src/ngircd/conn.c
--- a/src/ngircd/conn.c +++ b/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; diff --git a/src/ngircd/proc.c b/src/ngircd/proc.c
--- 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- */
diff --git a/src/ngircd/proc.h b/src/ngircd/proc.h
--- a/src/ngircd/proc.h +++ b/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- */ diff --git a/src/ngircd/resolve.c b/src/ngircd/resolve.c
--- a/src/ngircd/resolve.c
+++ b/src/ngircd/resolve.c
@@ -462,32 +462,4 @@ Do_ResolveName( const char *Host, int w_fd )
} /* 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- */
diff --git a/src/ngircd/resolve.h b/src/ngircd/resolve.h
--- a/src/ngircd/resolve.h +++ b/src/ngircd/resolve.h @@ -18,7 +18,6 @@ GLOBAL bool Resolve_Addr PARAMS((PROC_STAT * s, const ng_ipaddr_t * Addr, 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
-----END OF PAGE-----