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.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/lib/libc/stdlib/system.c b/src/lib/libc/stdlib/system.c
index c2f39325f6..636a9ebdff 100644
--- a/src/lib/libc/stdlib/system.c
+++ b/src/lib/libc/stdlib/system.c
@@ -32,8 +32,7 @@
32 */ 32 */
33 33
34#if defined(LIBC_SCCS) && !defined(lint) 34#if defined(LIBC_SCCS) && !defined(lint)
35/*static char *sccsid = "from: @(#)system.c 5.10 (Berkeley) 2/23/91";*/ 35static char *rcsid = "$OpenBSD: system.c,v 1.5 2002/05/26 09:29:02 deraadt 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 */ 36#endif /* LIBC_SCCS and not lint */
38 37
39#include <sys/types.h> 38#include <sys/types.h>
@@ -51,20 +50,24 @@ system(command)
51{ 50{
52 pid_t pid; 51 pid_t pid;
53 sig_t intsave, quitsave; 52 sig_t intsave, quitsave;
54 int omask; 53 sigset_t mask, omask;
55 int pstat; 54 int pstat;
56 char *argp[] = {"sh", "-c", (char *) command, NULL}; 55 char *argp[] = {"sh", "-c", NULL, NULL};
57 56
58 if (!command) /* just checking... */ 57 if (!command) /* just checking... */
59 return(1); 58 return(1);
60 59
61 omask = sigblock(sigmask(SIGCHLD)); 60 argp[2] = (char *)command;
62 switch(pid = vfork()) { 61
62 sigemptyset(&mask);
63 sigaddset(&mask, SIGCHLD);
64 sigprocmask(SIG_BLOCK, &mask, &omask);
65 switch (pid = vfork()) {
63 case -1: /* error */ 66 case -1: /* error */
64 (void)sigsetmask(omask); 67 sigprocmask(SIG_SETMASK, &omask, NULL);
65 return(-1); 68 return(-1);
66 case 0: /* child */ 69 case 0: /* child */
67 (void)sigsetmask(omask); 70 sigprocmask(SIG_SETMASK, &omask, NULL);
68 execve(_PATH_BSHELL, argp, environ); 71 execve(_PATH_BSHELL, argp, environ);
69 _exit(127); 72 _exit(127);
70 } 73 }
@@ -72,8 +75,8 @@ system(command)
72 intsave = signal(SIGINT, SIG_IGN); 75 intsave = signal(SIGINT, SIG_IGN);
73 quitsave = signal(SIGQUIT, SIG_IGN); 76 quitsave = signal(SIGQUIT, SIG_IGN);
74 pid = waitpid(pid, (int *)&pstat, 0); 77 pid = waitpid(pid, (int *)&pstat, 0);
75 (void)sigsetmask(omask); 78 sigprocmask(SIG_SETMASK, &omask, NULL);
76 (void)signal(SIGINT, intsave); 79 (void)signal(SIGINT, intsave);
77 (void)signal(SIGQUIT, quitsave); 80 (void)signal(SIGQUIT, quitsave);
78 return(pid == -1 ? -1 : pstat); 81 return (pid == -1 ? -1 : pstat);
79} 82}