1 /* $Header: /src/pub/tcsh/sh.sem.c,v 3.51 2000/11/11 23:03:38 christos Exp $ */
3 * sh.sem.c: I/O redirections and job forking. A touchy issue!
4 * Most stuff with builtins is incorrect
7 * Copyright (c) 1980, 1991 The Regents of the University of California.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 RCSID("$Id: sh.sem.c,v 3.51 2000/11/11 23:03:38 christos Exp $")
46 #endif /*WINNT_NATIVE*/
52 # endif /* CLEX_DUPS */
54 #endif /* CLOSE_ON_EXEC */
56 #if defined(__sparc__) || defined(sparc)
57 # if !defined(MACH) && SYSVREL == 0 && !defined(Lynx) && !defined(BSD4_4) && !defined(linux)
59 # endif /* !MACH && SYSVREL == 0 && !Lynx && !BSD4_4 && !linux */
60 #endif /* __sparc__ || sparc */
63 static sigret_t vffree __P((int));
65 static Char *splicepipe __P((struct command *, Char *));
66 static void doio __P((struct command *, int *, int *));
67 static void chkclob __P((char *));
74 * For SVR4, there are problems with pipelines having the first process as
75 * the group leader. The problem occurs when the first process exits before
76 * the others have a chance to setpgid(). This is because in SVR4 you can't
77 * have a zombie as a group leader. The solution I have used is to reverse
78 * the order in which pipelines are started, making the last process the
79 * group leader. (Note I am not using 'pipeline' in the generic sense -- I
80 * mean processes connected by '|'.) I don't know yet if this causes other
83 * All the changes for this are in execute(), and are enclosed in
86 * David Dawes (dawes@physics.su.oz.au) Oct 1991
91 execute(t, wanttty, pipein, pipeout)
92 register struct command *t;
94 int *pipein, *pipeout;
97 extern bool use_fork; /* use fork() instead of vfork()? */
101 struct biltins *bifunc;
105 static sigmask_t csigmask;
108 static int onosigchld = 0;
110 static int nosigchld = 0;
121 if ((varval(STRNTslowexec) == STRNULL) &&
122 !t->t_dcdr && !t->t_dcar && !t->t_dflg && !didfds &&
123 (intty || intact) && (t->t_dtyp == NODE_COMMAND) &&
125 if ((t->t_dcom[0][0] & (QUOTE | TRIM)) == QUOTE)
126 (void) Strcpy(t->t_dcom[0], t->t_dcom[0] + 1);
128 if (nt_try_fast_exec(t) == 0)
132 #endif /* WINNT_NATIVE */
135 * Ed hutchins@sgi.com & Dominic dbg@sgi.com
136 * Sat Feb 25 03:13:11 PST 1995
137 * try implicit cd if we have a 1 word command
139 if (implicit_cd && (intty || intact) && t->t_dcom && t->t_dcom[0] &&
140 t->t_dcom[0][0] && (blklen(t->t_dcom) == 1) && !noexec) {
141 Char sCName[MAXPATHLEN];
146 dollar(sCName, t->t_dcom[0]);
149 Char sCPath[MAXPATHLEN];
153 while (*pCN && *pCN != '/')
159 (void) Strcpy(sCPath, varval(STRhome));
160 catn(sCPath, pCN, MAXPATHLEN);
161 (void) Strcpy(sCName, sCPath);
164 pathname = short2str(sCName);
165 /* if this is a dir, tack a "cd" on as the first arg */
166 if ((stat(pathname, &stbuf) != -1 && S_ISDIR(stbuf.st_mode))
168 || (pathname[0] && pathname[1] == ':' && pathname[2] == '\0')
169 #endif /* WINNT_NATIVE */
172 Char **ot_dcom = t->t_dcom;
174 vCD[0] = Strsave(STRcd);
176 t->t_dcom = blkspl(vCD, ot_dcom);
177 if (implicit_cd > 1) {
181 xfree((ptr_t) ot_dcom);
186 * From: Michael Schroeder <mlschroe@immd4.informatik.uni-erlangen.de>
187 * Don't check for wantty > 0...
189 if (t->t_dflg & F_AMPERSAND)
194 if ((t->t_dcom[0][0] & (QUOTE | TRIM)) == QUOTE)
195 (void) Strcpy(t->t_dcom[0], t->t_dcom[0] + 1);
196 if ((t->t_dflg & F_REPEAT) == 0)
197 Dfix(t); /* $ " ' \ */
198 if (t->t_dcom[0] == 0) {
205 if (t->t_dflg & F_PIPEIN)
207 #else /* !BACKPIPE */
208 if (t->t_dflg & F_PIPEOUT)
210 #endif /* BACKPIPE */
212 * Must do << early so parent will know where input pointer should be.
213 * If noexec then this is all we do.
215 if (t->t_dflg & F_READ) {
222 set(STRstatus, Strsave(STR0), VAR_READWRITE);
225 * This mess is the necessary kludge to handle the prefix builtins:
226 * nice, nohup, time. These commands can also be used by themselves,
227 * and this is not handled here. This will also work when loops are
230 while (t->t_dtyp == NODE_COMMAND)
231 if (eq(t->t_dcom[0], STRnice)) {
233 if (strchr("+-", t->t_dcom[1][0])) {
238 lshift(t->t_dcom, 2);
246 lshift(t->t_dcom, 1);
253 else if (eq(t->t_dcom[0], STRnohup)) {
255 t->t_dflg |= F_NOHUP;
256 lshift(t->t_dcom, 1);
261 else if (eq(t->t_dcom[0], STRhup)) {
264 lshift(t->t_dcom, 1);
269 else if (eq(t->t_dcom[0], STRtime)) {
272 lshift(t->t_dcom, 1);
278 else if (eq(t->t_dcom[0], STRver))
279 if (t->t_dcom[1] && t->t_dcom[2]) {
281 t->t_systype = getv(t->t_dcom[1]);
282 lshift(t->t_dcom, 2);
291 /* is it a command */
292 if (t->t_dtyp == NODE_COMMAND) {
294 * Check if we have a builtin function and remember which one.
297 if (noexec && bifunc) {
299 * Continue for builtins that are part of the scripting language
301 if (bifunc->bfunct != (bfunc_t)dobreak &&
302 bifunc->bfunct != (bfunc_t)docontin &&
303 bifunc->bfunct != (bfunc_t)doelse &&
304 bifunc->bfunct != (bfunc_t)doend &&
305 bifunc->bfunct != (bfunc_t)doforeach&&
306 bifunc->bfunct != (bfunc_t)dogoto &&
307 bifunc->bfunct != (bfunc_t)doif &&
308 bifunc->bfunct != (bfunc_t)dorepeat &&
309 bifunc->bfunct != (bfunc_t)doswbrk &&
310 bifunc->bfunct != (bfunc_t)doswitch &&
311 bifunc->bfunct != (bfunc_t)dowhile &&
312 bifunc->bfunct != (bfunc_t)dozip)
316 else { /* not a command */
323 * We fork only if we are timed, or are not the end of a parenthesized
324 * list and not a simple builtin function. Simple meaning one that is
325 * not pipedout, niced, nohupped, or &'d. It would be nice(?) to not
326 * fork in some of these cases.
329 * Prevent forking cd, pushd, popd, chdir cause this will cause the
330 * shell not to change dir!
334 * Can't have NOFORK for the tail of a pipe - because it is not the
335 * last command spawned (even if it is at the end of a parenthesised
338 if (t->t_dflg & F_PIPEIN)
339 t->t_dflg &= ~(F_NOFORK);
340 #endif /* BACKPIPE */
341 if (bifunc && (bifunc->bfunct == (bfunc_t)dochngd ||
342 bifunc->bfunct == (bfunc_t)dopushd ||
343 bifunc->bfunct == (bfunc_t)dopopd))
344 t->t_dflg &= ~(F_NICE);
345 if (((t->t_dflg & F_TIME) || ((t->t_dflg & F_NOFORK) == 0 &&
346 (!bifunc || t->t_dflg &
347 (F_PIPEOUT | F_AMPERSAND | F_NICE | F_NOHUP | F_HUP)))) ||
349 * We have to fork for eval too.
351 (bifunc && (t->t_dflg & F_PIPEIN) != 0 &&
352 bifunc->bfunct == (bfunc_t)doeval)) {
354 if (t->t_dtyp == NODE_PAREN ||
355 t->t_dflg & (F_REPEAT | F_AMPERSAND) || bifunc)
360 * We need to block SIGCHLD here, so that if the process does
361 * not die before we can set the process group
363 if (wanttty >= 0 && !nosigchld) {
365 csigmask = sigblock(sigmask(SIGCHLD));
367 (void) sighold(SIGCHLD);
373 pid = pfork(t, wanttty);
374 if (pid == 0 && nosigchld) {
376 (void) sigsetmask(csigmask);
378 (void) sigrelse(SIGCHLD);
382 else if (pid != 0 && (t->t_dflg & F_AMPERSAND))
388 int ochild, osetintr, ohaderr, odidfds;
389 int oSHIN, oSHOUT, oSHDIAG, oOLDSTD, otpgrp;
390 int oisoutatty, oisdiagatty;
392 # ifndef CLOSE_ON_EXEC
394 # endif /* !CLOSE_ON_EXEC */
396 sigmask_t omask, ocsigmask;
397 # endif /* BSDSIGS */
400 * Prepare for the vfork by saving everything that the child
401 * corrupts before it exec's. Note that in some signal
402 * implementations which keep the signal info in user space
403 * (e.g. Sun's) it will also be necessary to save and restore
404 * the current sigvec's for the signals the child touches
409 * Sooooo true... If this is a Sun, save the sigvec's. (Skip
410 * Gilbrech - 11/22/87)
413 sigvec_t savesv[NSIGSAVED];
416 # endif /* SAVESIGVEC */
417 if (wanttty >= 0 && !nosigchld && !noexec) {
419 csigmask = sigblock(sigmask(SIGCHLD));
420 # else /* !BSDSIGS */
421 (void) sighold(SIGCHLD);
422 # endif /* BSDSIGS */
426 omask = sigblock(sigmask(SIGCHLD)|sigmask(SIGINT));
427 # else /* !BSDSIGS */
428 (void) sighold(SIGCHLD);
429 (void) sighold(SIGINT);
430 # endif /* BSDSIGS */
435 # ifndef CLOSE_ON_EXEC
437 # endif /* !CLOSE_ON_EXEC */
443 oisoutatty = isoutatty;
444 oisdiagatty = isdiagatty;
446 ocsigmask = csigmask;
447 # endif /* BSDSIGS */
448 onosigchld = nosigchld;
453 savesm = savesigvec(savesv);
454 # endif /* SAVESIGVEC */
463 restoresigvec(savesv, savesm);
464 # endif /* SAVESIGVEC */
465 (void) sigsetmask(omask);
466 # else /* !BSDSIGS */
467 (void) sigrelse(SIGCHLD);
468 (void) sigrelse(SIGINT);
469 # endif /* BSDSIGS */
470 stderror(ERR_NOPROC);
473 if (pid) { /* parent */
475 restoresigvec(savesv, savesm);
476 # endif /* SAVESIGVEC */
482 # ifndef CLOSE_ON_EXEC
484 # endif /* !CLOSE_ON_EXEC */
489 isoutatty = oisoutatty;
490 isdiagatty = oisdiagatty;
492 csigmask = ocsigmask;
493 # endif /* BSDSIGS */
494 nosigchld = onosigchld;
500 xfree((ptr_t) Vexpath);
502 blkfree((Char **) Vt);
504 /* this is from pfork() */
507 (void) sigsetmask(omask);
508 # else /* !BSDSIGS */
509 (void) sigrelse(SIGCHLD);
510 (void) sigrelse(SIGINT);
511 # endif /* BSDSIGS */
514 /* this is from pfork() */
519 (void) sigsetmask(csigmask);
520 # else /* !BSDSIGS */
521 (void) sigrelse(SIGCHLD);
522 # endif /* BSDSIGS */
527 ignint = (tpgrp == -1 && (t->t_dflg & F_NOINTERRUPT))
528 || (gointr && eq(gointr, STRminus));
529 pgrp = pcurrjob ? pcurrjob->p_jobid : getpid();
534 * casts made right for SunOS 4.0 by Douglas C. Schmidt
535 * <schmidt%sunshine.ics.uci.edu@ROME.ICS.UCI.EDU>
538 * ignint ifs cleaned by Johan Widen <mcvax!osiris.sics.se!jw@uunet.UU.NET>
542 (void) signal(SIGINT, SIG_IGN);
543 (void) signal(SIGQUIT, SIG_IGN);
546 (void) signal(SIGINT, vffree);
547 (void) signal(SIGQUIT, SIG_DFL);
551 (void) signal(SIGTSTP, SIG_DFL);
552 (void) signal(SIGTTIN, SIG_DFL);
553 (void) signal(SIGTTOU, SIG_DFL);
555 # endif /* BSDJOBS */
557 (void) signal(SIGTERM, parterm);
559 else if (tpgrp == -1 &&
560 (t->t_dflg & F_NOINTERRUPT)) {
561 (void) signal(SIGINT, SIG_IGN);
562 (void) signal(SIGQUIT, SIG_IGN);
565 pgetty(wanttty, pgrp);
567 if (t->t_dflg & F_NOHUP)
568 (void) signal(SIGHUP, SIG_IGN);
569 if (t->t_dflg & F_HUP)
570 (void) signal(SIGHUP, SIG_DFL);
571 if (t->t_dflg & F_NICE) {
572 int nval = SIGN_EXTEND_CHAR(t->t_nice);
574 (void) setpriority(PRIO_PROCESS, 0, nval);
575 # else /* !BSDNICE */
577 # endif /* BSDNICE */
580 if (t->t_dflg & F_VER) {
581 tsetenv(STRSYSTYPE, t->t_systype ? STRbsd43 : STRsys53);
592 * It would be better if we could wait for the whole job when we
593 * knew the last process had been started. Pwait, in fact, does
594 * wait for the whole job anyway, but this test doesn't really
595 * express our intentions.
598 if (didfds == 0 && t->t_dflg & F_PIPEOUT) {
599 (void) close(pipeout[0]);
600 (void) close(pipeout[1]);
602 if ((t->t_dflg & F_PIPEIN) != 0)
604 #else /* !BACKPIPE */
605 if (didfds == 0 && t->t_dflg & F_PIPEIN) {
606 (void) close(pipein[0]);
607 (void) close(pipein[1]);
609 if ((t->t_dflg & F_PIPEOUT) != 0)
611 #endif /* BACKPIPE */
615 (void) sigsetmask(csigmask);
617 (void) sigrelse(SIGCHLD);
621 if ((t->t_dflg & F_AMPERSAND) == 0)
626 doio(t, pipein, pipeout);
628 if (t->t_dflg & F_PIPEIN) {
629 (void) close(pipein[0]);
630 (void) close(pipein[1]);
632 #else /* !BACKPIPE */
633 if (t->t_dflg & F_PIPEOUT) {
634 (void) close(pipeout[0]);
635 (void) close(pipeout[1]);
637 #endif /* BACKPIPE */
639 * Perform a builtin function. If we are not forked, arrange for
648 if (t->t_dtyp != NODE_PAREN) {
653 * For () commands must put new 0,1,2 in FSH* and recurse
655 OLDSTD = dcopy(0, FOLDSTD);
656 SHOUT = dcopy(1, FSHOUT);
657 isoutatty = isatty(SHOUT);
658 SHDIAG = dcopy(2, FSHDIAG);
659 isdiagatty = isatty(SHDIAG);
662 #ifndef CLOSE_ON_EXEC
664 #endif /* !CLOSE_ON_EXEC */
667 t->t_dspr->t_dflg |= t->t_dflg & F_NOINTERRUPT;
668 execute(t->t_dspr, wanttty, NULL, NULL);
673 t->t_dcdr->t_dflg |= F_PIPEIN | (t->t_dflg &
674 (F_PIPEOUT | F_AMPERSAND | F_NOFORK | F_NOINTERRUPT));
675 execute(t->t_dcdr, wanttty, pv, pipeout);
676 t->t_dcar->t_dflg |= F_PIPEOUT |
677 (t->t_dflg & (F_PIPEIN | F_AMPERSAND | F_STDERR | F_NOINTERRUPT));
678 execute(t->t_dcar, wanttty, pipein, pv);
679 #else /* !BACKPIPE */
680 t->t_dcar->t_dflg |= F_PIPEOUT |
681 (t->t_dflg & (F_PIPEIN | F_AMPERSAND | F_STDERR | F_NOINTERRUPT));
682 execute(t->t_dcar, wanttty, pipein, pv);
683 t->t_dcdr->t_dflg |= F_PIPEIN | (t->t_dflg &
684 (F_PIPEOUT | F_AMPERSAND | F_NOFORK | F_NOINTERRUPT));
685 execute(t->t_dcdr, wanttty, pv, pipeout);
686 #endif /* BACKPIPE */
691 t->t_dcar->t_dflg |= t->t_dflg & F_NOINTERRUPT;
692 execute(t->t_dcar, wanttty, NULL, NULL);
694 * In strange case of A&B make a new job after A
696 if (t->t_dcar->t_dflg & F_AMPERSAND && t->t_dcdr &&
697 (t->t_dcdr->t_dflg & F_AMPERSAND) == 0)
701 t->t_dcdr->t_dflg |= t->t_dflg &
702 (F_NOFORK | F_NOINTERRUPT);
703 execute(t->t_dcdr, wanttty, NULL, NULL);
710 t->t_dcar->t_dflg |= t->t_dflg & F_NOINTERRUPT;
711 execute(t->t_dcar, wanttty, NULL, NULL);
712 if ((getn(varval(STRstatus)) == 0) !=
713 (t->t_dtyp == NODE_AND)) {
718 t->t_dcdr->t_dflg |= t->t_dflg &
719 (F_NOFORK | F_NOINTERRUPT);
720 execute(t->t_dcdr, wanttty, NULL, NULL);
728 * Fall through for all breaks from switch
730 * If there will be no more executions of this command, flush all file
731 * descriptors. Places that turn on the F_REPEAT bit are responsible for
732 * doing donefds after the last re-execution
734 if (didfds && !(t->t_dflg & F_REPEAT))
747 if ((v = gargv) != 0) {
752 if ((v = pargv) != 0) {
766 * Expand and glob the words after an i/o redirection.
767 * If more than one word is generated, then update the command vector.
769 * This is done differently in all the shells:
770 * 1. in the bourne shell and ksh globbing is not performed
771 * 2. Bash/csh say ambiguous
772 * 3. zsh does i/o to/from all the files
773 * 4. itcsh concatenates the words.
775 * I don't know what is best to do. I think that Ambiguous is better
776 * than restructuring the command vector, because the user can get
777 * unexpected results. In any case, the command vector restructuring
778 * code is present and the user can choose it by setting noambiguous
782 register struct command *t;
783 Char *cp; /* word after < or > */
787 if (adrof(STRnoambiguous)) {
790 blk[0] = Dfix1(cp); /* expand $ */
793 gflag = 0, tglob(blk);
797 setname(short2str(blk[0]));
798 xfree((ptr_t) blk[0]);
799 stderror(ERR_NAME | ERR_NOMATCH);
802 if (pv[1] != NULL) { /* we need to fix the command vector */
803 Char **av = blkspl(t->t_dcom, &pv[1]);
804 xfree((ptr_t) t->t_dcom);
807 xfree((ptr_t) blk[0]);
815 (void) Strcpy(buf, blk[1] = Dfix1(cp));
816 xfree((ptr_t) blk[1]);
817 blk[0] = globone(buf, G_ERROR);
823 * Perform io redirection.
824 * We may or maynot be forked here.
827 doio(t, pipein, pipeout)
828 register struct command *t;
829 int *pipein, *pipeout;
833 register unsigned long flags = t->t_dflg;
835 if (didfds || (flags & F_REPEAT))
837 if ((flags & F_READ) == 0) {/* F_READ already done */
839 char tmp[MAXPATHLEN+1];
842 * so < /dev/std{in,out,err} work
844 (void) dcopy(SHIN, 0);
845 (void) dcopy(SHOUT, 1);
846 (void) dcopy(SHDIAG, 2);
847 cp = splicepipe(t, t->t_dlef);
848 (void) strncpy(tmp, short2str(cp), MAXPATHLEN);
849 tmp[MAXPATHLEN] = '\0';
851 if ((fd = open(tmp, O_RDONLY)) < 0)
852 stderror(ERR_SYSTEM, tmp, strerror(errno));
854 /* allow input files larger than 2Gb */
855 (void) fcntl(fd, O_LARGEFILE, 0);
856 #endif /* O_LARGEFILE */
859 else if (flags & F_PIPEIN) {
861 (void) dup(pipein[0]);
862 (void) close(pipein[0]);
863 (void) close(pipein[1]);
865 else if ((flags & F_NOINTERRUPT) && tpgrp == -1) {
867 (void) open(_PATH_DEVNULL, O_RDONLY);
872 #if defined(CLOSE_ON_EXEC) && defined(CLEX_DUPS)
874 * PWP: Unlike Bezerkeley 4.3, FIONCLEX for Pyramid is preserved
875 * across dup()s, so we have to UNSET it here or else we get a
876 * command with NO stdin, stdout, or stderr at all (a bad thing
879 (void) close_on_exec(0, 0);
880 #endif /* CLOSE_ON_EXEC && CLEX_DUPS */
884 char tmp[MAXPATHLEN+1];
886 cp = splicepipe(t, t->t_drit);
887 (void) strncpy(tmp, short2str(cp), MAXPATHLEN);
888 tmp[MAXPATHLEN] = '\0';
891 * so > /dev/std{out,err} work
893 (void) dcopy(SHOUT, 1);
894 (void) dcopy(SHDIAG, 2);
895 if ((flags & F_APPEND) != 0) {
897 fd = open(tmp, O_WRONLY | O_APPEND);
898 #else /* !O_APPEND */
899 fd = open(tmp, O_WRONLY);
900 (void) lseek(fd, (off_t) 0, L_XTND);
901 #endif /* O_APPEND */
905 if ((flags & F_APPEND) == 0 || fd == -1) {
906 if (!(flags & F_OVERWRITE) && adrof(STRnoclobber)) {
907 if (flags & F_APPEND)
908 stderror(ERR_SYSTEM, tmp, strerror(errno));
911 if ((fd = creat(tmp, 0666)) < 0)
912 stderror(ERR_SYSTEM, tmp, strerror(errno));
914 /* allow input files larger than 2Gb */
915 (void) fcntl(fd, O_LARGEFILE, 0);
916 #endif /* O_LARGEFILE */
921 else if (flags & F_PIPEOUT) {
923 (void) dup(pipeout[1]);
930 # if defined(CLOSE_ON_EXEC) && defined(CLEX_DUPS)
931 (void) close_on_exec(1, 0);
932 # endif /* CLOSE_ON_EXEC && CLEX_DUPS */
936 if (flags & F_STDERR) {
942 is2atty = isdiagatty;
943 # if defined(CLOSE_ON_EXEC) && defined(CLEX_DUPS)
944 (void) close_on_exec(2, 0);
945 # endif /* CLOSE_ON_EXEC && CLEX_DUPS */
957 pv[0] = dmove(pv[0], -1);
958 pv[1] = dmove(pv[1], -1);
959 if (pv[0] >= 0 && pv[1] >= 0)
971 if (stat(cp, &stb) < 0)
973 if (S_ISCHR(stb.st_mode))
975 stderror(ERR_EXISTS, cp);