--- ray/src/common/unix_process.c 2020/02/28 05:18:49 3.16 +++ ray/src/common/unix_process.c 2024/06/04 21:47:55 3.19 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: unix_process.c,v 3.16 2020/02/28 05:18:49 greg Exp $"; +static const char RCSid[] = "$Id: unix_process.c,v 3.19 2024/06/04 21:47:55 greg Exp $"; #endif /* * Routines to communicate with separate process via dual pipes @@ -32,7 +32,7 @@ open_process( /* open communication to separate proce if (pd->pid > 0) return(-1); /* need to close, first */ - if ((pd->flags & (PF_FILT_INP|PF_FILT_OUT)) == (PF_FILT_INP|PF_FILT_OUT)) + if ((pd->flags&(PF_FILT_INP|PF_FILT_OUT)) == (PF_FILT_INP|PF_FILT_OUT)) return(-1); /* circular process not supported */ pd->flags &= ~PF_RUNNING; /* not running for sure */ @@ -58,11 +58,6 @@ open_process( /* open communication to separate proce p1[1] = pd->w; } else if (pipe(p1) < 0) return(-1); -#ifdef BSD - if (compath != NULL) - pd->pid = vfork(); /* more efficient with exec() */ - else -#endif pd->pid = fork(); if (pd->pid == 0) { /* if child... */ close(p0[1]); @@ -112,9 +107,9 @@ open_process( /* open communication to separate proce * No use in read stream without it, so set flag there as well. * GW: This bug took me two days to figure out!! */ - if (pd->r >= 0) + if (pd->r > 0) fcntl(pd->r, F_SETFD, FD_CLOEXEC); - if (pd->w >= 0) + if (pd->w > 1) fcntl(pd->w, F_SETFD, FD_CLOEXEC); pd->flags |= PF_RUNNING; return(PIPE_BUF); @@ -134,8 +129,8 @@ close_processes( /* close pipes and wait for processes for (i = 0; i < nproc; i++) /* close pipes, first */ if (pd[i].flags & PF_RUNNING) { - close(pd[i].w); - close(pd[i].r); + if (pd[i].w >= 0) close(pd[i].w); + if (pd[i].r >= 0) close(pd[i].r); pd[i].flags &= ~PF_RUNNING; } else togo -= (pd[i].pid < 0);