1 /* Copyright (C) 1991, 1992 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. */
39 /* Execute LINE as a shell command, returning its status. */
41 DEFUN(system, (line), register CONST char *line)
45 struct sigaction sa, intr, quit;
46 sigset_t block, omask;
51 sa.sa_handler = SIG_IGN;
53 if (__sigemptyset(&sa.sa_mask) < 0)
55 if (__sigaction(SIGINT, &sa, &intr) < 0)
57 if (__sigaction(SIGQUIT, &sa, &quit) < 0)
59 (void) __sigaction(SIGINT, &intr, (struct sigaction *) NULL);
62 if (__sigemptyset(&block) < 0 || __sigaddset(&block, SIGCHLD) < 0 ||
63 __sigprocmask(SIG_BLOCK, &block, &omask) < 0)
65 (void) __sigaction(SIGINT, &intr, (struct sigaction *) NULL);
66 (void) __sigaction(SIGQUIT, &quit, (struct sigaction *) NULL);
74 CONST char *new_argv[4];
75 new_argv[0] = SHELL_NAME;
80 /* Restore the signals. */
81 (void) __sigaction(SIGINT, &intr, (struct sigaction *) NULL);
82 (void) __sigaction(SIGQUIT, &quit, (struct sigaction *) NULL);
83 (void) __sigprocmask(SIG_SETMASK, &omask, (sigset_t *) NULL);
86 (void) __execve(SHELL_PATH, (char *CONST *) new_argv, __environ);
89 else if (pid < (pid_t) 0)
90 /* The fork failed. */
99 child = __wait (&status);
105 } while (child != pid);
108 if (__waitpid(pid, &status, 0) != pid)
112 if ((__sigaction(SIGINT, &intr, (struct sigaction *) NULL) |
113 __sigaction(SIGQUIT, &quit, (struct sigaction *) NULL) |
114 __sigprocmask(SIG_SETMASK, &omask, (sigset_t *) NULL)) != 0)