4 * The system() function. If this turns out to actually be *used*,
5 * we may want to try to detect the very simple cases (no shell magic)
6 * and handle them internally, instead of requiring that /bin/sh be
16 int system(const char *string)
19 struct sigaction ignore, old_int, old_quit;
20 sigset_t masked, oldmask;
21 static const char *argv[] = { "/bin/sh", "-c", NULL, NULL };
24 /* Block SIGCHLD and ignore SIGINT and SIGQUIT */
25 /* Do this before the fork() to avoid races */
27 ignore.sa_handler = SIG_IGN;
28 sigemptyset(&ignore.sa_mask);
30 sigaction(SIGINT, &ignore, &old_int);
31 sigaction(SIGQUIT, &ignore, &old_quit);
34 sigaddset(&masked, SIGCHLD);
35 sigprocmask(SIG_BLOCK, &masked, &oldmask);
41 else if ( pid == 0 ) {
42 sigaction(SIGINT, &old_int, NULL);
43 sigaction(SIGQUIT, &old_quit, NULL);
44 sigprocmask(SIG_SETMASK, &oldmask, NULL);
48 execve(argv[0], (char * const *)argv, (char * const *)environ);
54 waitpid(pid, &status, 0);
56 sigaction(SIGINT, &old_int, NULL);
57 sigaction(SIGQUIT, &old_quit, NULL);
58 sigprocmask(SIG_SETMASK, &oldmask, NULL);