1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
21 ***********************************************************************/
27 * close a proc opened by procopen()
28 * otherwise exit() status of process is returned
36 procclose(register Proc_t
* p
)
46 if (p
->wfd
>= 0 && p
->wfd
!= p
->rfd
)
48 if (p
->flags
& PROC_ZOMBIE
)
51 * process may leave a zombie behind
52 * give it a chance to do that but
53 * don't hang waiting for it
59 if (!(p
->flags
& PROC_FOREGROUND
))
60 sigcritical(SIG_REG_EXEC
|SIG_REG_PROC
);
61 while ((pid
= waitpid(p
->pid
, &status
, flags
)) == -1 && errno
== EINTR
);
62 if (pid
!= p
->pid
&& (flags
& WNOHANG
))
64 if (!(p
->flags
& PROC_FOREGROUND
))
68 if (p
->sigint
!= SIG_IGN
)
69 signal(SIGINT
, p
->sigint
);
70 if (p
->sigquit
!= SIG_IGN
)
71 signal(SIGQUIT
, p
->sigquit
);
74 sigprocmask(SIG_SETMASK
, &p
->mask
, NiL
);
79 if (p
->sigchld
!= SIG_DFL
)
80 signal(SIGCHLD
, p
->sigchld
);
85 status
= status
== -1 ?
88 EXIT_TERM(WTERMSIG(status
)) :
89 EXIT_CODE(WEXITSTATUS(status
));
93 status
= errno
== ENOENT
? EXIT_NOTFOUND
: EXIT_NOEXEC
;