Skip to content

Commit

Permalink
[Unix, piped process] If waitpid() returns a fatal error, give up wai…
Browse files Browse the repository at this point in the history
…ting.
  • Loading branch information
mywave82 committed Dec 27, 2024
1 parent bf4ffa8 commit c2f5e60
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions stuff/piperun-unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
#include "types.h"
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit c2f5e60

Please sign in to comment.