xref: /csrg-svn/lib/libc/stdlib/system.c (revision 2035)
1*2035Swnj /* @(#)system.c	4.1 (Berkeley) 12/21/80 */
2*2035Swnj #include	<signal.h>
3*2035Swnj 
4*2035Swnj system(s)
5*2035Swnj char *s;
6*2035Swnj {
7*2035Swnj 	int status, pid, w;
8*2035Swnj 	register int (*istat)(), (*qstat)();
9*2035Swnj 
10*2035Swnj 	if ((pid = vfork()) == 0) {
11*2035Swnj 		execl("/bin/sh", "sh", "-c", s, 0);
12*2035Swnj 		_exit(127);
13*2035Swnj 	}
14*2035Swnj 	istat = signal(SIGINT, SIG_IGN);
15*2035Swnj 	qstat = signal(SIGQUIT, SIG_IGN);
16*2035Swnj 	while ((w = wait(&status)) != pid && w != -1)
17*2035Swnj 		;
18*2035Swnj 	if (w == -1)
19*2035Swnj 		status = -1;
20*2035Swnj 	signal(SIGINT, istat);
21*2035Swnj 	signal(SIGQUIT, qstat);
22*2035Swnj 	return(status);
23*2035Swnj }
24