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