135701Sbostic /* 235701Sbostic * Copyright (c) 1988 The Regents of the University of California. 335701Sbostic * All rights reserved. 435701Sbostic * 542635Sbostic * %sccs.include.redist.c% 635701Sbostic */ 735701Sbostic 826603Sdonn #if defined(LIBC_SCCS) && !defined(lint) 9*46599Sdonn static char sccsid[] = "@(#)system.c 5.10 (Berkeley) 02/23/91"; 1035701Sbostic #endif /* LIBC_SCCS and not lint */ 1122120Smckusick 1236680Sbostic #include <sys/types.h> 1342138Sbostic #include <sys/signal.h> 1435701Sbostic #include <sys/wait.h> 1542138Sbostic #include <stdlib.h> 1642123Sbostic #include <stddef.h> 17*46599Sdonn #include <unistd.h> 1839192Sbostic #include <paths.h> 192035Swnj 2035701Sbostic system(command) 21*46599Sdonn const char *command; 222035Swnj { 2336680Sbostic union wait pstat; 24*46599Sdonn pid_t pid; 2539192Sbostic int omask; 2639192Sbostic sig_t intsave, quitsave; 272035Swnj 2842123Sbostic if (!command) /* just checking... */ 2942123Sbostic return(1); 3042123Sbostic 3136688Skarels omask = sigblock(sigmask(SIGCHLD)); 3235701Sbostic switch(pid = vfork()) { 3335701Sbostic case -1: /* error */ 3436688Skarels (void)sigsetmask(omask); 3536680Sbostic pstat.w_status = 0; 3636680Sbostic pstat.w_retcode = 127; 3736680Sbostic return(pstat.w_status); 3835701Sbostic case 0: /* child */ 3936688Skarels (void)sigsetmask(omask); 4039192Sbostic execl(_PATH_BSHELL, "sh", "-c", command, (char *)NULL); 412035Swnj _exit(127); 422035Swnj } 4339192Sbostic intsave = signal(SIGINT, SIG_IGN); 4439192Sbostic quitsave = signal(SIGQUIT, SIG_IGN); 45*46599Sdonn pid = waitpid(pid, (int *)&pstat, 0); 4636680Sbostic (void)sigsetmask(omask); 4739192Sbostic (void)signal(SIGINT, intsave); 4839192Sbostic (void)signal(SIGQUIT, quitsave); 4936680Sbostic return(pid == -1 ? -1 : pstat.w_status); 502035Swnj } 51