version 1.248, 2020/09/27 23:56:25 |
version 1.249, 2020/09/28 00:06:36 |
|
|
JobCreatePipe(Job *job, int minfd) |
JobCreatePipe(Job *job, int minfd) |
{ |
{ |
int i, fd, flags; |
int i, fd, flags; |
|
int pipe_fds[2]; |
|
|
if (pipe(job->jobPipe) == -1) |
if (pipe(pipe_fds) == -1) |
Punt("Cannot create pipe: %s", strerror(errno)); |
Punt("Cannot create pipe: %s", strerror(errno)); |
|
|
for (i = 0; i < 2; i++) { |
for (i = 0; i < 2; i++) { |
/* Avoid using low numbered fds */ |
/* Avoid using low numbered fds */ |
fd = fcntl(job->jobPipe[i], F_DUPFD, minfd); |
fd = fcntl(pipe_fds[i], F_DUPFD, minfd); |
if (fd != -1) { |
if (fd != -1) { |
close(job->jobPipe[i]); |
close(pipe_fds[i]); |
job->jobPipe[i] = fd; |
pipe_fds[i] = fd; |
} |
} |
} |
} |
|
|
|
job->inPipe = pipe_fds[0]; |
|
job->outPipe = pipe_fds[1]; |
|
|
/* Set close-on-exec flag for both */ |
/* Set close-on-exec flag for both */ |
if (fcntl(job->inPipe, F_SETFD, FD_CLOEXEC) == -1) |
if (fcntl(job->inPipe, F_SETFD, FD_CLOEXEC) == -1) |
Punt("Cannot set close-on-exec: %s", strerror(errno)); |
Punt("Cannot set close-on-exec: %s", strerror(errno)); |