aboutsummaryrefslogtreecommitdiffstats
path: root/nojobs.c
diff options
context:
space:
mode:
authorJari Aalto <jari.aalto@cante.net>2002-07-17 14:10:11 +0000
committerJari Aalto <jari.aalto@cante.net>2009-09-12 16:46:55 +0000
commit7117c2d221b2aed4ede8600f6a36b7c1454b4f55 (patch)
treeb792f26ecca68813c51ed5ba2e381790758ef31b /nojobs.c
parentf73dda092b33638d2d5e9c35375f687a607b5403 (diff)
downloadandroid_external_bash-7117c2d221b2aed4ede8600f6a36b7c1454b4f55.tar.gz
android_external_bash-7117c2d221b2aed4ede8600f6a36b7c1454b4f55.tar.bz2
android_external_bash-7117c2d221b2aed4ede8600f6a36b7c1454b4f55.zip
Imported from ../bash-2.05b.tar.gz.
Diffstat (limited to 'nojobs.c')
-rw-r--r--nojobs.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/nojobs.c b/nojobs.c
index a4b5539..7763283 100644
--- a/nojobs.c
+++ b/nojobs.c
@@ -57,9 +57,7 @@
#include "builtins/builtext.h" /* for wait_builtin */
-#if !defined (CHILD_MAX)
-# define CHILD_MAX 32
-#endif
+#define DEFAULT_CHILD_MAX 32
#if defined (_POSIX_VERSION) || !defined (HAVE_KILLPG)
# define killpg(pg, sig) kill(-(pg),(sig))
@@ -95,6 +93,7 @@ extern sh_builtin_func_t *this_shell_builtin;
extern sigset_t top_level_mask;
#endif
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;
@@ -130,6 +129,8 @@ static struct proc_status *pid_list = (struct proc_status *)NULL;
static int pid_list_size;
static int wait_sigint_received;
+static long child_max = -1L;
+
static void alloc_pid_list __P((void));
static int find_proc_slot __P((void));
static int find_index_by_pid __P((pid_t));
@@ -143,7 +144,7 @@ static void mark_dead_jobs_as_notified __P((int));
static void get_new_window_size __P((int));
static sighandler sigwinch_sighandler __P((int));
-static sighandler wait_signal_handler __P((int));
+static sighandler wait_sigint_handler __P((int));
#if defined (HAVE_WAITPID)
static void reap_zombie_children __P((void));
@@ -306,7 +307,12 @@ mark_dead_jobs_as_notified (force)
ndead++;
}
- if (force == 0 && ndead <= CHILD_MAX)
+ if (child_max < 0)
+ child_max = getmaxchild ();
+ if (child_max < 0)
+ child_max = DEFAULT_CHILD_MAX;
+
+ if (force == 0 && ndead <= child_max)
return;
/* If FORCE == 0, we just mark as many non-running async jobs as notified
@@ -319,7 +325,7 @@ mark_dead_jobs_as_notified (force)
pid_list[i].pid != last_asynchronous_pid)
{
pid_list[i].flags |= PROC_NOTIFIED;
- if (force == 0 && (pid_list[i].flags & PROC_ASYNC) && --ndead <= CHILD_MAX)
+ if (force == 0 && (pid_list[i].flags & PROC_ASYNC) && --ndead <= child_max)
break;
}
}
@@ -588,13 +594,16 @@ wait_for_single_pid (pid)
set_pid_status (got_pid, status);
}
- set_pid_status (got_pid, status);
- set_pid_flags (got_pid, PROC_NOTIFIED);
+ if (got_pid > 0)
+ {
+ set_pid_status (got_pid, status);
+ set_pid_flags (got_pid, PROC_NOTIFIED);
+ }
siginterrupt (SIGINT, 0);
QUIT;
- return (process_exit_status (status));
+ return (got_pid > 0 ? process_exit_status (status) : -1);
}
/* Wait for all of the shell's children to exit. Called by the `wait'
@@ -662,6 +671,7 @@ wait_sigint_handler (sig)
restore_sigint_handler ();
interrupt_immediately = 0;
trap_handler (SIGINT); /* set pending_traps[SIGINT] */
+ wait_signal_received = SIGINT;
longjmp (wait_intr_buf, 1);
}
@@ -719,7 +729,8 @@ wait_for (pid)
set_pid_status (got_pid, status);
}
- set_pid_status (got_pid, status);
+ if (got_pid > 0)
+ set_pid_status (got_pid, status);
#if defined (HAVE_WAITPID)
if (got_pid >= 0)