As a style matter we should prefer "kill -INT ..." too, I suppose. I installed the attached, which also fixes a couple of very minor pid_t glitches.
From ac6115cfb3a71be3a472835d420fbef24cd4889a Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Sat, 26 Nov 2022 10:43:24 -0800
Subject: [PATCH] Prefer "kill -INT" to killing with a number
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* m4/pthread_sigmask.m4 (gl_FUNC_PTHREAD_SIGMASK):
* tests/test-login_tty.c (main):
* tests/test-pthread_sigmask1.c (main):
* tests/test-sigprocmask.c (main):
Prefer "kill -INT" to "kill -N" where N is SIGINT’s value.
Don’t assume pid_t fits in int.
---
 ChangeLog                     | 10 ++++++++++
 m4/pthread_sigmask.m4         |  7 +++++--
 tests/test-login_tty.c        |  2 +-
 tests/test-pthread_sigmask1.c | 11 +++++++++--
 tests/test-sigprocmask.c      |  5 +++--
 5 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c0c1026711..36825874d2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2022-11-26  Paul Eggert  <[email protected]>
+
+	Prefer "kill -INT" to killing with a number
+	* m4/pthread_sigmask.m4 (gl_FUNC_PTHREAD_SIGMASK):
+	* tests/test-login_tty.c (main):
+	* tests/test-pthread_sigmask1.c (main):
+	* tests/test-sigprocmask.c (main):
+	Prefer "kill -INT" to "kill -N" where N is SIGINT’s value.
+	Don’t assume pid_t fits in int.
+
 2022-11-25  Bruno Haible  <[email protected]>
 
 	In 'trap' commands, prefer symbolic to numeric signal names.
diff --git a/m4/pthread_sigmask.m4 b/m4/pthread_sigmask.m4
index 0aa8c53f9e..8282a371e4 100644
--- a/m4/pthread_sigmask.m4
+++ b/m4/pthread_sigmask.m4
@@ -215,6 +215,7 @@ int main ()
            LIBS="$LIBS $LIBMULTITHREAD"])
         AC_RUN_IFELSE(
           [AC_LANG_SOURCE([[
+#include <limits.h>
 #include <pthread.h>
 #include <signal.h>
 #include <stdio.h>
@@ -230,14 +231,16 @@ sigint_handler (int sig)
 int main ()
 {
   sigset_t set;
-  int pid = getpid ();
+  pid_t pid = getpid ();
   char command[80];
+  if (LONG_MAX < pid)
+    return 6;
   signal (SIGINT, sigint_handler);
   sigemptyset (&set);
   sigaddset (&set, SIGINT);
   if (!(pthread_sigmask (SIG_BLOCK, &set, NULL) == 0))
     return 1;
-  sprintf (command, "sh -c 'sleep 1; kill -%d %d' &", SIGINT, pid);
+  sprintf (command, "sh -c 'sleep 1; kill -INT %ld' &", (long) pid);
   if (!(system (command) == 0))
     return 2;
   sleep (2);
diff --git a/tests/test-login_tty.c b/tests/test-login_tty.c
index 3ea6968e41..c8f971de4e 100644
--- a/tests/test-login_tty.c
+++ b/tests/test-login_tty.c
@@ -64,7 +64,7 @@ main ()
         abort ();
     for (fd = 0; fd < 3; fd++)
       {
-        int sid = tcgetsid (fd);
+        pid_t sid = tcgetsid (fd);
         if (!(sid == -1 ? errno == ENOSYS : sid == getpid ()))
           abort ();
       }
diff --git a/tests/test-pthread_sigmask1.c b/tests/test-pthread_sigmask1.c
index a7816b5e55..0f87baed7c 100644
--- a/tests/test-pthread_sigmask1.c
+++ b/tests/test-pthread_sigmask1.c
@@ -24,6 +24,7 @@
 SIGNATURE_CHECK (pthread_sigmask, int, (int, const sigset_t *, sigset_t *));
 
 #include <errno.h>
+#include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -44,9 +45,15 @@ int
 main (int argc, char *argv[])
 {
   sigset_t set;
-  int pid = getpid ();
+  pid_t pid = getpid ();
   char command[80];
 
+  if (LONG_MAX < pid)
+    {
+      fputs ("Skipping test: pid too large\n", stderr);
+      return 77;
+    }
+
   signal (SIGINT, sigint_handler);
 
   sigemptyset (&set);
@@ -59,7 +66,7 @@ main (int argc, char *argv[])
   ASSERT (pthread_sigmask (SIG_BLOCK, &set, NULL) == 0);
 
   /* Request a SIGINT signal from outside.  */
-  sprintf (command, "sh -c 'sleep 1; kill -%d %d' &", SIGINT, pid);
+  sprintf (command, "sh -c 'sleep 1; kill -INT %ld' &", (long) pid);
   ASSERT (system (command) == 0);
 
   /* Wait.  */
diff --git a/tests/test-sigprocmask.c b/tests/test-sigprocmask.c
index 4bab4c1cce..574bc82e1a 100644
--- a/tests/test-sigprocmask.c
+++ b/tests/test-sigprocmask.c
@@ -24,6 +24,7 @@
 SIGNATURE_CHECK (sigprocmask, int, (int, const sigset_t *, sigset_t *));
 
 #include <errno.h>
+#include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -47,7 +48,7 @@ main (int argc, char *argv[])
   pid_t pid = getpid ();
   char command[80];
 
-  if (sizeof (int) < sizeof pid && 0x7fffffff < pid)
+  if (LONG_MAX < pid)
     {
       fputs ("Skipping test: pid too large\n", stderr);
       return 77;
@@ -66,7 +67,7 @@ main (int argc, char *argv[])
   ASSERT (sigprocmask (SIG_BLOCK, &set, NULL) == 0);
 
   /* Request a SIGINT signal from outside.  */
-  sprintf (command, "sh -c 'sleep 1; kill -%d %d' &", SIGINT, (int) pid);
+  sprintf (command, "sh -c 'sleep 1; kill -INT %ld' &", (long) pid);
   ASSERT (system (command) == 0);
 
   /* Wait.  */
-- 
2.37.2

Reply via email to