]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/proc.c
Proc_Close(): Only close socket if it is still valid
[ngircd-alex.git] / src / ngircd / proc.c
index 2a5eda8304ea1c462612329118dbd698b00148c6..e062cd0b7c702494a3992e8bfe1beab2a348113a 100644 (file)
@@ -79,7 +79,6 @@ Proc_Fork(PROC_STAT *proc, int *pipefds, void (*cbfunc)(int, short), int timeout
                signal(SIGALRM, Proc_GenericSignalHandler);
                close(pipefds[0]);
                alarm(timeout);
-               Conn_CloseAllSockets();
                return 0;
        }
 
@@ -138,13 +137,14 @@ Proc_Read(PROC_STAT *proc, void *buffer, size_t buflen)
                        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);
        }
-#if DEBUG
-       else if (bytes_read == 0)
-               LogDebug("Can't read from child process %ld: EOF", proc->pid);
-#endif
-       Proc_InitStruct(proc);
        return (size_t)bytes_read;
 }
 
@@ -154,7 +154,10 @@ Proc_Read(PROC_STAT *proc, void *buffer, size_t buflen)
 GLOBAL void
 Proc_Close(PROC_STAT *proc)
 {
-       io_close(proc->pipe_fd);
+       /* Close socket, if it exists */
+       if (proc->pipe_fd >= 0)
+               io_close(proc->pipe_fd);
+
        Proc_InitStruct(proc);
 }