Roman Rakus e8e8bf
diff -pruN bash-4.1/jobs.c bash-4.1.patched/jobs.c
Roman Rakus e8e8bf
--- bash-4.1/jobs.c	2009-11-30 03:42:05.000000000 +0530
Roman Rakus e8e8bf
+++ bash-4.1.patched/jobs.c	2012-03-06 16:44:15.706595703 +0530
Roman Rakus e8e8bf
@@ -3037,6 +3037,7 @@ waitchld (wpid, block)
Roman Rakus e8e8bf
   PROCESS *child;
Roman Rakus e8e8bf
   pid_t pid;
Roman Rakus e8e8bf
   int call_set_current, last_stopped_job, job, children_exited, waitpid_flags;
Roman Rakus e8e8bf
+  int called_from_sighand = sigchld;
Roman Rakus e8e8bf
   static int wcontinued = WCONTINUED;	/* run-time fix for glibc problem */
Roman Rakus e8e8bf
 
Roman Rakus e8e8bf
   call_set_current = children_exited = 0;
Roman Rakus e8e8bf
@@ -3161,7 +3162,17 @@ waitchld (wpid, block)
Roman Rakus e8e8bf
 	  longjmp (wait_intr_buf, 1);
Roman Rakus e8e8bf
 	}
Roman Rakus e8e8bf
 
Roman Rakus e8e8bf
-      run_sigchld_trap (children_exited);
Roman Rakus e8e8bf
+      /* Queue up the trap handler if we're called directly from within the
Roman Rakus e8e8bf
+         signal handler. */
Roman Rakus e8e8bf
+      if (called_from_sighand)
Roman Rakus e8e8bf
+	{
Roman Rakus e8e8bf
+	  int i = children_exited;
Roman Rakus e8e8bf
+	  interrupt_immediately = 0;
Roman Rakus e8e8bf
+	  while (i--)
Roman Rakus e8e8bf
+	    trap_handler (SIGCHLD);
Roman Rakus e8e8bf
+	}
Roman Rakus e8e8bf
+      else
Roman Rakus e8e8bf
+	run_sigchld_trap (children_exited);
Roman Rakus e8e8bf
     }
Roman Rakus e8e8bf
 
Roman Rakus e8e8bf
   /* We have successfully recorded the useful information about this process