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