* job.c (set_child_handler_action_flags): [SV 41341]
authorPaul Smith <psmith@gnu.org>
Sun, 2 Feb 2014 04:08:59 +0000 (23:08 -0500)
committerPaul Smith <psmith@gnu.org>
Sun, 2 Feb 2014 04:12:04 +0000 (23:12 -0500)
Ensure signal handler is in place before alarm(1).

job.c

diff --git a/job.c b/job.c
index 0b34e17cbedfc0d2eaeee69f23ab3190e053871d..e4a40acae3d57c47f5e09e6f19c045256dc2fb6f 100644 (file)
--- a/job.c
+++ b/job.c
@@ -1116,10 +1116,20 @@ set_child_handler_action_flags (int set_handler, int set_alarm)
       /* If we're about to enter the read(), set an alarm to wake up in a
          second so we can check if the load has dropped and we can start more
          work.  On the way out, turn off the alarm and set SIG_DFL.  */
-      alarm (set_handler ? 1 : 0);
-      sa.sa_handler = set_handler ? job_noop : SIG_DFL;
-      sa.sa_flags = 0;
-      sigaction (SIGALRM, &sa, NULL);
+      if (set_handler)
+        {
+          sa.sa_handler = job_noop;
+          sa.sa_flags = 0;
+          sigaction (SIGALRM, &sa, NULL);
+          alarm (1);
+        }
+      else
+        {
+          alarm (0);
+          sa.sa_handler = SIG_DFL;
+          sa.sa_flags = 0;
+          sigaction (SIGALRM, &sa, NULL);
+        }
     }
 #endif
 }