]> git.ipfire.org Git - thirdparty/bash.git/blobdiff - nojobs.c
commit bash-20140214 snapshot
[thirdparty/bash.git] / nojobs.c
index 7bb60b3b5b39b559457e95d7e89e2a7060f8e2bd..0c9bd751bb80752dfff194812fb1f432fab61bc4 100644 (file)
--- a/nojobs.c
+++ b/nojobs.c
@@ -83,8 +83,8 @@ extern sigset_t top_level_mask;
 extern procenv_t wait_intr_buf;
 extern int wait_signal_received;
 
-pid_t last_made_pid = NO_PID;
-pid_t last_asynchronous_pid = NO_PID;
+volatile pid_t last_made_pid = NO_PID;
+volatile pid_t last_asynchronous_pid = NO_PID;
 
 /* Call this when you start making children. */
 int already_making_children = 0;
@@ -442,10 +442,12 @@ reap_zombie_children ()
   WAIT status;
 
   CHECK_TERMSIG;
+  CHECK_WAIT_INTR;
   while ((pid = waitpid (-1, (int *)&status, WNOHANG)) > 0)
     set_pid_status (pid, status);
 #  endif /* WNOHANG */
   CHECK_TERMSIG;
+  CHECK_WAIT_INTR;
 }
 #endif /* WAITPID */
 
@@ -499,11 +501,17 @@ make_child (command, async_p)
     sync_buffered_stream (default_buffered_input);
 #endif /* BUFFERED_INPUT */
 
+  /* XXX - block SIGTERM here and unblock in child after fork resets the
+     set of pending signals? */
+  RESET_SIGTERM;
+
   /* Create the child, handle severe errors.  Retry on EAGAIN. */
   forksleep = 1;
   while ((pid = fork ()) < 0 && errno == EAGAIN && forksleep < FORKSLEEP_MAX)
     {
       sys_error ("fork: retry");
+      RESET_SIGTERM;
+
 #if defined (HAVE_WAITPID)
       /* Posix systems with a non-blocking waitpid () system call available
         get another chance after zombies are reaped. */
@@ -517,6 +525,9 @@ make_child (command, async_p)
       forksleep <<= 1;
     }
 
+  if (pid != 0)
+    RESET_SIGTERM;
+
   if (pid < 0)
     {
       sys_error ("fork");
@@ -606,6 +617,7 @@ wait_for_single_pid (pid)
   while ((got_pid = WAITPID (pid, &status, 0)) != pid)
     {
       CHECK_TERMSIG;
+      CHECK_WAIT_INTR;
       if (got_pid < 0)
        {
          if (errno != EINTR && errno != ECHILD)
@@ -692,12 +704,12 @@ wait_sigint_handler (sig)
       signal_is_trapped (SIGINT) &&
       ((sigint_handler = trap_to_sighandler (SIGINT)) == trap_handler))
     {
-      last_command_exit_value = EXECUTION_FAILURE;
+      last_command_exit_value = 128+SIGINT;
       restore_sigint_handler ();
       interrupt_immediately = 0;
       trap_handler (SIGINT);   /* set pending_traps[SIGINT] */
       wait_signal_received = SIGINT;
-      longjmp (wait_intr_buf, 1);
+      SIGRETURN (0);
     }
 
   if (interrupt_immediately)
@@ -760,6 +772,7 @@ wait_for (pid)
   while ((got_pid = WAITPID (-1, &status, 0)) != pid) /* XXX was pid now -1 */
     {
       CHECK_TERMSIG;
+      CHECK_WAIT_INTR;
       if (got_pid < 0 && errno == ECHILD)
        {
 #if !defined (_POSIX_VERSION)
@@ -783,6 +796,9 @@ wait_for (pid)
     reap_zombie_children ();
 #endif /* HAVE_WAITPID */
 
+  CHECK_TERMSIG;
+  CHECK_WAIT_INTR;
+
   if (interactive_shell == 0)
     {
       SigHandler *temp_handler;