diff options
Diffstat (limited to 'src/lib/libc/stdlib/system.c')
-rw-r--r-- | src/lib/libc/stdlib/system.c | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/src/lib/libc/stdlib/system.c b/src/lib/libc/stdlib/system.c index c2f39325f6..06b439230b 100644 --- a/src/lib/libc/stdlib/system.c +++ b/src/lib/libc/stdlib/system.c | |||
@@ -10,11 +10,7 @@ | |||
10 | * 2. Redistributions in binary form must reproduce the above copyright | 10 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the | 11 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. | 12 | * documentation and/or other materials provided with the distribution. |
13 | * 3. All advertising materials mentioning features or use of this software | 13 | * 3. Neither the name of the University nor the names of its contributors |
14 | * must display the following acknowledgement: | ||
15 | * This product includes software developed by the University of | ||
16 | * California, Berkeley and its contributors. | ||
17 | * 4. Neither the name of the University nor the names of its contributors | ||
18 | * may be used to endorse or promote products derived from this software | 14 | * may be used to endorse or promote products derived from this software |
19 | * without specific prior written permission. | 15 | * without specific prior written permission. |
20 | * | 16 | * |
@@ -32,8 +28,7 @@ | |||
32 | */ | 28 | */ |
33 | 29 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 30 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)system.c 5.10 (Berkeley) 2/23/91";*/ | 31 | static char *rcsid = "$OpenBSD: system.c,v 1.6 2003/06/02 20:18:38 millert Exp $"; |
36 | static char *rcsid = "$Id: system.c,v 1.1.1.1 1995/10/18 08:42:20 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 32 | #endif /* LIBC_SCCS and not lint */ |
38 | 33 | ||
39 | #include <sys/types.h> | 34 | #include <sys/types.h> |
@@ -51,20 +46,24 @@ system(command) | |||
51 | { | 46 | { |
52 | pid_t pid; | 47 | pid_t pid; |
53 | sig_t intsave, quitsave; | 48 | sig_t intsave, quitsave; |
54 | int omask; | 49 | sigset_t mask, omask; |
55 | int pstat; | 50 | int pstat; |
56 | char *argp[] = {"sh", "-c", (char *) command, NULL}; | 51 | char *argp[] = {"sh", "-c", NULL, NULL}; |
57 | 52 | ||
58 | if (!command) /* just checking... */ | 53 | if (!command) /* just checking... */ |
59 | return(1); | 54 | return(1); |
60 | 55 | ||
61 | omask = sigblock(sigmask(SIGCHLD)); | 56 | argp[2] = (char *)command; |
62 | switch(pid = vfork()) { | 57 | |
58 | sigemptyset(&mask); | ||
59 | sigaddset(&mask, SIGCHLD); | ||
60 | sigprocmask(SIG_BLOCK, &mask, &omask); | ||
61 | switch (pid = vfork()) { | ||
63 | case -1: /* error */ | 62 | case -1: /* error */ |
64 | (void)sigsetmask(omask); | 63 | sigprocmask(SIG_SETMASK, &omask, NULL); |
65 | return(-1); | 64 | return(-1); |
66 | case 0: /* child */ | 65 | case 0: /* child */ |
67 | (void)sigsetmask(omask); | 66 | sigprocmask(SIG_SETMASK, &omask, NULL); |
68 | execve(_PATH_BSHELL, argp, environ); | 67 | execve(_PATH_BSHELL, argp, environ); |
69 | _exit(127); | 68 | _exit(127); |
70 | } | 69 | } |
@@ -72,8 +71,8 @@ system(command) | |||
72 | intsave = signal(SIGINT, SIG_IGN); | 71 | intsave = signal(SIGINT, SIG_IGN); |
73 | quitsave = signal(SIGQUIT, SIG_IGN); | 72 | quitsave = signal(SIGQUIT, SIG_IGN); |
74 | pid = waitpid(pid, (int *)&pstat, 0); | 73 | pid = waitpid(pid, (int *)&pstat, 0); |
75 | (void)sigsetmask(omask); | 74 | sigprocmask(SIG_SETMASK, &omask, NULL); |
76 | (void)signal(SIGINT, intsave); | 75 | (void)signal(SIGINT, intsave); |
77 | (void)signal(SIGQUIT, quitsave); | 76 | (void)signal(SIGQUIT, quitsave); |
78 | return(pid == -1 ? -1 : pstat); | 77 | return (pid == -1 ? -1 : pstat); |
79 | } | 78 | } |