From c2f5e60976784643e692cf52f5a38c542abef1bd Mon Sep 17 00:00:00 2001 From: Stian Skjelstad Date: Sat, 28 Dec 2024 00:36:45 +0100 Subject: [PATCH] [Unix, piped process] If waitpid() returns a fatal error, give up waiting. --- stuff/piperun-unix.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/stuff/piperun-unix.c b/stuff/piperun-unix.c index f562b7aa..73910e16 100644 --- a/stuff/piperun-unix.c +++ b/stuff/piperun-unix.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include "types.h" @@ -62,8 +63,6 @@ void *ocpPipeProcess_create (const char * const commandLine[]) { close (fdout[1]); close (fderr[1]); - fcntl (fdout[0], F_SETFD, FD_CLOEXEC); - fcntl (fderr[0], F_SETFD, FD_CLOEXEC); return process; } @@ -107,13 +106,23 @@ int ocpPipeProcess_destroy (void *_process) while (process->pid >= 0) { - if (waitpid (process->pid, &retval, WNOHANG) != process->pid) + pid_t retval = waitpid (process->pid, &retval, WNOHANG); + if (retval == process->pid) { - usleep(10000); - continue; + break; } - process->pid = -1; + if (retval < 0) + { + if ((errno != EAGAIN) && + (errno != EINTR)) + { + fprintf (stderr, "waitpid() failed: %s\n", strerror (errno)); + break; + } + } + usleep(10000); } + process->pid = -1; free (process); return retval; }