|
@ -32,7 +32,7 @@ |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
#if defined(LIBC_SCCS) && !defined(lint) |
|
|
#if defined(LIBC_SCCS) && !defined(lint) |
|
|
static char *rcsid = "$OpenBSD: system.c,v 1.3 1996/09/15 09:31:52 tholo Exp $"; |
|
|
|
|
|
|
|
|
static char *rcsid = "$OpenBSD: system.c,v 1.4 2001/09/04 23:35:58 millert Exp $"; |
|
|
#endif /* LIBC_SCCS and not lint */ |
|
|
#endif /* LIBC_SCCS and not lint */ |
|
|
|
|
|
|
|
|
#include <sys/types.h> |
|
|
#include <sys/types.h> |
|
@ -50,7 +50,7 @@ system(command) |
|
|
{ |
|
|
{ |
|
|
pid_t pid; |
|
|
pid_t pid; |
|
|
sig_t intsave, quitsave; |
|
|
sig_t intsave, quitsave; |
|
|
int omask; |
|
|
|
|
|
|
|
|
sigset_t mask, omask; |
|
|
int pstat; |
|
|
int pstat; |
|
|
char *argp[] = {"sh", "-c", NULL, NULL}; |
|
|
char *argp[] = {"sh", "-c", NULL, NULL}; |
|
|
|
|
|
|
|
@ -59,13 +59,15 @@ system(command) |
|
|
|
|
|
|
|
|
argp[2] = (char *)command; |
|
|
argp[2] = (char *)command; |
|
|
|
|
|
|
|
|
omask = sigblock(sigmask(SIGCHLD)); |
|
|
|
|
|
|
|
|
sigemptyset(&mask); |
|
|
|
|
|
sigaddset(&mask, SIGCHLD); |
|
|
|
|
|
sigprocmask(SIG_BLOCK, &mask, &omask); |
|
|
switch(pid = vfork()) { |
|
|
switch(pid = vfork()) { |
|
|
case -1: /* error */ |
|
|
case -1: /* error */ |
|
|
(void)sigsetmask(omask); |
|
|
|
|
|
|
|
|
sigprocmask(SIG_SETMASK, &omask, NULL); |
|
|
return(-1); |
|
|
return(-1); |
|
|
case 0: /* child */ |
|
|
case 0: /* child */ |
|
|
(void)sigsetmask(omask); |
|
|
|
|
|
|
|
|
sigprocmask(SIG_SETMASK, &omask, NULL); |
|
|
execve(_PATH_BSHELL, argp, environ); |
|
|
execve(_PATH_BSHELL, argp, environ); |
|
|
_exit(127); |
|
|
_exit(127); |
|
|
} |
|
|
} |
|
@ -73,7 +75,7 @@ system(command) |
|
|
intsave = signal(SIGINT, SIG_IGN); |
|
|
intsave = signal(SIGINT, SIG_IGN); |
|
|
quitsave = signal(SIGQUIT, SIG_IGN); |
|
|
quitsave = signal(SIGQUIT, SIG_IGN); |
|
|
pid = waitpid(pid, (int *)&pstat, 0); |
|
|
pid = waitpid(pid, (int *)&pstat, 0); |
|
|
(void)sigsetmask(omask); |
|
|
|
|
|
|
|
|
sigprocmask(SIG_SETMASK, &omask, NULL); |
|
|
(void)signal(SIGINT, intsave); |
|
|
(void)signal(SIGINT, intsave); |
|
|
(void)signal(SIGQUIT, quitsave); |
|
|
(void)signal(SIGQUIT, quitsave); |
|
|
return(pid == -1 ? -1 : pstat); |
|
|
return(pid == -1 ? -1 : pstat); |
|
|