diffutils-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 5/5] maint: port better to non-POSIX


From: Paul Eggert
Subject: [PATCH 5/5] maint: port better to non-POSIX
Date: Mon, 30 Aug 2021 10:33:19 -0700

Problem privately reported by Gisle Vanem for MS-Windows.
* src/util.c (sig, install_signal_handlers):
Don’t assume SIGTSTP, SIGALRM, SIGQUIT.
(is_tstp_index): New function, for use in SIGTSTP avoidance.
---
 src/util.c | 28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)

diff --git a/src/util.c b/src/util.c
index 7e77522..a3d2ab4 100644
--- a/src/util.c
+++ b/src/util.c
@@ -299,11 +299,20 @@ process_signals (void)
    and which of them are actually caught.  */
 static int const sig[] =
   {
-    /* This one is handled specially.  */
+#ifdef SIGTSTP
+    /* This one is handled specially; see is_tstp_index.  */
     SIGTSTP,
+#endif
 
     /* The usual suspects.  */
-    SIGALRM, SIGHUP, SIGINT, SIGPIPE, SIGQUIT, SIGTERM,
+#ifdef SIGALRM
+    SIGALRM,
+#endif
+    SIGHUP, SIGINT, SIGPIPE,
+#ifdef SIGQUIT
+    SIGQUIT,
+#endif
+    SIGTERM,
 #ifdef SIGPOLL
     SIGPOLL,
 #endif
@@ -322,6 +331,17 @@ static int const sig[] =
   };
 enum { nsigs = sizeof (sig) / sizeof *(sig) };
 
+/* True if sig[j] == SIGTSTP.  */
+static bool
+is_tstp_index (int j)
+{
+#ifdef SIGTSTP
+  return j == 0;
+#else
+  return false;
+#endif
+}
+
 static void
 install_signal_handlers (void)
 {
@@ -343,7 +363,7 @@ install_signal_handlers (void)
   for (int j = 0; j < nsigs; j++)
     if (xsigismember (&caught_signals, sig[j]))
       {
-       act.sa_handler = sig[j] == SIGTSTP ? stophandler : sighandler;
+       act.sa_handler = is_tstp_index (j) ? stophandler : sighandler;
        if (sigaction (sig[j], &act, NULL) != 0)
          pfatal_with_name ("sigaction");
        some_signals_caught = true;
@@ -355,7 +375,7 @@ install_signal_handlers (void)
       if (h != SIG_IGN && h != SIG_ERR)
        {
          xsigaddset (&caught_signals, sig[j]);
-         xsignal (sig[j], sig[j] == SIGTSTP ? stophandler : sighandler);
+         xsignal (sig[j], is_tstp_index (j) ? stophandler : sighandler);
          some_signals_caught = true;
          if (siginterrupt (sig[j], 0) != 0)
            pfatal_with_name ("siginterrupt");
-- 
2.31.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]