135701Sbostic /*
2*61180Sbostic * Copyright (c) 1988, 1993
3*61180Sbostic * The Regents of the University of California. All rights reserved.
435701Sbostic *
542635Sbostic * %sccs.include.redist.c%
635701Sbostic */
735701Sbostic
826603Sdonn #if defined(LIBC_SCCS) && !defined(lint)
9*61180Sbostic static char sccsid[] = "@(#)system.c 8.1 (Berkeley) 06/04/93";
1035701Sbostic #endif /* LIBC_SCCS and not lint */
1122120Smckusick
1236680Sbostic #include <sys/types.h>
1335701Sbostic #include <sys/wait.h>
1451655Sbostic #include <signal.h>
1542138Sbostic #include <stdlib.h>
1642123Sbostic #include <stddef.h>
1746599Sdonn #include <unistd.h>
1839192Sbostic #include <paths.h>
192035Swnj
system(command)2035701Sbostic system(command)
2146599Sdonn const char *command;
222035Swnj {
2336680Sbostic union wait pstat;
2446599Sdonn 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);
4546599Sdonn 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