|
|
28653a |
commit 5fb7fc96350575c9adb1316833e48ca11553be49
|
|
|
28653a |
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
|
|
|
28653a |
Date: Wed Oct 24 16:29:38 2018 -0300
|
|
|
28653a |
|
|
|
28653a |
posix: Use posix_spawn on system
|
|
|
28653a |
|
|
|
28653a |
This patch uses posix_spawn on system implementation. On Linux this has
|
|
|
28653a |
the advantage of much lower memory consumption (usually 32 Kb minimum for
|
|
|
28653a |
the mmap stack area).
|
|
|
28653a |
|
|
|
28653a |
Although POSIX does not require, glibc system implementation aims to be
|
|
|
28653a |
thread and cancellation safe. The cancellation code is moved to generic
|
|
|
28653a |
implementation and enabled iff SIGCANCEL is defined (similar on how the
|
|
|
28653a |
cancellation handler is enabled on nptl-init.c).
|
|
|
28653a |
|
|
|
28653a |
Checked on x86_64-linux-gnu, i686-linux-gnu, aarch64-linux-gnu,
|
|
|
28653a |
arm-linux-gnueabihf, and powerpc64le-linux-gnu.
|
|
|
28653a |
|
|
|
28653a |
* sysdeps/unix/sysv/linux/spawni.c (__spawni_child): Use
|
|
|
28653a |
__sigismember instead of sigismember.
|
|
|
28653a |
* sysdeps/posix/system.c [SIGCANCEL] (cancel_handler_args,
|
|
|
28653a |
cancel_handler): New definitions.
|
|
|
28653a |
(CLEANUP_HANDLER, CLEANUP_RESET): Likewise.
|
|
|
28653a |
(DO_LOCK, DO_UNLOCK, INIT_LOCK, ADD_REF, SUB_REF): Remove.
|
|
|
28653a |
(do_system): Use posix_spawn instead of fork and execl and remove
|
|
|
28653a |
reentracy code.
|
|
|
28653a |
* sysdeps/generic/not-errno.h (__kill_noerrno): New prototype.
|
|
|
28653a |
* sysdeps/unix/sysv/linux/not-errno.h (__kill_noerrno): Likewise.
|
|
|
28653a |
* sysdeps/unix/sysv/linux/ia64/system.c: Remove file.
|
|
|
28653a |
* sysdeps/unix/sysv/linux/s390/system.c: Likewise.
|
|
|
28653a |
* sysdeps/unix/sysv/linux/sparc/system.c: Likewise.
|
|
|
28653a |
* sysdeps/unix/sysv/linux/system.c: Likewise.
|
|
|
28653a |
|
|
|
28653a |
diff --git a/sysdeps/generic/not-errno.h b/sysdeps/generic/not-errno.h
|
|
|
28653a |
index 93617a3266fd4aad..0fd66b5c5ed82315 100644
|
|
|
28653a |
--- a/sysdeps/generic/not-errno.h
|
|
|
28653a |
+++ b/sysdeps/generic/not-errno.h
|
|
|
28653a |
@@ -17,3 +17,5 @@
|
|
|
28653a |
<http://www.gnu.org/licenses/>. */
|
|
|
28653a |
|
|
|
28653a |
extern __typeof (__access) __access_noerrno attribute_hidden;
|
|
|
28653a |
+
|
|
|
28653a |
+extern __typeof (__kill) __kill_noerrno attribute_hidden;
|
|
|
28653a |
diff --git a/sysdeps/posix/system.c b/sysdeps/posix/system.c
|
|
|
28653a |
index d7594436ed59906f..8a51a6b9919ec39b 100644
|
|
|
28653a |
--- a/sysdeps/posix/system.c
|
|
|
28653a |
+++ b/sysdeps/posix/system.c
|
|
|
28653a |
@@ -17,20 +17,36 @@
|
|
|
28653a |
|
|
|
28653a |
#include <errno.h>
|
|
|
28653a |
#include <signal.h>
|
|
|
28653a |
-#include <stddef.h>
|
|
|
28653a |
#include <stdlib.h>
|
|
|
28653a |
#include <unistd.h>
|
|
|
28653a |
+#include <sigsetops.h>
|
|
|
28653a |
+#include <spawn.h>
|
|
|
28653a |
+#include <pthread.h>
|
|
|
28653a |
#include <sys/types.h>
|
|
|
28653a |
#include <sys/wait.h>
|
|
|
28653a |
-#include <libc-lock.h>
|
|
|
28653a |
-#include <sysdep-cancel.h>
|
|
|
28653a |
-#include <sigsetops.h>
|
|
|
28653a |
+#include <stdio.h>
|
|
|
28653a |
|
|
|
28653a |
+#include <libc-lock.h>
|
|
|
28653a |
+#include <not-errno.h>
|
|
|
28653a |
+#include <not-cancel.h>
|
|
|
28653a |
+#include <internal-signals.h>
|
|
|
28653a |
|
|
|
28653a |
#define SHELL_PATH "/bin/sh" /* Path of the shell. */
|
|
|
28653a |
#define SHELL_NAME "sh" /* Name to give it. */
|
|
|
28653a |
|
|
|
28653a |
|
|
|
28653a |
+/* This system implementation aims to be thread-safe, which requires to
|
|
|
28653a |
+ restore the signal dispositions for SIGINT and SIGQUIT correctly and to
|
|
|
28653a |
+ deal with cancellation by terminating the child process.
|
|
|
28653a |
+
|
|
|
28653a |
+ The signal disposition restoration on the single-thread case is
|
|
|
28653a |
+ straighfoward. For multithreaded case, a reference-counter with a lock
|
|
|
28653a |
+ is used, so the first thread will set the SIGINT/SIGQUIT dispositions and
|
|
|
28653a |
+ last thread will restore them.
|
|
|
28653a |
+
|
|
|
28653a |
+ Cancellation handling is done with thread cancellation clean-up handlers
|
|
|
28653a |
+ on waitpid call. */
|
|
|
28653a |
+
|
|
|
28653a |
#ifdef _LIBC_REENTRANT
|
|
|
28653a |
static struct sigaction intr, quit;
|
|
|
28653a |
static int sa_refcntr;
|
|
|
28653a |
@@ -50,17 +66,45 @@ __libc_lock_define_initialized (static, lock);
|
|
|
28653a |
#endif
|
|
|
28653a |
|
|
|
28653a |
|
|
|
28653a |
+#if defined(_LIBC_REENTRANT) && defined(SIGCANCEL)
|
|
|
28653a |
+struct cancel_handler_args
|
|
|
28653a |
+{
|
|
|
28653a |
+ struct sigaction *quit;
|
|
|
28653a |
+ struct sigaction *intr;
|
|
|
28653a |
+ pid_t pid;
|
|
|
28653a |
+};
|
|
|
28653a |
+
|
|
|
28653a |
+static void
|
|
|
28653a |
+cancel_handler (void *arg)
|
|
|
28653a |
+{
|
|
|
28653a |
+ struct cancel_handler_args *args = (struct cancel_handler_args *) (arg);
|
|
|
28653a |
+
|
|
|
28653a |
+ __kill_noerrno (args->pid, SIGKILL);
|
|
|
28653a |
+
|
|
|
28653a |
+ TEMP_FAILURE_RETRY (__waitpid_nocancel (args->pid, NULL, 0));
|
|
|
28653a |
+
|
|
|
28653a |
+ DO_LOCK ();
|
|
|
28653a |
+ if (SUB_REF () == 0)
|
|
|
28653a |
+ {
|
|
|
28653a |
+ __sigaction (SIGQUIT, args->quit, NULL);
|
|
|
28653a |
+ __sigaction (SIGINT, args->intr, NULL);
|
|
|
28653a |
+ }
|
|
|
28653a |
+ DO_UNLOCK ();
|
|
|
28653a |
+}
|
|
|
28653a |
+#endif
|
|
|
28653a |
+
|
|
|
28653a |
/* Execute LINE as a shell command, returning its status. */
|
|
|
28653a |
static int
|
|
|
28653a |
do_system (const char *line)
|
|
|
28653a |
{
|
|
|
28653a |
- int status, save;
|
|
|
28653a |
+ int status;
|
|
|
28653a |
pid_t pid;
|
|
|
28653a |
struct sigaction sa;
|
|
|
28653a |
#ifndef _LIBC_REENTRANT
|
|
|
28653a |
struct sigaction intr, quit;
|
|
|
28653a |
#endif
|
|
|
28653a |
sigset_t omask;
|
|
|
28653a |
+ sigset_t reset;
|
|
|
28653a |
|
|
|
28653a |
sa.sa_handler = SIG_IGN;
|
|
|
28653a |
sa.sa_flags = 0;
|
|
|
28653a |
@@ -69,105 +113,72 @@ do_system (const char *line)
|
|
|
28653a |
DO_LOCK ();
|
|
|
28653a |
if (ADD_REF () == 0)
|
|
|
28653a |
{
|
|
|
28653a |
- if (__sigaction (SIGINT, &sa, &intr) < 0)
|
|
|
28653a |
- {
|
|
|
28653a |
- (void) SUB_REF ();
|
|
|
28653a |
- goto out;
|
|
|
28653a |
- }
|
|
|
28653a |
- if (__sigaction (SIGQUIT, &sa, &quit) < 0)
|
|
|
28653a |
- {
|
|
|
28653a |
- save = errno;
|
|
|
28653a |
- (void) SUB_REF ();
|
|
|
28653a |
- goto out_restore_sigint;
|
|
|
28653a |
- }
|
|
|
28653a |
+ /* sigaction can not fail with SIGINT/SIGQUIT used with SIG_IGN. */
|
|
|
28653a |
+ __sigaction (SIGINT, &sa, &intr;;
|
|
|
28653a |
+ __sigaction (SIGQUIT, &sa, &quit);
|
|
|
28653a |
}
|
|
|
28653a |
DO_UNLOCK ();
|
|
|
28653a |
|
|
|
28653a |
- /* We reuse the bitmap in the 'sa' structure. */
|
|
|
28653a |
__sigaddset (&sa.sa_mask, SIGCHLD);
|
|
|
28653a |
- save = errno;
|
|
|
28653a |
- if (__sigprocmask (SIG_BLOCK, &sa.sa_mask, &omask) < 0)
|
|
|
28653a |
+ /* sigprocmask can not fail with SIG_BLOCK used with valid input
|
|
|
28653a |
+ arguments. */
|
|
|
28653a |
+ __sigprocmask (SIG_BLOCK, &sa.sa_mask, &omask);
|
|
|
28653a |
+
|
|
|
28653a |
+ __sigemptyset (&reset);
|
|
|
28653a |
+ if (intr.sa_handler != SIG_IGN)
|
|
|
28653a |
+ __sigaddset(&reset, SIGINT);
|
|
|
28653a |
+ if (quit.sa_handler != SIG_IGN)
|
|
|
28653a |
+ __sigaddset(&reset, SIGQUIT);
|
|
|
28653a |
+
|
|
|
28653a |
+ posix_spawnattr_t spawn_attr;
|
|
|
28653a |
+ /* None of the posix_spawnattr_* function returns an error, including
|
|
|
28653a |
+ posix_spawnattr_setflags for the follow specific usage (using valid
|
|
|
28653a |
+ flags). */
|
|
|
28653a |
+ __posix_spawnattr_init (&spawn_attr);
|
|
|
28653a |
+ __posix_spawnattr_setsigmask (&spawn_attr, &omask);
|
|
|
28653a |
+ __posix_spawnattr_setsigdefault (&spawn_attr, &reset);
|
|
|
28653a |
+ __posix_spawnattr_setflags (&spawn_attr,
|
|
|
28653a |
+ POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK);
|
|
|
28653a |
+
|
|
|
28653a |
+ status = __posix_spawn (&pid, SHELL_PATH, 0, &spawn_attr,
|
|
|
28653a |
+ (char *const[]){ (char*) SHELL_NAME,
|
|
|
28653a |
+ (char*) "-c",
|
|
|
28653a |
+ (char *) line, NULL },
|
|
|
28653a |
+ __environ);
|
|
|
28653a |
+ __posix_spawnattr_destroy (&spawn_attr);
|
|
|
28653a |
+
|
|
|
28653a |
+ if (status == 0)
|
|
|
28653a |
{
|
|
|
28653a |
-#ifndef _LIBC
|
|
|
28653a |
- if (errno == ENOSYS)
|
|
|
28653a |
- __set_errno (save);
|
|
|
28653a |
- else
|
|
|
28653a |
-#endif
|
|
|
28653a |
- {
|
|
|
28653a |
- DO_LOCK ();
|
|
|
28653a |
- if (SUB_REF () == 0)
|
|
|
28653a |
- {
|
|
|
28653a |
- save = errno;
|
|
|
28653a |
- (void) __sigaction (SIGQUIT, &quit, (struct sigaction *) NULL);
|
|
|
28653a |
- out_restore_sigint:
|
|
|
28653a |
- (void) __sigaction (SIGINT, &intr, (struct sigaction *) NULL);
|
|
|
28653a |
- __set_errno (save);
|
|
|
28653a |
- }
|
|
|
28653a |
- out:
|
|
|
28653a |
- DO_UNLOCK ();
|
|
|
28653a |
- return -1;
|
|
|
28653a |
- }
|
|
|
28653a |
- }
|
|
|
28653a |
-
|
|
|
28653a |
-#ifdef CLEANUP_HANDLER
|
|
|
28653a |
- CLEANUP_HANDLER;
|
|
|
28653a |
-#endif
|
|
|
28653a |
-
|
|
|
28653a |
-#ifdef FORK
|
|
|
28653a |
- pid = FORK ();
|
|
|
28653a |
-#else
|
|
|
28653a |
- pid = __fork ();
|
|
|
28653a |
+ /* Cancellation results in cleanup handlers running as exceptions in
|
|
|
28653a |
+ the block where they were installed, so it is safe to reference
|
|
|
28653a |
+ stack variable allocate in the broader scope. */
|
|
|
28653a |
+#if defined(_LIBC_REENTRANT) && defined(SIGCANCEL)
|
|
|
28653a |
+ struct cancel_handler_args cancel_args =
|
|
|
28653a |
+ {
|
|
|
28653a |
+ .quit = &quit,
|
|
|
28653a |
+ .intr = &intr,
|
|
|
28653a |
+ .pid = pid
|
|
|
28653a |
+ };
|
|
|
28653a |
+ __libc_cleanup_region_start (1, cancel_handler, &cancel_args);
|
|
|
28653a |
#endif
|
|
|
28653a |
- if (pid == (pid_t) 0)
|
|
|
28653a |
- {
|
|
|
28653a |
- /* Child side. */
|
|
|
28653a |
- const char *new_argv[4];
|
|
|
28653a |
- new_argv[0] = SHELL_NAME;
|
|
|
28653a |
- new_argv[1] = "-c";
|
|
|
28653a |
- new_argv[2] = line;
|
|
|
28653a |
- new_argv[3] = NULL;
|
|
|
28653a |
-
|
|
|
28653a |
- /* Restore the signals. */
|
|
|
28653a |
- (void) __sigaction (SIGINT, &intr, (struct sigaction *) NULL);
|
|
|
28653a |
- (void) __sigaction (SIGQUIT, &quit, (struct sigaction *) NULL);
|
|
|
28653a |
- (void) __sigprocmask (SIG_SETMASK, &omask, (sigset_t *) NULL);
|
|
|
28653a |
- INIT_LOCK ();
|
|
|
28653a |
-
|
|
|
28653a |
- /* Exec the shell. */
|
|
|
28653a |
- (void) __execve (SHELL_PATH, (char *const *) new_argv, __environ);
|
|
|
28653a |
- _exit (127);
|
|
|
28653a |
- }
|
|
|
28653a |
- else if (pid < (pid_t) 0)
|
|
|
28653a |
- /* The fork failed. */
|
|
|
28653a |
- status = -1;
|
|
|
28653a |
- else
|
|
|
28653a |
- /* Parent side. */
|
|
|
28653a |
- {
|
|
|
28653a |
/* Note the system() is a cancellation point. But since we call
|
|
|
28653a |
waitpid() which itself is a cancellation point we do not
|
|
|
28653a |
have to do anything here. */
|
|
|
28653a |
if (TEMP_FAILURE_RETRY (__waitpid (pid, &status, 0)) != pid)
|
|
|
28653a |
status = -1;
|
|
|
28653a |
- }
|
|
|
28653a |
-
|
|
|
28653a |
-#ifdef CLEANUP_HANDLER
|
|
|
28653a |
- CLEANUP_RESET;
|
|
|
28653a |
+#if defined(_LIBC_REENTRANT) && defined(SIGCANCEL)
|
|
|
28653a |
+ __libc_cleanup_region_end (0);
|
|
|
28653a |
#endif
|
|
|
28653a |
+ }
|
|
|
28653a |
|
|
|
28653a |
- save = errno;
|
|
|
28653a |
DO_LOCK ();
|
|
|
28653a |
- if ((SUB_REF () == 0
|
|
|
28653a |
- && (__sigaction (SIGINT, &intr, (struct sigaction *) NULL)
|
|
|
28653a |
- | __sigaction (SIGQUIT, &quit, (struct sigaction *) NULL)) != 0)
|
|
|
28653a |
- || __sigprocmask (SIG_SETMASK, &omask, (sigset_t *) NULL) != 0)
|
|
|
28653a |
+ if (SUB_REF () == 0)
|
|
|
28653a |
{
|
|
|
28653a |
-#ifndef _LIBC
|
|
|
28653a |
- /* glibc cannot be used on systems without waitpid. */
|
|
|
28653a |
- if (errno == ENOSYS)
|
|
|
28653a |
- __set_errno (save);
|
|
|
28653a |
- else
|
|
|
28653a |
-#endif
|
|
|
28653a |
- status = -1;
|
|
|
28653a |
+ /* sigaction can not fail with SIGINT/SIGQUIT used with old
|
|
|
28653a |
+ disposition. Same applies for sigprocmask. */
|
|
|
28653a |
+ __sigaction (SIGINT, &intr, NULL);
|
|
|
28653a |
+ __sigaction (SIGQUIT, &quit, NULL);
|
|
|
28653a |
+ __sigprocmask (SIG_SETMASK, &omask, NULL);
|
|
|
28653a |
}
|
|
|
28653a |
DO_UNLOCK ();
|
|
|
28653a |
|
|
|
28653a |
diff --git a/sysdeps/unix/sysv/linux/ia64/system.c b/sysdeps/unix/sysv/linux/ia64/system.c
|
|
|
28653a |
deleted file mode 100644
|
|
|
28653a |
index d09fefefe64753ab..0000000000000000
|
|
|
28653a |
--- a/sysdeps/unix/sysv/linux/ia64/system.c
|
|
|
28653a |
+++ /dev/null
|
|
|
28653a |
@@ -1,30 +0,0 @@
|
|
|
28653a |
-/* Copyright (C) 2002-2018 Free Software Foundation, Inc.
|
|
|
28653a |
- This file is part of the GNU C Library.
|
|
|
28653a |
-
|
|
|
28653a |
- The GNU C Library is free software; you can redistribute it and/or
|
|
|
28653a |
- modify it under the terms of the GNU Lesser General Public
|
|
|
28653a |
- License as published by the Free Software Foundation; either
|
|
|
28653a |
- version 2.1 of the License, or (at your option) any later version.
|
|
|
28653a |
-
|
|
|
28653a |
- The GNU C Library is distributed in the hope that it will be useful,
|
|
|
28653a |
- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
28653a |
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
28653a |
- Lesser General Public License for more details.
|
|
|
28653a |
-
|
|
|
28653a |
- You should have received a copy of the GNU Lesser General Public
|
|
|
28653a |
- License along with the GNU C Library; if not, see
|
|
|
28653a |
- <http://www.gnu.org/licenses/>. */
|
|
|
28653a |
-
|
|
|
28653a |
-/* We have to and actually can handle cancelable system(). The big
|
|
|
28653a |
- problem: we have to kill the child process if necessary. To do
|
|
|
28653a |
- this a cleanup handler has to be registered and is has to be able
|
|
|
28653a |
- to find the PID of the child. The main problem is to reliable have
|
|
|
28653a |
- the PID when needed. It is not necessary for the parent thread to
|
|
|
28653a |
- return. It might still be in the kernel when the cancellation
|
|
|
28653a |
- request comes. Therefore we have to use the clone() calls ability
|
|
|
28653a |
- to have the kernel write the PID into the user-level variable. */
|
|
|
28653a |
-#define FORK() \
|
|
|
28653a |
- INLINE_SYSCALL (clone2, 6, CLONE_PARENT_SETTID | SIGCHLD, NULL, 0, \
|
|
|
28653a |
- &pid, NULL, NULL)
|
|
|
28653a |
-
|
|
|
28653a |
-#include <sysdeps/unix/sysv/linux/system.c>
|
|
|
28653a |
diff --git a/sysdeps/unix/sysv/linux/not-errno.h b/sysdeps/unix/sysv/linux/not-errno.h
|
|
|
28653a |
index 106ba5c72e3d7dda..b2f72cfb3d412c56 100644
|
|
|
28653a |
--- a/sysdeps/unix/sysv/linux/not-errno.h
|
|
|
28653a |
+++ b/sysdeps/unix/sysv/linux/not-errno.h
|
|
|
28653a |
@@ -16,6 +16,9 @@
|
|
|
28653a |
License along with the GNU C Library; if not, see
|
|
|
28653a |
<http://www.gnu.org/licenses/>. */
|
|
|
28653a |
|
|
|
28653a |
+#include <sysdep.h>
|
|
|
28653a |
+#include <fcntl.h>
|
|
|
28653a |
+
|
|
|
28653a |
/* This function is used on maybe_enable_malloc_check (elf/dl-tunables.c)
|
|
|
28653a |
and to avoid having to build/use multiple versions if stack protection
|
|
|
28653a |
in enabled it is defined as inline. */
|
|
|
28653a |
@@ -33,3 +36,14 @@ __access_noerrno (const char *pathname, int mode)
|
|
|
28653a |
return INTERNAL_SYSCALL_ERRNO (res, err);
|
|
|
28653a |
return 0;
|
|
|
28653a |
}
|
|
|
28653a |
+
|
|
|
28653a |
+static inline int
|
|
|
28653a |
+__kill_noerrno (pid_t pid, int sig)
|
|
|
28653a |
+{
|
|
|
28653a |
+ int res;
|
|
|
28653a |
+ INTERNAL_SYSCALL_DECL (err);
|
|
|
28653a |
+ res = INTERNAL_SYSCALL_CALL (kill, err, pid, sig);
|
|
|
28653a |
+ if (INTERNAL_SYSCALL_ERROR_P (res, err))
|
|
|
28653a |
+ return INTERNAL_SYSCALL_ERRNO (res, err);
|
|
|
28653a |
+ return 0;
|
|
|
28653a |
+}
|
|
|
28653a |
diff --git a/sysdeps/unix/sysv/linux/s390/system.c b/sysdeps/unix/sysv/linux/s390/system.c
|
|
|
28653a |
deleted file mode 100644
|
|
|
28653a |
index d8ef46133419dd89..0000000000000000
|
|
|
28653a |
--- a/sysdeps/unix/sysv/linux/s390/system.c
|
|
|
28653a |
+++ /dev/null
|
|
|
28653a |
@@ -1,29 +0,0 @@
|
|
|
28653a |
-/* Copyright (C) 2003-2018 Free Software Foundation, Inc.
|
|
|
28653a |
- This file is part of the GNU C Library.
|
|
|
28653a |
-
|
|
|
28653a |
- The GNU C Library is free software; you can redistribute it and/or
|
|
|
28653a |
- modify it under the terms of the GNU Lesser General Public
|
|
|
28653a |
- License as published by the Free Software Foundation; either
|
|
|
28653a |
- version 2.1 of the License, or (at your option) any later version.
|
|
|
28653a |
-
|
|
|
28653a |
- The GNU C Library is distributed in the hope that it will be useful,
|
|
|
28653a |
- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
28653a |
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
28653a |
- Lesser General Public License for more details.
|
|
|
28653a |
-
|
|
|
28653a |
- You should have received a copy of the GNU Lesser General Public
|
|
|
28653a |
- License along with the GNU C Library; if not, see
|
|
|
28653a |
- <http://www.gnu.org/licenses/>. */
|
|
|
28653a |
-
|
|
|
28653a |
-/* We have to and actually can handle cancelable system(). The big
|
|
|
28653a |
- problem: we have to kill the child process if necessary. To do
|
|
|
28653a |
- this a cleanup handler has to be registered and is has to be able
|
|
|
28653a |
- to find the PID of the child. The main problem is to reliable have
|
|
|
28653a |
- the PID when needed. It is not necessary for the parent thread to
|
|
|
28653a |
- return. It might still be in the kernel when the cancellation
|
|
|
28653a |
- request comes. Therefore we have to use the clone() calls ability
|
|
|
28653a |
- to have the kernel write the PID into the user-level variable. */
|
|
|
28653a |
-#define FORK() \
|
|
|
28653a |
- INLINE_SYSCALL (clone, 3, 0, CLONE_PARENT_SETTID | SIGCHLD, &pid)
|
|
|
28653a |
-
|
|
|
28653a |
-#include "../system.c"
|
|
|
28653a |
diff --git a/sysdeps/unix/sysv/linux/sparc/system.c b/sysdeps/unix/sysv/linux/sparc/system.c
|
|
|
28653a |
deleted file mode 100644
|
|
|
28653a |
index 1f65c83399f920d6..0000000000000000
|
|
|
28653a |
--- a/sysdeps/unix/sysv/linux/sparc/system.c
|
|
|
28653a |
+++ /dev/null
|
|
|
28653a |
@@ -1,29 +0,0 @@
|
|
|
28653a |
-/* Copyright (C) 2003-2018 Free Software Foundation, Inc.
|
|
|
28653a |
- This file is part of the GNU C Library.
|
|
|
28653a |
-
|
|
|
28653a |
- The GNU C Library is free software; you can redistribute it and/or
|
|
|
28653a |
- modify it under the terms of the GNU Lesser General Public
|
|
|
28653a |
- License as published by the Free Software Foundation; either
|
|
|
28653a |
- version 2.1 of the License, or (at your option) any later version.
|
|
|
28653a |
-
|
|
|
28653a |
- The GNU C Library is distributed in the hope that it will be useful,
|
|
|
28653a |
- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
28653a |
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
28653a |
- Lesser General Public License for more details.
|
|
|
28653a |
-
|
|
|
28653a |
- You should have received a copy of the GNU Lesser General Public
|
|
|
28653a |
- License along with the GNU C Library; if not, see
|
|
|
28653a |
- <http://www.gnu.org/licenses/>. */
|
|
|
28653a |
-
|
|
|
28653a |
-/* We have to and actually can handle cancelable system(). The big
|
|
|
28653a |
- problem: we have to kill the child process if necessary. To do
|
|
|
28653a |
- this a cleanup handler has to be registered and is has to be able
|
|
|
28653a |
- to find the PID of the child. The main problem is to reliable have
|
|
|
28653a |
- the PID when needed. It is not necessary for the parent thread to
|
|
|
28653a |
- return. It might still be in the kernel when the cancellation
|
|
|
28653a |
- request comes. Therefore we have to use the clone() calls ability
|
|
|
28653a |
- to have the kernel write the PID into the user-level variable. */
|
|
|
28653a |
-#define FORK() \
|
|
|
28653a |
- INLINE_CLONE_SYSCALL (CLONE_PARENT_SETTID | SIGCHLD, 0, &pid, NULL, NULL)
|
|
|
28653a |
-
|
|
|
28653a |
-#include "../system.c"
|
|
|
28653a |
diff --git a/sysdeps/unix/sysv/linux/spawni.c b/sysdeps/unix/sysv/linux/spawni.c
|
|
|
28653a |
index 85239cedbf2a5ab5..6a8bd2ed2e1c29b7 100644
|
|
|
28653a |
--- a/sysdeps/unix/sysv/linux/spawni.c
|
|
|
28653a |
+++ b/sysdeps/unix/sysv/linux/spawni.c
|
|
|
28653a |
@@ -138,11 +138,11 @@ __spawni_child (void *arguments)
|
|
|
28653a |
for (int sig = 1; sig < _NSIG; ++sig)
|
|
|
28653a |
{
|
|
|
28653a |
if ((attr->__flags & POSIX_SPAWN_SETSIGDEF)
|
|
|
28653a |
- && sigismember (&attr->__sd, sig))
|
|
|
28653a |
+ && __sigismember (&attr->__sd, sig))
|
|
|
28653a |
{
|
|
|
28653a |
sa.sa_handler = SIG_DFL;
|
|
|
28653a |
}
|
|
|
28653a |
- else if (sigismember (&hset, sig))
|
|
|
28653a |
+ else if (__sigismember (&hset, sig))
|
|
|
28653a |
{
|
|
|
28653a |
if (__is_internal_signal (sig))
|
|
|
28653a |
sa.sa_handler = SIG_IGN;
|
|
|
28653a |
diff --git a/sysdeps/unix/sysv/linux/system.c b/sysdeps/unix/sysv/linux/system.c
|
|
|
28653a |
deleted file mode 100644
|
|
|
28653a |
index 7cc68a1528ee8f99..0000000000000000
|
|
|
28653a |
--- a/sysdeps/unix/sysv/linux/system.c
|
|
|
28653a |
+++ /dev/null
|
|
|
28653a |
@@ -1,76 +0,0 @@
|
|
|
28653a |
-/* Copyright (C) 2002-2018 Free Software Foundation, Inc.
|
|
|
28653a |
- This file is part of the GNU C Library.
|
|
|
28653a |
-
|
|
|
28653a |
- The GNU C Library is free software; you can redistribute it and/or
|
|
|
28653a |
- modify it under the terms of the GNU Lesser General Public
|
|
|
28653a |
- License as published by the Free Software Foundation; either
|
|
|
28653a |
- version 2.1 of the License, or (at your option) any later version.
|
|
|
28653a |
-
|
|
|
28653a |
- The GNU C Library is distributed in the hope that it will be useful,
|
|
|
28653a |
- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
28653a |
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
28653a |
- Lesser General Public License for more details.
|
|
|
28653a |
-
|
|
|
28653a |
- You should have received a copy of the GNU Lesser General Public
|
|
|
28653a |
- License along with the GNU C Library; if not, see
|
|
|
28653a |
- <http://www.gnu.org/licenses/>. */
|
|
|
28653a |
-
|
|
|
28653a |
-#include <sched.h>
|
|
|
28653a |
-#include <signal.h>
|
|
|
28653a |
-#include <string.h> /* For the real memset prototype. */
|
|
|
28653a |
-#include <sysdep.h>
|
|
|
28653a |
-#include <unistd.h>
|
|
|
28653a |
-#include <sys/wait.h>
|
|
|
28653a |
-#include <libc-lock.h>
|
|
|
28653a |
-
|
|
|
28653a |
-/* We have to and actually can handle cancelable system(). The big
|
|
|
28653a |
- problem: we have to kill the child process if necessary. To do
|
|
|
28653a |
- this a cleanup handler has to be registered and is has to be able
|
|
|
28653a |
- to find the PID of the child. The main problem is to reliable have
|
|
|
28653a |
- the PID when needed. It is not necessary for the parent thread to
|
|
|
28653a |
- return. It might still be in the kernel when the cancellation
|
|
|
28653a |
- request comes. Therefore we have to use the clone() calls ability
|
|
|
28653a |
- to have the kernel write the PID into the user-level variable. */
|
|
|
28653a |
-#ifndef FORK
|
|
|
28653a |
-# define FORK() \
|
|
|
28653a |
- INLINE_SYSCALL (clone, 3, CLONE_PARENT_SETTID | SIGCHLD, 0, &pid)
|
|
|
28653a |
-#endif
|
|
|
28653a |
-
|
|
|
28653a |
-#ifdef _LIBC_REENTRANT
|
|
|
28653a |
-static void cancel_handler (void *arg);
|
|
|
28653a |
-
|
|
|
28653a |
-# define CLEANUP_HANDLER \
|
|
|
28653a |
- __libc_cleanup_region_start (1, cancel_handler, &pid)
|
|
|
28653a |
-
|
|
|
28653a |
-# define CLEANUP_RESET \
|
|
|
28653a |
- __libc_cleanup_region_end (0)
|
|
|
28653a |
-#endif
|
|
|
28653a |
-
|
|
|
28653a |
-
|
|
|
28653a |
-/* Linux has waitpid(), so override the generic unix version. */
|
|
|
28653a |
-#include <sysdeps/posix/system.c>
|
|
|
28653a |
-
|
|
|
28653a |
-
|
|
|
28653a |
-#ifdef _LIBC_REENTRANT
|
|
|
28653a |
-/* The cancellation handler. */
|
|
|
28653a |
-static void
|
|
|
28653a |
-cancel_handler (void *arg)
|
|
|
28653a |
-{
|
|
|
28653a |
- pid_t child = *(pid_t *) arg;
|
|
|
28653a |
-
|
|
|
28653a |
- INTERNAL_SYSCALL_DECL (err);
|
|
|
28653a |
- INTERNAL_SYSCALL (kill, err, 2, child, SIGKILL);
|
|
|
28653a |
-
|
|
|
28653a |
- TEMP_FAILURE_RETRY (__waitpid (child, NULL, 0));
|
|
|
28653a |
-
|
|
|
28653a |
- DO_LOCK ();
|
|
|
28653a |
-
|
|
|
28653a |
- if (SUB_REF () == 0)
|
|
|
28653a |
- {
|
|
|
28653a |
- (void) __sigaction (SIGQUIT, &quit, (struct sigaction *) NULL);
|
|
|
28653a |
- (void) __sigaction (SIGINT, &intr, (struct sigaction *) NULL);
|
|
|
28653a |
- }
|
|
|
28653a |
-
|
|
|
28653a |
- DO_UNLOCK ();
|
|
|
28653a |
-}
|
|
|
28653a |
-#endif
|