- 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[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[2] >= 0) {
- if (fds[2]) {
- close(err[0]);
- if (err[1] != STDERR_FILENO)
- dup2(err[1], STDERR_FILENO);
- } else
- dup2(null, STDERR_FILENO);
- }
- if (null >= 0)
- close(null);
- signal(SIGINT, SIG_DFL);
- signal(SIGTERM, SIG_DFL);
- signal(SIGCHLD, SIG_DFL);
- execvp(file, args);
- _exit(EXIT_FAILURE);
- }
- if (fds[0] > 0) {
- close(in[0]);
- *fds = in[1];
- }
- if (fds[1] > 0) {
- close(out[1]);
- *(fds + 1) = out[0];
- }
- if (fds[2] > 0) {
- close(err[1]);
- *(fds + 2) = err[0];