135701Sbostic /* 235701Sbostic * Copyright (c) 1988 The Regents of the University of California. 335701Sbostic * All rights reserved. 435701Sbostic * 535701Sbostic * Redistribution and use in source and binary forms are permitted 635701Sbostic * provided that the above copyright notice and this paragraph are 735701Sbostic * duplicated in all such forms and that any documentation, 835701Sbostic * advertising materials, and other materials related to such 935701Sbostic * distribution and use acknowledge that the software was developed 1035701Sbostic * by the University of California, Berkeley. The name of the 1135701Sbostic * University may not be used to endorse or promote products derived 1235701Sbostic * from this software without specific prior written permission. 1335701Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 1435701Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 1535701Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1635701Sbostic */ 1735701Sbostic 1826603Sdonn #if defined(LIBC_SCCS) && !defined(lint) 19*42138Sbostic static char sccsid[] = "@(#)system.c 5.8 (Berkeley) 05/16/90"; 2035701Sbostic #endif /* LIBC_SCCS and not lint */ 2122120Smckusick 2236680Sbostic #include <sys/types.h> 23*42138Sbostic #include <sys/signal.h> 2435701Sbostic #include <sys/wait.h> 25*42138Sbostic #include <stdlib.h> 2642123Sbostic #include <stddef.h> 2739192Sbostic #include <paths.h> 282035Swnj 2935701Sbostic system(command) 3035701Sbostic char *command; 312035Swnj { 3236680Sbostic union wait pstat; 3336680Sbostic pid_t pid, waitpid(); 3439192Sbostic int omask; 3539192Sbostic sig_t intsave, quitsave; 362035Swnj 3742123Sbostic if (!command) /* just checking... */ 3842123Sbostic return(1); 3942123Sbostic 4036688Skarels omask = sigblock(sigmask(SIGCHLD)); 4135701Sbostic switch(pid = vfork()) { 4235701Sbostic case -1: /* error */ 4336688Skarels (void)sigsetmask(omask); 4436680Sbostic pstat.w_status = 0; 4536680Sbostic pstat.w_retcode = 127; 4636680Sbostic return(pstat.w_status); 4735701Sbostic case 0: /* child */ 4836688Skarels (void)sigsetmask(omask); 4939192Sbostic execl(_PATH_BSHELL, "sh", "-c", command, (char *)NULL); 502035Swnj _exit(127); 512035Swnj } 5239192Sbostic intsave = signal(SIGINT, SIG_IGN); 5339192Sbostic quitsave = signal(SIGQUIT, SIG_IGN); 5436680Sbostic pid = waitpid(pid, &pstat, 0); 5536680Sbostic (void)sigsetmask(omask); 5639192Sbostic (void)signal(SIGINT, intsave); 5739192Sbostic (void)signal(SIGQUIT, quitsave); 5836680Sbostic return(pid == -1 ? -1 : pstat.w_status); 592035Swnj } 60