summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/system.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/stdlib/system.c')
-rw-r--r--src/lib/libc/stdlib/system.c32
1 files changed, 15 insertions, 17 deletions
diff --git a/src/lib/libc/stdlib/system.c b/src/lib/libc/stdlib/system.c
index c2f39325f6..ebf5577674 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";*/ 31static char *rcsid = "$OpenBSD: system.c,v 1.7 2005/03/30 18:51:49 pat Exp $";
36static 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>
@@ -46,25 +41,28 @@ static char *rcsid = "$Id: system.c,v 1.1.1.1 1995/10/18 08:42:20 deraadt Exp $"
46extern char **environ; 41extern char **environ;
47 42
48int 43int
49system(command) 44system(const char *command)
50 const char *command;
51{ 45{
52 pid_t pid; 46 pid_t pid;
53 sig_t intsave, quitsave; 47 sig_t intsave, quitsave;
54 int omask; 48 sigset_t mask, omask;
55 int pstat; 49 int pstat;
56 char *argp[] = {"sh", "-c", (char *) command, NULL}; 50 char *argp[] = {"sh", "-c", NULL, NULL};
57 51
58 if (!command) /* just checking... */ 52 if (!command) /* just checking... */
59 return(1); 53 return(1);
60 54
61 omask = sigblock(sigmask(SIGCHLD)); 55 argp[2] = (char *)command;
62 switch(pid = vfork()) { 56
57 sigemptyset(&mask);
58 sigaddset(&mask, SIGCHLD);
59 sigprocmask(SIG_BLOCK, &mask, &omask);
60 switch (pid = vfork()) {
63 case -1: /* error */ 61 case -1: /* error */
64 (void)sigsetmask(omask); 62 sigprocmask(SIG_SETMASK, &omask, NULL);
65 return(-1); 63 return(-1);
66 case 0: /* child */ 64 case 0: /* child */
67 (void)sigsetmask(omask); 65 sigprocmask(SIG_SETMASK, &omask, NULL);
68 execve(_PATH_BSHELL, argp, environ); 66 execve(_PATH_BSHELL, argp, environ);
69 _exit(127); 67 _exit(127);
70 } 68 }
@@ -72,8 +70,8 @@ system(command)
72 intsave = signal(SIGINT, SIG_IGN); 70 intsave = signal(SIGINT, SIG_IGN);
73 quitsave = signal(SIGQUIT, SIG_IGN); 71 quitsave = signal(SIGQUIT, SIG_IGN);
74 pid = waitpid(pid, (int *)&pstat, 0); 72 pid = waitpid(pid, (int *)&pstat, 0);
75 (void)sigsetmask(omask); 73 sigprocmask(SIG_SETMASK, &omask, NULL);
76 (void)signal(SIGINT, intsave); 74 (void)signal(SIGINT, intsave);
77 (void)signal(SIGQUIT, quitsave); 75 (void)signal(SIGQUIT, quitsave);
78 return(pid == -1 ? -1 : pstat); 76 return (pid == -1 ? -1 : pstat);
79} 77}