On 8/29/21 4:13 AM, Gisle Vanem wrote:

With some added trace-code I found this was for
SIGHUP (=1) which is not supported. So I just dropped
SIGHUP from the list.

Thanks for reporting that. I installed the attached, which I hope fixes the problem in a more-portable way. Please give it a try.

In hindsight perhaps 'diff' should never have added signal handling, as it's a bug magnet. If your display's colors get messed up due to ^C the shell should fix the colors, not 'diff'.
>From 078321ebeb4d9e83e900278154dbf47ec2758295 Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Sun, 29 Aug 2021 11:14:14 -0700
Subject: [PATCH] diff: port better to MS-Windows

Problem reported by Gisle Vanem (Bug#36488#30).
* src/util.c (xsigaction) [SA_NOCLDSTOP]: Remove; no longer needed.
(install_signal_handlers): If the first call to sigaction or
signal fails, do not exit; just skip the signal and continue,
in case the runtime does not support the signal even though the
corresponding SIG* macro is defined.
---
 src/util.c | 36 +++++++++++++++---------------------
 1 file changed, 15 insertions(+), 21 deletions(-)

diff --git a/src/util.c b/src/util.c
index 8e676c8..f8b911a 100644
--- a/src/util.c
+++ b/src/util.c
@@ -159,16 +159,7 @@ print_message_queue (void)
     }
 }
 
-
-#if SA_NOCLDSTOP
-static void
-xsigaction (int sig, struct sigaction const *restrict act,
-	    struct sigaction *restrict oact)
-{
-  if (sigaction (sig, act, oact) != 0)
-    pfatal_with_name ("sigaction");
-}
-#endif
+/* Signal handling, needed for restoring default colors.  */
 
 static void
 xsigaddset (sigset_t *set, int sig)
@@ -321,8 +312,7 @@ install_signal_handlers (void)
   for (int j = 0; j < nsigs; j++)
     {
       struct sigaction actj;
-      xsigaction (sig[j], NULL, &actj);
-      if (actj.sa_handler != SIG_IGN)
+      if (sigaction (sig[j], NULL, &actj) == 0 && actj.sa_handler != SIG_IGN)
 	xsigaddset (&caught_signals, sig[j]);
     }
 
@@ -334,19 +324,23 @@ install_signal_handlers (void)
     if (xsigismember (&caught_signals, sig[j]))
       {
 	act.sa_handler = sig[j] == SIGTSTP ? stophandler : sighandler;
-	xsigaction (sig[j], &act, NULL);
+	if (sigaction (sig[j], &act, NULL) != 0)
+	  pfatal_with_name ("sigaction");
 	some_signals_caught = true;
       }
 #else
   for (int j = 0; j < nsigs; j++)
-    if (xsignal (sig[j], SIG_IGN) != SIG_IGN)
-      {
-	xsigaddset (&caught_signals, sig[j]);
-	xsignal (sig[j], sig[j] == SIGTSTP ? stophandler : sighandler);
-	some_signals_caught = true;
-	if (siginterrupt (sig[j], 0) != 0)
-	  pfatal_with_name ("siginterrupt");
-      }
+    {
+      signal_handler h = signal (sig[j], SIG_IGN);
+      if (h != SIG_IGN && h != SIG_ERR)
+	{
+	  xsigaddset (&caught_signals, sig[j]);
+	  xsignal (sig[j], sig[j] == SIGTSTP ? stophandler : sighandler);
+	  some_signals_caught = true;
+	  if (siginterrupt (sig[j], 0) != 0)
+	    pfatal_with_name ("siginterrupt");
+	}
+    }
 #endif
 }
 
-- 
2.30.2

Reply via email to