]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Linux: Add the tgkill function
authorFlorian Weimer <fweimer@redhat.com>
Tue, 14 May 2019 19:35:09 +0000 (21:35 +0200)
committerFlorian Weimer <fweimer@redhat.com>
Tue, 14 May 2019 20:55:51 +0000 (22:55 +0200)
The tgkill function is sometimes used in crash handlers.

<bits/signal_ext.h> follows the same approach as <bits/unistd_ext.h>
(which was added for the gettid system call wrapper).

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
38 files changed:
ChangeLog
NEWS
bits/signal_ext.h [new file with mode: 0644]
manual/signal.texi
signal/Makefile
signal/signal.h
sysdeps/unix/sysv/linux/Makefile
sysdeps/unix/sysv/linux/Versions
sysdeps/unix/sysv/linux/aarch64/libc.abilist
sysdeps/unix/sysv/linux/alpha/libc.abilist
sysdeps/unix/sysv/linux/arm/libc.abilist
sysdeps/unix/sysv/linux/bits/signal_ext.h [new file with mode: 0644]
sysdeps/unix/sysv/linux/csky/libc.abilist
sysdeps/unix/sysv/linux/hppa/libc.abilist
sysdeps/unix/sysv/linux/i386/libc.abilist
sysdeps/unix/sysv/linux/ia64/libc.abilist
sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
sysdeps/unix/sysv/linux/microblaze/libc.abilist
sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
sysdeps/unix/sysv/linux/nios2/libc.abilist
sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist
sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist
sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
sysdeps/unix/sysv/linux/sh/libc.abilist
sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
sysdeps/unix/sysv/linux/syscalls.list
sysdeps/unix/sysv/linux/tst-tgkill.c [new file with mode: 0644]
sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist

index edfb9ad96bc7957d27f17ac16a8bca4ccaf276d4..cfdfcd57b704609c85360437dd228f61922714eb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,49 @@
+2019-05-14  Florian Weimer  <fweimer@redhat.com>
+
+       Linux: Add the tgkill function.
+       * bits/signal_ext.h: New file.
+       * manual/signal.texi (Signaling Another Process): Document tgkill.
+       * signal/Makefile (headers): Add bits/signal_ext.h.
+       * signal/signal.h: Include <bits/signal_ext.h>.
+       * sysdeps/unix/sysv/linux/Makefile (tests): Add tst-tgkill.
+       (tst-tgkill): Link with libpthread.
+       * sysdeps/unix/sysv/linux/Versions (GLIBC_2.30): Export tgkill.
+       * sysdeps/unix/sysv/linux/bits/signal_ext.h: New file.
+       * sysdeps/unix/sysv/linux/bits/tst-tgkill.c: Likewise.
+       * sysdeps/unix/sysv/linux/aarch64/libc.abilist (GLIBC_2.30): Add
+       tgkill.
+       * sysdeps/unix/sysv/linux/alpha/libc.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/arm/libc.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/csky/libc.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/hppa/libc.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/i386/libc.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/ia64/libc.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/microblaze/libc.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist:
+       Likewise.
+       * sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/nios2/libc.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist:
+       Likewise.
+       * sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist:
+       Likewise.
+       * sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist:
+       Likewise.
+       * sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist:
+       Likewise.
+       * sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/sh/libc.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/x86_64/64/libc.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist: Likewise.
+
 2019-05-14  Carlos O'Donell  <carlos@redhat.com>
 
        * manual/search.texi (Tree Search Function): Adjust twalk_r
diff --git a/NEWS b/NEWS
index 7f5ef432fa259267e55a6303093949e6d369cddd..0e4c57f27335d4d62580765aec74fce538459821 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -20,7 +20,7 @@ Major new features:
   twalk function, but it passes an additional caller-supplied argument
   to the callback function.
 
-* On Linux, the gettid function has been added.
+* On Linux, the gettid and tgkill functions have been added.
 
 * Minguo (Republic of China) calendar support has been added as an
   alternative calendar for the following locales: zh_TW, cmn_TW, hak_TW,
diff --git a/bits/signal_ext.h b/bits/signal_ext.h
new file mode 100644 (file)
index 0000000..d1bed56
--- /dev/null
@@ -0,0 +1,21 @@
+/* System-specific extensions of <signal.h>, generic version.
+   Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _SIGNAL_H
+# error "Never include <bits/signal_ext.h> directly; use <signal.h> instead."
+#endif
index 8b3a52e22a01fed04471663b46f5e5c8e0e9ba1d..33e66469758cca7b33ce32f9fc7d117362b40187 100644 (file)
@@ -2291,6 +2291,21 @@ The @var{pid} argument does not refer to an existing process or group.
 @end table
 @end deftypefun
 
+@deftypefun int tgkill (pid_t @var{pid}, pid_t @var{tid}, int @var{signum})
+@standards{Linux, signal.h}
+@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
+The @code{tgkill} function sends the signal @var{signum} to the thread
+or process with ID @var{tid}, like the @code{kill} function, but only
+if the process ID of the thread @var{tid} is equal to @var{pid}.  If
+the target thread belongs to another process, the function fails with
+@code{ESRCH}.
+
+The @code{tgkill} function can be used to avoid sending a signal to a
+thread in the wrong process if the caller ensures that the passed
+@var{pid} value is not reused by the kernel (for example, if it is the
+process ID of the current process, as returned by @code{getpid}).
+@end deftypefun
+
 @deftypefun int killpg (int @var{pgid}, int @var{signum})
 @standards{BSD, signal.h}
 @safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
index 06034fee8ef8d215cc36ad1ed541b09a0f65a467..4596112f0a75add9a7290dd9b159b7c061a40af3 100644 (file)
@@ -31,7 +31,7 @@ headers := signal.h sys/signal.h \
           bits/types/sigevent_t.h bits/types/siginfo_t.h \
           bits/types/sigset_t.h bits/types/sigval_t.h \
           bits/types/stack_t.h bits/types/struct_sigstack.h \
-          bits/types/__sigval_t.h
+          bits/types/__sigval_t.h bits/signal_ext.h
 
 routines       := signal raise killpg \
                   sigaction sigprocmask kill \
index ee591fcb2d7c8cfd0e42891e9d248adb12222759..4c0de7f6ce7563eed92a844fdb58bd65140583d5 100644 (file)
@@ -370,6 +370,9 @@ extern int __libc_current_sigrtmax (void) __THROW;
 #define SIGRTMIN        (__libc_current_sigrtmin ())
 #define SIGRTMAX        (__libc_current_sigrtmax ())
 
+/* System-specific extensions.  */
+#include <bits/signal_ext.h>
+
 __END_DECLS
 
 #endif /* not signal.h */
index 52ac6ad4844a6bb90976ffcecc1b60c30019c1c0..d2f0b60ea9b0f8e4fa68784aad42595d708ef7b8 100644 (file)
@@ -53,7 +53,8 @@ sysdep_headers += sys/mount.h sys/acct.h sys/sysctl.h \
 tests += tst-clone tst-clone2 tst-clone3 tst-fanotify tst-personality \
         tst-quota tst-sync_file_range tst-sysconf-iov_max tst-ttyname \
         test-errno-linux tst-memfd_create tst-mlock2 tst-pkey \
-        tst-rlimit-infinity tst-ofdlocks tst-gettid tst-gettid-kill
+        tst-rlimit-infinity tst-ofdlocks tst-gettid tst-gettid-kill \
+        tst-tgkill
 tests-internal += tst-ofdlocks-compat
 
 # Generate the list of SYS_* macros for the system calls (__NR_*
@@ -115,6 +116,7 @@ $(objpfx)tst-mman-consts.out: ../sysdeps/unix/sysv/linux/tst-mman-consts.py
 
 $(objpfx)tst-gettid: $(shared-thread-library)
 $(objpfx)tst-gettid-kill: $(shared-thread-library)
+$(objpfx)tst-tgkill: $(shared-thread-library)
 
 endif # $(subdir) == misc
 
index 5166ccff25159bd5d4324406383d329a09892cd0..c7137e2c2cc6659f5404962a2139376056855925 100644 (file)
@@ -175,7 +175,7 @@ libc {
     getcpu;
   }
   GLIBC_2.30 {
-    gettid;
+    gettid; tgkill;
   }
   GLIBC_PRIVATE {
     # functions used in other libraries
index b7283ad486a8edf774902f610c8645f0370d9aea..324909d5538cd43f6a2aa26583d7313d09a68621 100644 (file)
@@ -2142,4 +2142,5 @@ GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.30 gettid F
+GLIBC_2.30 tgkill F
 GLIBC_2.30 twalk_r F
index a817e683a49d211dd17656fbc8e746c268ed28aa..084e4755694e85791ee2cd7f65678763c4d49ec5 100644 (file)
@@ -2217,6 +2217,7 @@ GLIBC_2.30 __nldbl_vwarnx F
 GLIBC_2.30 __nldbl_warn F
 GLIBC_2.30 __nldbl_warnx F
 GLIBC_2.30 gettid F
+GLIBC_2.30 tgkill F
 GLIBC_2.30 twalk_r F
 GLIBC_2.4 _IO_fprintf F
 GLIBC_2.4 _IO_printf F
index 97b6cbf903e1a11fea9fa67978ae0d2ff5d9fad7..f58d16e210771aa892c7fb509758342e83666f29 100644 (file)
@@ -127,6 +127,7 @@ GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.30 gettid F
+GLIBC_2.30 tgkill F
 GLIBC_2.30 twalk_r F
 GLIBC_2.4 _Exit F
 GLIBC_2.4 _IO_2_1_stderr_ D 0xa0
diff --git a/sysdeps/unix/sysv/linux/bits/signal_ext.h b/sysdeps/unix/sysv/linux/bits/signal_ext.h
new file mode 100644 (file)
index 0000000..c07b869
--- /dev/null
@@ -0,0 +1,31 @@
+/* System-specific extensions of <signal.h>, Linux version.
+   Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _SIGNAL_H
+# error "Never include <bits/signal_ext.h> directly; use <signal.h> instead."
+#endif
+
+#ifdef __USE_GNU
+
+/* Send SIGNAL to the thread TID in the thread group (process)
+   identified by TGID.  This function behaves like kill, but also
+   fails with ESRCH if the specified TID does not belong to the
+   specified thread group.  */
+extern int tgkill (__pid_t __tgid, __pid_t __tid, int __signal);
+
+#endif /* __USE_GNU */
index 796e622a6d58a3764acfb95737c57578019386fb..38f6abaa3054a69b7e489d7cf9c8054875bce4ff 100644 (file)
@@ -2086,4 +2086,5 @@ GLIBC_2.29 xencrypt F
 GLIBC_2.29 xprt_register F
 GLIBC_2.29 xprt_unregister F
 GLIBC_2.30 gettid F
+GLIBC_2.30 tgkill F
 GLIBC_2.30 twalk_r F
index 4e7d71d112505bbe6cc949d8b2c3a97e46c42a8c..eb628f907bc9ac9b66aab771951b7c3f574b1ab6 100644 (file)
@@ -2038,6 +2038,7 @@ GLIBC_2.3.4 setsourcefilter F
 GLIBC_2.3.4 xdr_quad_t F
 GLIBC_2.3.4 xdr_u_quad_t F
 GLIBC_2.30 gettid F
+GLIBC_2.30 tgkill F
 GLIBC_2.30 twalk_r F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
index 11bd8c601a15a357fdf55bb180f59503eeb5a28f..6f240d9a5916ae5fa9d4ee4ae1acadb684c5f0bb 100644 (file)
@@ -2204,6 +2204,7 @@ GLIBC_2.3.4 vm86 F
 GLIBC_2.3.4 xdr_quad_t F
 GLIBC_2.3.4 xdr_u_quad_t F
 GLIBC_2.30 gettid F
+GLIBC_2.30 tgkill F
 GLIBC_2.30 twalk_r F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
index 589cce5b8db261ee4ec0d42d74a6a2e4e89e8e42..e589e3d7e2dea13022f4efc2317207fadde43f0c 100644 (file)
@@ -2070,6 +2070,7 @@ GLIBC_2.3.4 setsourcefilter F
 GLIBC_2.3.4 xdr_quad_t F
 GLIBC_2.3.4 xdr_u_quad_t F
 GLIBC_2.30 gettid F
+GLIBC_2.30 tgkill F
 GLIBC_2.30 twalk_r F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
index 4b3727a91d3a3d38313b73da7965b0bc6a2c710e..02c3ceee8d7633c869b885a2862538679b182990 100644 (file)
@@ -128,6 +128,7 @@ GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.30 gettid F
+GLIBC_2.30 tgkill F
 GLIBC_2.30 twalk_r F
 GLIBC_2.4 _Exit F
 GLIBC_2.4 _IO_2_1_stderr_ D 0x98
index 4be30c03390e69be7300a6ce5a16a60eb3a5b51d..f9a86bd95163cfe9c6b84ad2ba87001a087ebfe7 100644 (file)
@@ -2147,6 +2147,7 @@ GLIBC_2.3.4 setsourcefilter F
 GLIBC_2.3.4 xdr_quad_t F
 GLIBC_2.3.4 xdr_u_quad_t F
 GLIBC_2.30 gettid F
+GLIBC_2.30 tgkill F
 GLIBC_2.30 twalk_r F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
index e0010965a83f3ef9d57efbfc83d11ae7d3766574..d153fe0df53ff991bcea319b5dc557c717913213 100644 (file)
@@ -2134,4 +2134,5 @@ GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.30 gettid F
+GLIBC_2.30 tgkill F
 GLIBC_2.30 twalk_r F
index 2a62f67741922ba8589daad699a1f66ec4431296..fb3a9b18fcff113f0958ea6636d746621942d510 100644 (file)
@@ -2121,6 +2121,7 @@ GLIBC_2.3.4 setsourcefilter F
 GLIBC_2.3.4 xdr_quad_t F
 GLIBC_2.3.4 xdr_u_quad_t F
 GLIBC_2.30 gettid F
+GLIBC_2.30 tgkill F
 GLIBC_2.30 twalk_r F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
index 5a23f11fc9b8753a07203bb49fdeedf6b53d3dd5..22c80418f6fa82a9513630608f9f67bc11880b2c 100644 (file)
@@ -2119,6 +2119,7 @@ GLIBC_2.3.4 setsourcefilter F
 GLIBC_2.3.4 xdr_quad_t F
 GLIBC_2.3.4 xdr_u_quad_t F
 GLIBC_2.30 gettid F
+GLIBC_2.30 tgkill F
 GLIBC_2.30 twalk_r F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
index 32532a19da01fb147b73fd76e0385f902d32432b..a32aafb5527b34635c685c8eb59b3cbddbdb9761 100644 (file)
@@ -2127,6 +2127,7 @@ GLIBC_2.3.4 setsourcefilter F
 GLIBC_2.3.4 xdr_quad_t F
 GLIBC_2.3.4 xdr_u_quad_t F
 GLIBC_2.30 gettid F
+GLIBC_2.30 tgkill F
 GLIBC_2.30 twalk_r F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
index 882f5cb5bf65aab84cbf8da578585c5354d1a07f..45342a587e05bd3ab369acbd9584b7ab8e2cd572 100644 (file)
@@ -2121,6 +2121,7 @@ GLIBC_2.3.4 setsourcefilter F
 GLIBC_2.3.4 xdr_quad_t F
 GLIBC_2.3.4 xdr_u_quad_t F
 GLIBC_2.30 gettid F
+GLIBC_2.30 tgkill F
 GLIBC_2.30 twalk_r F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
index c99a299bab35cd38b55b632ddb01815167bb8cdf..fe1e96c170d365416c13ee0d09b3c98140c79476 100644 (file)
@@ -2175,4 +2175,5 @@ GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.30 gettid F
+GLIBC_2.30 tgkill F
 GLIBC_2.30 twalk_r F
index d5f436419746e6b004ca61a0c99849ea352b4f3a..cbcad5db989dc87ee305ee107de5fb37f811192a 100644 (file)
@@ -2177,6 +2177,7 @@ GLIBC_2.30 __nldbl_vwarnx F
 GLIBC_2.30 __nldbl_warn F
 GLIBC_2.30 __nldbl_warnx F
 GLIBC_2.30 gettid F
+GLIBC_2.30 tgkill F
 GLIBC_2.30 twalk_r F
 GLIBC_2.4 _IO_fprintf F
 GLIBC_2.4 _IO_printf F
index 581fd10290302fbee40867325b27f61c403a731c..060994eccf3631ab43444644dbcc6da32d5c26d0 100644 (file)
@@ -2210,6 +2210,7 @@ GLIBC_2.30 __nldbl_vwarnx F
 GLIBC_2.30 __nldbl_warn F
 GLIBC_2.30 __nldbl_warnx F
 GLIBC_2.30 gettid F
+GLIBC_2.30 tgkill F
 GLIBC_2.30 twalk_r F
 GLIBC_2.4 _IO_fprintf F
 GLIBC_2.4 _IO_printf F
index ce10e0436e322b9eccd182488c4fd65fefbaef90..af68ed8d013c970aba27091230caed1f6fc2992e 100644 (file)
@@ -2040,6 +2040,7 @@ GLIBC_2.30 __nldbl_vwarnx F
 GLIBC_2.30 __nldbl_warn F
 GLIBC_2.30 __nldbl_warnx F
 GLIBC_2.30 gettid F
+GLIBC_2.30 tgkill F
 GLIBC_2.30 twalk_r F
 GLIBC_2.4 _IO_fprintf F
 GLIBC_2.4 _IO_printf F
index 1cc729da7f3428aca3cc549876de5bca11492fe6..d317dc0586f8f06b51cad1fe163204d33bf7afc5 100644 (file)
@@ -2244,4 +2244,5 @@ GLIBC_2.30 __nldbl_vwarnx F
 GLIBC_2.30 __nldbl_warn F
 GLIBC_2.30 __nldbl_warnx F
 GLIBC_2.30 gettid F
+GLIBC_2.30 tgkill F
 GLIBC_2.30 twalk_r F
index 2bda5692f471bbcbec3289af2f0a0a9f8318a6eb..07d75c0481575bf48614d294478c6ecf14aab1d3 100644 (file)
@@ -2104,4 +2104,5 @@ GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.30 gettid F
+GLIBC_2.30 tgkill F
 GLIBC_2.30 twalk_r F
index dddc138a1e5986498a70aa007bc8ef6b787f3044..0fdcd6109c0200884c0e13d58469e0dc44155e04 100644 (file)
@@ -2172,6 +2172,7 @@ GLIBC_2.30 __nldbl_vwarnx F
 GLIBC_2.30 __nldbl_warn F
 GLIBC_2.30 __nldbl_warnx F
 GLIBC_2.30 gettid F
+GLIBC_2.30 tgkill F
 GLIBC_2.30 twalk_r F
 GLIBC_2.4 _IO_fprintf F
 GLIBC_2.4 _IO_printf F
index b2c75a48a810dd9bdc0b591fdc77ebefc2dcc505..ca871ad4bea6b74b66f4aab43f1ebe271de701c2 100644 (file)
@@ -2076,6 +2076,7 @@ GLIBC_2.30 __nldbl_vwarnx F
 GLIBC_2.30 __nldbl_warn F
 GLIBC_2.30 __nldbl_warnx F
 GLIBC_2.30 gettid F
+GLIBC_2.30 tgkill F
 GLIBC_2.30 twalk_r F
 GLIBC_2.4 _IO_fprintf F
 GLIBC_2.4 _IO_printf F
index 8b83449b169a3f6b64689f68f89630d6cb941a35..b559e5b3161b289ded7dc8eec615391f158e425f 100644 (file)
@@ -2042,6 +2042,7 @@ GLIBC_2.3.4 setsourcefilter F
 GLIBC_2.3.4 xdr_quad_t F
 GLIBC_2.3.4 xdr_u_quad_t F
 GLIBC_2.30 gettid F
+GLIBC_2.30 tgkill F
 GLIBC_2.30 twalk_r F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
index a237be9d9390066b30d48a42d4cba59ae389ce87..37daaa28e49df1c6d1f9b8398717b0008b9a708d 100644 (file)
@@ -2166,6 +2166,7 @@ GLIBC_2.30 __nldbl_vwarnx F
 GLIBC_2.30 __nldbl_warn F
 GLIBC_2.30 __nldbl_warnx F
 GLIBC_2.30 gettid F
+GLIBC_2.30 tgkill F
 GLIBC_2.30 twalk_r F
 GLIBC_2.4 _IO_fprintf F
 GLIBC_2.4 _IO_printf F
index b8506944348f627a4bfde9cf50ea4245ee256d1c..5f0a3adc3c21ed01eeaf8b65fbfe7df9eedfe1a2 100644 (file)
@@ -2093,6 +2093,7 @@ GLIBC_2.3.4 setsourcefilter F
 GLIBC_2.3.4 xdr_quad_t F
 GLIBC_2.3.4 xdr_u_quad_t F
 GLIBC_2.30 gettid F
+GLIBC_2.30 tgkill F
 GLIBC_2.30 twalk_r F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
index 25424e1399b8cf56c40539f423b3fa985d4908f7..e374f97b5f84aea6afa85b647d8232b7ce334106 100644 (file)
@@ -111,3 +111,4 @@ memfd_create    EXTRA       memfd_create    i:si    memfd_create
 pkey_alloc     EXTRA   pkey_alloc      i:ii    pkey_alloc
 pkey_free      EXTRA   pkey_free       i:i     pkey_free
 gettid          EXTRA   gettid          Ei:     __gettid       gettid
+tgkill          EXTRA   tgkill          i:iii   __tgkill       tgkill
diff --git a/sysdeps/unix/sysv/linux/tst-tgkill.c b/sysdeps/unix/sysv/linux/tst-tgkill.c
new file mode 100644 (file)
index 0000000..818e2f5
--- /dev/null
@@ -0,0 +1,132 @@
+/* Smoke test for the tgkill system call.
+   Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <signal.h>
+#include <support/check.h>
+#include <support/namespace.h>
+#include <support/xthread.h>
+#include <unistd.h>
+
+/* Number of times sigusr1_handler has been invoked.  */
+static volatile sig_atomic_t signals_delivered;
+
+/* Expected TID of the thread receiving the signal.  */
+static pid_t expected_signal_tid;
+
+static void
+sigusr1_handler (int signo)
+{
+  TEST_COMPARE (expected_signal_tid, gettid ());
+  ++signals_delivered;
+}
+
+struct pid_and_tid
+{
+  pid_t pid;
+  pid_t tid;
+};
+
+/* Send signals from the subprocess which are not expected to be
+   delivered.  There is no handler for SIGUSR2, so delivery will
+   result in a test failure.  CLOSURE must point to a valid PID/TID
+   combination that is still running.  */
+static void
+subprocess_no_tid_match (void *closure)
+{
+  struct pid_and_tid *ids = closure;
+  TEST_COMPARE (tgkill (ids->pid, gettid (), SIGUSR2), -1);
+  TEST_COMPARE (errno, ESRCH);
+
+  TEST_COMPARE (tgkill (getpid (), ids->tid, SIGUSR2), -1);
+  TEST_COMPARE (errno, ESRCH);
+
+  TEST_COMPARE (tgkill (getppid (), gettid (), SIGUSR2), -1);
+  TEST_COMPARE (errno, ESRCH);
+}
+
+/* Called from threadfunc below.  */
+static void
+subprocess (void *closure)
+{
+  int original_tid = expected_signal_tid;
+
+  /* Do not expect that the folloing signals are delivered to the
+     subprocess.  The parent process retains the original
+     expected_signal_tid value.  */
+  expected_signal_tid = 0;
+  TEST_COMPARE (tgkill (getpid (), original_tid, SIGUSR1), -1);
+  TEST_COMPARE (errno, ESRCH);
+  TEST_COMPARE (tgkill (getppid (), gettid (), SIGUSR1), -1);
+  TEST_COMPARE (errno, ESRCH);
+  TEST_COMPARE (expected_signal_tid, 0);
+
+  /* This call has the correct PID/TID combination and is therefore
+     expected to suceed.  */
+  TEST_COMPARE (tgkill (getppid (), original_tid, SIGUSR1), 0);
+}
+
+static void *
+threadfunc (void *closure)
+{
+  TEST_VERIFY (gettid () != getpid ());
+  expected_signal_tid = gettid ();
+  TEST_COMPARE (tgkill (getpid (), gettid (), SIGUSR1), 0);
+  TEST_COMPARE (signals_delivered, 1);
+  signals_delivered = 0;
+
+  support_isolate_in_subprocess (subprocess, NULL);
+
+  /* Check that exactly one signal arrived from the subprocess.  */
+  TEST_COMPARE (signals_delivered, 1);
+
+  support_isolate_in_subprocess (subprocess_no_tid_match,
+                                 &(struct pid_and_tid)
+                                 {
+                                   .pid = getpid (),
+                                   .tid = gettid (),
+                                 });
+
+  support_isolate_in_subprocess (subprocess_no_tid_match,
+                                 &(struct pid_and_tid)
+                                 {
+                                   .pid = getpid (),
+                                   .tid = getpid (),
+                                 });
+
+  return NULL;
+}
+
+static int
+do_test (void)
+{
+  TEST_VERIFY_EXIT (signal (SIGUSR1, sigusr1_handler) != SIG_ERR);
+
+  expected_signal_tid = gettid ();
+  TEST_COMPARE (gettid (), getpid ());
+  TEST_COMPARE (tgkill (getpid (), gettid (), SIGUSR1), 0);
+  TEST_COMPARE (signals_delivered, 1);
+  signals_delivered = 0;
+
+  xpthread_join (xpthread_create (NULL, threadfunc, NULL));
+
+  TEST_VERIFY (signal (SIGUSR1, SIG_DFL) == sigusr1_handler);
+  return 0;
+}
+
+#include <support/test-driver.c>
index c6f22f0c7b5a5fa31f8a06ee1312e00f708ca777..c82b3ba7b8c2d52bdb63abd84deee05f3a11fefc 100644 (file)
@@ -2051,6 +2051,7 @@ GLIBC_2.3.4 setsourcefilter F
 GLIBC_2.3.4 xdr_quad_t F
 GLIBC_2.3.4 xdr_u_quad_t F
 GLIBC_2.30 gettid F
+GLIBC_2.30 tgkill F
 GLIBC_2.30 twalk_r F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
index 1184385bcec82e10375101ebdc60d2d377eef1e8..ed89c34c5531f56d48abfc096b97f879e92ac63e 100644 (file)
@@ -2150,4 +2150,5 @@ GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.30 gettid F
+GLIBC_2.30 tgkill F
 GLIBC_2.30 twalk_r F