]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(restore_default_color_handler, sigtstp_handler): Remove functions.
authorJim Meyering <jim@meyering.net>
Sun, 10 Nov 2002 11:11:34 +0000 (11:11 +0000)
committerJim Meyering <jim@meyering.net>
Sun, 10 Nov 2002 11:11:34 +0000 (11:11 +0000)
(sighandler): New function, based on the one in sort.c.
(main): Use sigaction, if possible; otherwise signal.
Handle these signals:
SIGHUP, SIGINT, SIGPIPE, SIGQUIT, SIGTERM, SIGTSTP.
Don't register our handler if the signal is already being ignored.

src/ls.c

index f4763f514a72bf1c06244bdb3635ea1f73133394..4e7bb2abd9aaf6b8f1212a2d296a783a0008774b 100644 (file)
--- a/src/ls.c
+++ b/src/ls.c
@@ -1005,18 +1005,28 @@ restore_default_color (void)
 }
 
 static void
-restore_default_color_handler (int signum)
+sighandler (int sig)
 {
-  restore_default_color ();
-  _exit (128 + signum);
-}
+#ifndef SA_NOCLDSTOP
+  signal (sig, SIG_IGN);
+#endif
 
-static void
-sigtstp_handler (int signum)
-{
-  signal (SIGTSTP, sigtstp_handler);
   restore_default_color ();
-  raise (SIGSTOP);
+
+#ifdef SA_NOCLDSTOP
+  {
+    struct sigaction sigact;
+
+    sigact.sa_handler = SIG_DFL;
+    sigemptyset (&sigact.sa_mask);
+    sigact.sa_flags = 0;
+    sigaction (sig, &sigact, NULL);
+  }
+#else
+  signal (sig, SIG_DFL);
+#endif
+
+  raise (sig);
 }
 
 int
@@ -1057,10 +1067,36 @@ main (int argc, char **argv)
              && format == long_format))
        check_symlink_color = 1;
 
-      signal (SIGINT, restore_default_color_handler);
-      signal (SIGTERM, restore_default_color_handler);
-      signal (SIGQUIT, restore_default_color_handler);
-      signal (SIGTSTP, sigtstp_handler);
+      {
+       unsigned j;
+       static int const sigs[] = { SIGHUP, SIGINT, SIGPIPE,
+                                   SIGQUIT, SIGTERM, SIGTSTP };
+       unsigned nsigs = sizeof sigs / sizeof *sigs;
+#ifdef SA_NOCLDSTOP
+       struct sigaction oldact, newact;
+       sigset_t caught_signals;
+
+       sigemptyset (&caught_signals);
+       for (j = 0; j < nsigs; j++)
+         sigaddset (&caught_signals, sigs[j]);
+       newact.sa_handler = sighandler;
+       newact.sa_mask = caught_signals;
+       newact.sa_flags = 0;
+#endif
+
+       for (j = 0; j < nsigs; j++)
+         {
+           int sig = sigs[j];
+#ifdef SA_NOCLDSTOP
+           sigaction (sig, NULL, &oldact);
+           if (oldact.sa_handler != SIG_IGN)
+             sigaction (sig, &newact, NULL);
+#else
+           if (signal (sig, SIG_IGN) != SIG_IGN)
+             signal (sig, sighandler);
+#endif
+         }
+      }
     }
 
   if (dereference == DEREF_UNDEFINED)