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