1 /* Copyright (C) 1991, 1992, 1994, 1995 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>
30 #define __environ environ
33 #define SHELL_PATH "/bin/sh" /* Path of the shell. */
34 #define SHELL_NAME "sh" /* Name to give it. */
36 /* Execute LINE as a shell command, returning its status. */
38 DEFUN(system, (line), register CONST char *line)
42 struct sigaction sa, intr, quit;
43 #ifndef WAITPID_CANNOT_BLOCK_SIGCHLD
44 sigset_t block, omask;
50 sa.sa_handler = SIG_IGN;
52 __sigemptyset (&sa.sa_mask);
54 if (__sigaction (SIGINT, &sa, &intr) < 0)
56 if (__sigaction (SIGQUIT, &sa, &quit) < 0)
59 (void) __sigaction (SIGINT, &intr, (struct sigaction *) NULL);
64 #ifndef WAITPID_CANNOT_BLOCK_SIGCHLD
66 /* SCO 3.2v4 has a bug where `waitpid' will never return if SIGCHLD is
67 blocked. This makes it impossible for `system' to be implemented in
68 compliance with POSIX.2-1992. They have acknowledged that this is a bug
69 but I have not seen nor heard of any forthcoming fix. */
71 __sigemptyset (&block);
72 __sigaddset (&block, SIGCHLD);
74 if (__sigprocmask (SIG_BLOCK, &block, &omask) < 0)
81 (void) __sigaction (SIGINT, &intr, (struct sigaction *) NULL);
82 (void) __sigaction (SIGQUIT, &quit, (struct sigaction *) NULL);
87 #define UNBLOCK __sigprocmask (SIG_SETMASK, &omask, (sigset_t *) NULL)
96 CONST char *new_argv[4];
97 new_argv[0] = SHELL_NAME;
102 /* Restore the signals. */
103 (void) __sigaction (SIGINT, &intr, (struct sigaction *) NULL);
104 (void) __sigaction (SIGQUIT, &quit, (struct sigaction *) NULL);
107 /* Exec the shell. */
108 (void) __execve (SHELL_PATH, (char *CONST *) new_argv, __environ);
111 else if (pid < (pid_t) 0)
112 /* The fork failed. */
121 child = __wait (&status);
127 } while (child != pid);
130 if (__waitpid (pid, &status, 0) != pid)
135 if ((__sigaction (SIGINT, &intr, (struct sigaction *) NULL) |
136 __sigaction (SIGQUIT, &quit, (struct sigaction *) NULL) |