xref: /csrg-svn/lib/libc/stdlib/system.c (revision 35701)
1*35701Sbostic /*
2*35701Sbostic  * Copyright (c) 1988 The Regents of the University of California.
3*35701Sbostic  * All rights reserved.
4*35701Sbostic  *
5*35701Sbostic  * Redistribution and use in source and binary forms are permitted
6*35701Sbostic  * provided that the above copyright notice and this paragraph are
7*35701Sbostic  * duplicated in all such forms and that any documentation,
8*35701Sbostic  * advertising materials, and other materials related to such
9*35701Sbostic  * distribution and use acknowledge that the software was developed
10*35701Sbostic  * by the University of California, Berkeley.  The name of the
11*35701Sbostic  * University may not be used to endorse or promote products derived
12*35701Sbostic  * from this software without specific prior written permission.
13*35701Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14*35701Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15*35701Sbostic  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16*35701Sbostic  */
17*35701Sbostic 
1826603Sdonn #if defined(LIBC_SCCS) && !defined(lint)
19*35701Sbostic static char sccsid[] = "@(#)system.c	5.3 (Berkeley) 09/22/88";
20*35701Sbostic #endif /* LIBC_SCCS and not lint */
2122120Smckusick 
22*35701Sbostic #include <sys/wait.h>
23*35701Sbostic #include <sys/signal.h>
24*35701Sbostic #include <stdio.h>
252035Swnj 
26*35701Sbostic system(command)
27*35701Sbostic 	char *command;
282035Swnj {
29*35701Sbostic 	int pid, wval, (*i)(), (*q)();
30*35701Sbostic 	union wait stat_loc;
312035Swnj 
32*35701Sbostic 	switch(pid = vfork()) {
33*35701Sbostic 	case -1:			/* error */
34*35701Sbostic 		stat_loc.w_status = 0;
35*35701Sbostic 		stat_loc.w_retcode = 127;
36*35701Sbostic 		return(stat_loc.w_status);
37*35701Sbostic 	case 0:				/* child */
38*35701Sbostic 		execl("/bin/sh", "sh", "-c", command, (char *)NULL);
392035Swnj 		_exit(127);
402035Swnj 	}
41*35701Sbostic 	i = signal(SIGINT, SIG_IGN);
42*35701Sbostic 	q = signal(SIGQUIT, SIG_IGN);
43*35701Sbostic 	while ((wval = wait(&stat_loc)) != pid && wval != -1);
44*35701Sbostic 	(void)signal(SIGINT, i);
45*35701Sbostic 	(void)signal(SIGQUIT, q);
46*35701Sbostic 	return(wval == -1 ? -1 : stat_loc.w_status);
472035Swnj }
48