]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/posix/system.c
1 /* Copyright (C) 1991, 92, 94, 95, 96, 97 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 not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
24 #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 __libc_system (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
66 blocked. This makes it impossible for `system' to be implemented in
67 compliance with POSIX.2-1992. They have acknowledged that this is a bug
68 but I have not seen nor heard 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
) |
146 weak_alias (__libc_system
, system
)