diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-05-26 14:34:10 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-05-26 14:34:10 +0200 |
commit | e2df5f46d02d170d1d8c9dfdd186ef23504109dc (patch) | |
tree | 32015a7cfa8242d1fd3cdc8b349cc6be2f81e3dc | |
parent | 140def848c1a5997383a2954590663b55155e169 (diff) | |
download | busybox-e2df5f46d02d170d1d8c9dfdd186ef23504109dc.tar.gz |
hush: rename last_waitpid_was_0 to we_have_children
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/hush.c | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/shell/hush.c b/shell/hush.c index fd839d061..7360f0e4c 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -495,7 +495,7 @@ struct globals { #if ENABLE_HUSH_FAST unsigned count_SIGCHLD; unsigned handled_SIGCHLD; - smallint last_waitpid_was_0; + smallint we_have_children; #endif /* which signals have non-DFL handler (even with no traps set)? */ unsigned non_DFL_mask; @@ -3292,22 +3292,30 @@ static int checkjobs(struct pipe* fg_pipe) debug_printf_jobs("checkjobs %p\n", fg_pipe); + attributes = WUNTRACED; + if (fg_pipe == NULL) + attributes |= WNOHANG; + errno = 0; #if ENABLE_HUSH_FAST if (G.handled_SIGCHLD == G.count_SIGCHLD) { -//bb_error_msg("[%d] checkjobs: G.count_SIGCHLD:%d G.handled_SIGCHLD:%d was 0?:%d", getpid(), G.count_SIGCHLD, G.handled_SIGCHLD, G.last_waitpid_was_0); - /* avoid doing syscall, nothing there anyway */ - if (G.last_waitpid_was_0) +//bb_error_msg("[%d] checkjobs: G.count_SIGCHLD:%d G.handled_SIGCHLD:%d children?:%d fg_pipe:%p", +//getpid(), G.count_SIGCHLD, G.handled_SIGCHLD, G.we_have_children, fg_pipe); + /* There was heither fork nor SIGCHLD since last waitpid */ + /* Avoid doing syscall, nothing there anyway */ + if (!G.we_have_children) { + errno = ECHILD; + return -1; + } + if (fg_pipe == NULL) { /* is WNOHANG set? */ + /* We have children, but they did not exit + * or stop yet (we saw no SIGCHLD) */ return 0; - errno = ECHILD; - return -1; + } + /* else: !WNOHANG, waitpid will block, can't short-circuit */ } #endif - attributes = WUNTRACED; - if (fg_pipe == NULL) - attributes |= WNOHANG; - /* Do we do this right? * bash-3.00# sleep 20 | false * <ctrl-Z pressed> @@ -3330,7 +3338,7 @@ static int checkjobs(struct pipe* fg_pipe) bb_perror_msg("waitpid"); #if ENABLE_HUSH_FAST else { /* Until next SIGCHLD, waitpid's are useless */ - G.last_waitpid_was_0 = (childpid == 0); + G.we_have_children = (childpid == 0); G.handled_SIGCHLD = i; //bb_error_msg("[%d] checkjobs: waitpid returned <= 0, G.count_SIGCHLD:%d G.handled_SIGCHLD:%d", getpid(), G.count_SIGCHLD, G.handled_SIGCHLD); } |