STATIC int openhere(const union node *redir) { int pip[2]; int len = 0; if (pipe(pip) < 0) error("Pipe call failed"); if (redir->type == NHERE) { len = strlen(redir->nhere.doc->narg.text); if (len <= PIPESIZE) { xwrite(pip[1], redir->nhere.doc->narg.text, len); goto out; } } if (forkshell(NULL, NULL, FORK_NOJOB) == 0) { close(pip[0]); signal(SIGINT, SIG_IGN); signal(SIGQUIT, SIG_IGN); signal(SIGHUP, SIG_IGN); #ifdef SIGTSTP signal(SIGTSTP, SIG_IGN); #endif signal(SIGPIPE, SIG_DFL); if (redir->type == NHERE) xwrite(pip[1], redir->nhere.doc->narg.text, len); else expandhere(redir->nhere.doc, pip[1]); _exit(0); } out: close(pip[1]); return pip[0]; }
static int openhere(union node *redir) { int pip[2]; int len = 0; if (pipe(pip) < 0) error("Pipe call failed: %s", strerror(errno)); if (redir->type == NHERE) { len = strlen(redir->nhere.doc->narg.text); if (len <= PIPESIZE) { xwrite(pip[1], redir->nhere.doc->narg.text, len); goto out; } } if (forkshell((struct job *)NULL, (union node *)NULL, FORK_NOJOB) == 0) { close(pip[0]); signal(SIGINT, SIG_IGN); signal(SIGQUIT, SIG_IGN); signal(SIGHUP, SIG_IGN); signal(SIGTSTP, SIG_IGN); signal(SIGPIPE, SIG_DFL); if (redir->type == NHERE) xwrite(pip[1], redir->nhere.doc->narg.text, len); else expandhere(redir->nhere.doc, pip[1]); _exit(0); } out: close(pip[1]); return pip[0]; }