interactive = 0;
if (pin == NULL) {
close(0);
- open(bb_dev_null, O_RDONLY);
+ xopen(bb_dev_null, O_RDONLY);
}
_exit(execute(t->left, pin, pout, FEXEC));
}
#endif
if (pin != NULL) {
- dup2(pin[0], 0);
- closepipe(pin);
+ xmove_fd(pin[0], 0);
+ if (pin[1] != 0) close(pin[1]);
}
if (pout != NULL) {
- dup2(pout[1], 1);
- closepipe(pout);
+ xmove_fd(pout[1], 1);
+ if (pout[1] != 1) close(pout[0]);
}
iopp = t->ioact;
if (ourtrap[j] && signal(j, SIG_IGN) != SIG_IGN)
signal(j, SIG_DFL);
- dup2(pf[1], 1);
- closepipe(pf);
+ /* Testcase where below checks are needed:
+ * close stdout & run this script:
+ * files=`ls`
+ * echo "$files" >zz
+ */
+ xmove_fd(pf[1], 1);
+ if (pf[0] != 1) close(pf[0]);
argument_list[0] = (char *) DEFAULT_SHELL;
argument_list[1] = (char *) "-c";