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*39192Sbostic static char sccsid[] = "@(#)system.c 5.6 (Berkeley) 09/21/89"; 2035701Sbostic #endif /* LIBC_SCCS and not lint */ 2122120Smckusick 2236680Sbostic #include <sys/types.h> 2335701Sbostic #include <sys/wait.h> 2435701Sbostic #include <sys/signal.h> 2535701Sbostic #include <stdio.h> 26*39192Sbostic #include <paths.h> 272035Swnj 2835701Sbostic system(command) 2935701Sbostic char *command; 302035Swnj { 3136680Sbostic union wait pstat; 3236680Sbostic pid_t pid, waitpid(); 33*39192Sbostic int omask; 34*39192Sbostic sig_t intsave, quitsave; 352035Swnj 3636688Skarels omask = sigblock(sigmask(SIGCHLD)); 3735701Sbostic switch(pid = vfork()) { 3835701Sbostic case -1: /* error */ 3936688Skarels (void)sigsetmask(omask); 4036680Sbostic pstat.w_status = 0; 4136680Sbostic pstat.w_retcode = 127; 4236680Sbostic return(pstat.w_status); 4335701Sbostic case 0: /* child */ 4436688Skarels (void)sigsetmask(omask); 45*39192Sbostic execl(_PATH_BSHELL, "sh", "-c", command, (char *)NULL); 462035Swnj _exit(127); 472035Swnj } 48*39192Sbostic intsave = signal(SIGINT, SIG_IGN); 49*39192Sbostic quitsave = signal(SIGQUIT, SIG_IGN); 5036680Sbostic pid = waitpid(pid, &pstat, 0); 5136680Sbostic (void)sigsetmask(omask); 52*39192Sbostic (void)signal(SIGINT, intsave); 53*39192Sbostic (void)signal(SIGQUIT, quitsave); 5436680Sbostic return(pid == -1 ? -1 : pstat.w_status); 552035Swnj } 56