sigprocmask-tests: skip test if pid is unexpectedly large
authorEric Blake <eblake@redhat.com>
Mon, 31 Dec 2012 23:51:29 +0000 (16:51 -0700)
committerEric Blake <eblake@redhat.com>
Mon, 31 Dec 2012 23:59:00 +0000 (16:59 -0700)
At least mingw64 has 8-byte pid_t but only 4-byte long.  Silent
truncation to int in printing a pid value with %d risks killing the
wrong process.  But rather than try to futz with determining
the maximum pid_t, it is simpler to just cap things by realizing
that this test is already skipped on mingw64, so adding a sanity
check bounds comparison (and hard-coding the result rather than
dragging in headers for INT_MAX) is just as effective at avoiding
theoretical problems with no real loss in test coverage.

* tests/test-sigprocmask.c (main): Add range check.

Signed-off-by: Eric Blake <eblake@redhat.com>
ChangeLog
tests/test-sigprocmask.c

index 41fc6ac..df7999e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2012-12-31  Eric Blake  <eblake@redhat.com>
 
+       sigprocmask-tests: skip test if pid is unexpectedly large
+       * tests/test-sigprocmask.c (main): Add range check.
+
        git-version-gen: avoid test -z portability glitch
        * build-aux/git-version-gen: Prefer portable test spelling, since
        git-version-gen is run on more than just developer machines.
index 55d11b0..7c1af4f 100644 (file)
@@ -44,9 +44,15 @@ int
 main (int argc, char *argv[])
 {
   sigset_t set;
-  int pid = getpid ();
+  pid_t pid = getpid ();
   char command[80];
 
+  if (sizeof (int) < sizeof pid && 0x7fffffff < pid)
+    {
+      fputs ("Skipping test: pid too large\n", stderr);
+      return 77;
+    }
+
   signal (SIGINT, sigint_handler);
 
   sigemptyset (&set);
@@ -60,7 +66,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, pid);
+  sprintf (command, "sh -c 'sleep 1; kill -%d %d' &", SIGINT, (int) pid);
   ASSERT (system (command) == 0);
 
   /* Wait.  */