bug-coreutils
[Top][All Lists]
Advanced

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

[PATCH] Replacement for the sigs_to_ignore hack in timeout.c


From: Giuseppe Scrivano
Subject: [PATCH] Replacement for the sigs_to_ignore hack in timeout.c
Date: Mon, 06 Oct 2008 23:33:29 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

Hello,

what do you think about the following way to remove the sigs_to_ignore
hack in the timeout.c file?
It ignores temporarily the signal inside the `send_sig' function instead
of using the `sigs_to_ignore' array.

Regards,
Giuseppe Scrivano


diff --git a/src/timeout.c b/src/timeout.c
index 8b506f0..93b23f6 100644
--- a/src/timeout.c
+++ b/src/timeout.c
@@ -82,7 +82,8 @@
 static int timed_out;
 static int term_signal = SIGTERM;  /* same default as kill command.  */
 static int monitored_pid;
-static int sigs_to_ignore[NSIG];   /* so monitor can ignore sigs it resends.  
*/
+
+static void cleanup (int sig);
 
 static struct option const long_options[] =
 {
@@ -90,13 +91,25 @@ static struct option const long_options[] =
   {NULL, 0, NULL, 0}
 };
 
-/* send sig to group but not ourselves.
- * FIXME: Is there a better way to achieve this?  */
+/* send sig to group but not ourselves.  */
 static int
 send_sig (int where, int sig)
 {
-  sigs_to_ignore[sig] = 1;
-  return kill (where, sig);
+  int ret;
+  struct sigaction sa;
+  void (*handler)(int);
+
+  sigaction (sig, NULL, &sa);
+  handler = sa.sa_handler;
+  sa.sa_handler = SIG_IGN;
+  sigaction (sig, &sa, NULL);
+
+  ret = kill (where, sig);
+
+  sa.sa_handler = handler;
+  sigaction (sig, &sa, NULL);
+
+  return ret;
 }
 
 static void
@@ -109,11 +122,6 @@ cleanup (int sig)
     }
   if (monitored_pid)
     {
-      if (sigs_to_ignore[sig])
-        {
-          sigs_to_ignore[sig] = 0;
-          return;
-        }
       send_sig (0, sig);
       if (sig != SIGKILL && sig != SIGCONT)
         send_sig (0, SIGCONT);




reply via email to

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