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