index 4f15ebe..bc7bfba 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -1327,11 +1327,19 @@ execpline(Estate state, wordcode slcode, int how, int last1) zclose(coprocin); zclose(coprocout); } - mpipe(ipipe); - mpipe(opipe); - coprocin = ipipe[0]; - coprocout = opipe[1]; - fdtable[coprocin] = fdtable[coprocout] = FDT_UNUSED; + if (mpipe(ipipe) < 0) { + coprocin = coprocout = -1; + slflags &= ~WC_SUBLIST_COPROC; + } else if (mpipe(opipe) < 0) { + close(ipipe[0]); + close(ipipe[1]); + coprocin = coprocout = -1; + slflags &= ~WC_SUBLIST_COPROC; + } else { + coprocin = ipipe[0]; + coprocout = opipe[1]; + fdtable[coprocin] = fdtable[coprocout] = FDT_UNUSED; + } } /* This used to set list_pipe_pid=0 unconditionally, but in things * like `ls|if true; then sleep 20; cat; fi' where the sleep was @@ -1438,16 +1446,17 @@ execpline(Estate state, wordcode slcode, int how, int last1) ((jn->stat & STAT_STOPPED) || (list_pipe_job && pline_level && (jobtab[list_pipe_job].stat & STAT_STOPPED)))) { - pid_t pid; + pid_t pid = 0; int synch[2]; struct timeval bgtime; - pipe(synch); - - if ((pid = zfork(&bgtime)) == -1) { + if (pipe(synch) < 0 || (pid = zfork(&bgtime)) == -1) { + if (pid < 0) { + close(synch[0]); + close(synch[1]); + } else + zerr("pipe failed: %e", errno); zleentry(ZLE_CMD_TRASH); - close(synch[0]); - close(synch[1]); fprintf(stderr, "zsh: job can't be suspended\n"); fflush(stderr); makerunning(jn); @@ -1568,7 +1577,9 @@ execpline2(Estate state, wordcode pcode, for (pc = state->pc; wc_code(code = *pc) == WC_REDIR; pc += WC_REDIR_WORDS(code)); - mpipe(pipes); + if (mpipe(pipes) < 0) { + /* FIXME */ + } /* if we are doing "foo | bar" where foo is a current * * shell command, do foo in a subshell and do the * @@ -1577,8 +1588,9 @@ execpline2(Estate state, wordcode pcode, int synch[2]; struct timeval bgtime; - pipe(synch); - if ((pid = zfork(&bgtime)) == -1) { + if (pipe(synch) < 0) { + zerr("pipe failed: %e", errno); + } else if ((pid = zfork(&bgtime)) == -1) { close(synch[0]); close(synch[1]); } else if (pid) { @@ -1995,7 +2007,9 @@ addfd(int forked, int *save, struct multio **mfds, int fd1, int fd2, int rflag, return; } mfds[fd1]->fds[1] = fdN; - mpipe(pipes); + if (mpipe(pipes) < 0) { + /* FIXME */ + } mfds[fd1]->pipe = pipes[1 - rflag]; redup(pipes[rflag], fd1); mfds[fd1]->ct = 2; @@ -2671,9 +2685,12 @@ execcmd(Estate state, int input, int output, int how, int last1) struct timeval bgtime; child_block(); - pipe(synch); - - if ((pid = zfork(&bgtime)) == -1) { + if (pipe(synch) < 0) { + zerr("pipe failed: %e", errno); + if (oautocont >= 0) + opts[AUTOCONTINUE] = oautocont; + return; + } else if ((pid = zfork(&bgtime)) == -1) { close(synch[0]); close(synch[1]); if (oautocont >= 0) @@ -3468,7 +3485,11 @@ getoutput(char *cmd, int qt) } return readoutput(stream, qt); } - mpipe(pipes); + if (mpipe(pipes) < 0) { + errflag = 1; + cmdoutpid = 0; + return NULL; + } child_block(); cmdoutval = 0; if ((cmdoutpid = pid = zfork(NULL)) == -1) { @@ -3728,7 +3749,8 @@ getproc(char *cmd, char **eptr) pnam = hcalloc(strlen(PATH_DEV_FD) + 6); if (!(prog = parsecmd(cmd, eptr))) return NULL; - mpipe(pipes); + if (mpipe(pipes) < 0) + return NULL; if ((pid = zfork(&bgtime))) { sprintf(pnam, "%s/%d", PATH_DEV_FD, pipes[!out]); zclose(pipes[out]); @@ -3782,7 +3804,8 @@ getpipe(char *cmd, int nullexec) zerr("invalid syntax for process substitution in redirection"); return -1; } - mpipe(pipes); + if (mpipe(pipes) < 0) + return -1; if ((pid = zfork(&bgtime))) { zclose(pipes[out]); if (pid == -1) { @@ -3806,12 +3829,16 @@ getpipe(char *cmd, int nullexec) /* open pipes with fds >= 10 */ /**/ -static void +static int mpipe(int *pp) { - pipe(pp); + if (pipe(pp) < 0) { + zerr("pipe failed: %e", errno); + return -1; + } pp[0] = movefd(pp[0]); pp[1] = movefd(pp[1]); + return 0; } /*