}
*pid = ret;
if (!(*pid)) { /* child */
- if (fds[0] >= 0) {
- if (fds[0]) {
- close(in[1]);
- if (in[0] != STDIN_FILENO)
- dup2(in[0], STDIN_FILENO);
- } else
- dup2(null, STDIN_FILENO);
+ if (fds[0] == 0)
+ dup2(null, STDIN_FILENO);
+ else if (fds[0] > 0) {
+ close(in[1]);
+ if (in[0] != STDIN_FILENO)
+ dup2(in[0], STDIN_FILENO);
}
- if (fds[1] >= 0) {
- if (fds[1]) {
- close(out[0]);
- if (out[1] != STDOUT_FILENO)
- dup2(out[1], STDOUT_FILENO);
- } else
- dup2(null, STDOUT_FILENO);
+ if (fds[1] == 0)
+ dup2(null, STDOUT_FILENO);
+ else if (fds[1] > 0) {
+ close(out[0]);
+ if (out[1] != STDOUT_FILENO)
+ dup2(out[1], STDOUT_FILENO);
}
- if (fds[2] >= 0) {
- if (fds[2]) {
- close(err[0]);
- if (err[1] != STDERR_FILENO)
- dup2(err[1], STDERR_FILENO);
- } else
- dup2(null, STDERR_FILENO);
+ if (fds[2] == 0)
+ dup2(null, STDERR_FILENO);
+ else if (fds[2] > 0) {
+ close(err[0]);
+ if (err[1] != STDERR_FILENO)
+ dup2(err[1], STDERR_FILENO);
}
if (null >= 0)
close(null);