Commit | Line | Data |
---|---|---|
98295de1 KB |
1 | /* |
2 | * Copyright (c) 1988 The Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
019bea33 | 5 | * %sccs.include.redist.c% |
98295de1 KB |
6 | */ |
7 | ||
2ce81398 | 8 | #if defined(LIBC_SCCS) && !defined(lint) |
f0a345ab | 9 | static char sccsid[] = "@(#)system.c 5.10 (Berkeley) %G%"; |
98295de1 | 10 | #endif /* LIBC_SCCS and not lint */ |
b8f253e8 | 11 | |
4d506f35 | 12 | #include <sys/types.h> |
98295de1 | 13 | #include <sys/signal.h> |
d9080451 KB |
14 | #include <sys/wait.h> |
15 | #include <stdlib.h> | |
f357e0f1 | 16 | #include <stddef.h> |
f0a345ab | 17 | #include <unistd.h> |
a2f3a875 | 18 | #include <paths.h> |
a59df51f | 19 | |
98295de1 | 20 | system(command) |
f0a345ab | 21 | const char *command; |
a59df51f | 22 | { |
4d506f35 | 23 | union wait pstat; |
f0a345ab | 24 | pid_t pid; |
a2f3a875 KB |
25 | int omask; |
26 | sig_t intsave, quitsave; | |
a59df51f | 27 | |
f357e0f1 KB |
28 | if (!command) /* just checking... */ |
29 | return(1); | |
30 | ||
db505a5a | 31 | omask = sigblock(sigmask(SIGCHLD)); |
98295de1 KB |
32 | switch(pid = vfork()) { |
33 | case -1: /* error */ | |
db505a5a | 34 | (void)sigsetmask(omask); |
4d506f35 KB |
35 | pstat.w_status = 0; |
36 | pstat.w_retcode = 127; | |
37 | return(pstat.w_status); | |
98295de1 | 38 | case 0: /* child */ |
db505a5a | 39 | (void)sigsetmask(omask); |
a2f3a875 | 40 | execl(_PATH_BSHELL, "sh", "-c", command, (char *)NULL); |
a59df51f BJ |
41 | _exit(127); |
42 | } | |
a2f3a875 KB |
43 | intsave = signal(SIGINT, SIG_IGN); |
44 | quitsave = signal(SIGQUIT, SIG_IGN); | |
f0a345ab | 45 | pid = waitpid(pid, (int *)&pstat, 0); |
4d506f35 | 46 | (void)sigsetmask(omask); |
a2f3a875 KB |
47 | (void)signal(SIGINT, intsave); |
48 | (void)signal(SIGQUIT, quitsave); | |
4d506f35 | 49 | return(pid == -1 ? -1 : pstat.w_status); |
a59df51f | 50 | } |