1 /* Copyright (C) 1991, 1992, 1994 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If
16 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
25 #include <sys/types.h>
29 #define __environ environ
32 #define SHELL_PATH "/bin/sh" /* Path of the shell. */
33 #define SHELL_NAME "sh" /* Name to give it. */
35 /* Execute LINE as a shell command, returning its status. */
37 DEFUN(system, (line), register CONST char *line)
41 struct sigaction sa, intr, quit;
42 #ifndef WAITPID_CANNOT_BLOCK_SIGCHLD
43 sigset_t block, omask;
49 sa.sa_handler = SIG_IGN;
51 __sigemptyset (&sa.sa_mask);
53 if (__sigaction (SIGINT, &sa, &intr) < 0)
55 if (__sigaction (SIGQUIT, &sa, &quit) < 0)
58 (void) __sigaction (SIGINT, &intr, (struct sigaction *) NULL);
63 #ifndef WAITPID_CANNOT_BLOCK_SIGCHLD
65 /* SCO 3.2v4 has a bug where `waitpid' will never return if SIGCHLD is blocked.
67 They have acknowledged that this is a bug but I have not seen nor heard
68 of any forthcoming fix.
70 __sigemptyset (&block);
71 __sigaddset (&block, SIGCHLD);
73 if (__sigprocmask (SIG_BLOCK, &block, &omask) < 0)
80 (void) __sigaction (SIGINT, &intr, (struct sigaction *) NULL);
81 (void) __sigaction (SIGQUIT, &quit, (struct sigaction *) NULL);
86 #define UNBLOCK __sigprocmask (SIG_SETMASK, &omask, (sigset_t *) NULL)
95 CONST char *new_argv[4];
96 new_argv[0] = SHELL_NAME;
101 /* Restore the signals. */
102 (void) __sigaction (SIGINT, &intr, (struct sigaction *) NULL);
103 (void) __sigaction (SIGQUIT, &quit, (struct sigaction *) NULL);
106 /* Exec the shell. */
107 (void) __execve (SHELL_PATH, (char *CONST *) new_argv, __environ);
110 else if (pid < (pid_t) 0)
111 /* The fork failed. */
120 child = __wait (&status);
126 } while (child != pid);
129 if (__waitpid (pid, &status, 0) != pid)
134 if ((__sigaction (SIGINT, &intr, (struct sigaction *) NULL) |
135 __sigaction (SIGQUIT, &quit, (struct sigaction *) NULL) |