aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-05-26 14:34:10 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-05-26 14:34:10 +0200
commite2df5f46d02d170d1d8c9dfdd186ef23504109dc (patch)
tree32015a7cfa8242d1fd3cdc8b349cc6be2f81e3dc
parent140def848c1a5997383a2954590663b55155e169 (diff)
downloadbusybox-w32-e2df5f46d02d170d1d8c9dfdd186ef23504109dc.tar.gz
busybox-w32-e2df5f46d02d170d1d8c9dfdd186ef23504109dc.tar.bz2
busybox-w32-e2df5f46d02d170d1d8c9dfdd186ef23504109dc.zip
hush: rename last_waitpid_was_0 to we_have_children
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/hush.c30
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 {
495#if ENABLE_HUSH_FAST 495#if ENABLE_HUSH_FAST
496 unsigned count_SIGCHLD; 496 unsigned count_SIGCHLD;
497 unsigned handled_SIGCHLD; 497 unsigned handled_SIGCHLD;
498 smallint last_waitpid_was_0; 498 smallint we_have_children;
499#endif 499#endif
500 /* which signals have non-DFL handler (even with no traps set)? */ 500 /* which signals have non-DFL handler (even with no traps set)? */
501 unsigned non_DFL_mask; 501 unsigned non_DFL_mask;
@@ -3292,22 +3292,30 @@ static int checkjobs(struct pipe* fg_pipe)
3292 3292
3293 debug_printf_jobs("checkjobs %p\n", fg_pipe); 3293 debug_printf_jobs("checkjobs %p\n", fg_pipe);
3294 3294
3295 attributes = WUNTRACED;
3296 if (fg_pipe == NULL)
3297 attributes |= WNOHANG;
3298
3295 errno = 0; 3299 errno = 0;
3296#if ENABLE_HUSH_FAST 3300#if ENABLE_HUSH_FAST
3297 if (G.handled_SIGCHLD == G.count_SIGCHLD) { 3301 if (G.handled_SIGCHLD == G.count_SIGCHLD) {
3298//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); 3302//bb_error_msg("[%d] checkjobs: G.count_SIGCHLD:%d G.handled_SIGCHLD:%d children?:%d fg_pipe:%p",
3299 /* avoid doing syscall, nothing there anyway */ 3303//getpid(), G.count_SIGCHLD, G.handled_SIGCHLD, G.we_have_children, fg_pipe);
3300 if (G.last_waitpid_was_0) 3304 /* There was heither fork nor SIGCHLD since last waitpid */
3305 /* Avoid doing syscall, nothing there anyway */
3306 if (!G.we_have_children) {
3307 errno = ECHILD;
3308 return -1;
3309 }
3310 if (fg_pipe == NULL) { /* is WNOHANG set? */
3311 /* We have children, but they did not exit
3312 * or stop yet (we saw no SIGCHLD) */
3301 return 0; 3313 return 0;
3302 errno = ECHILD; 3314 }
3303 return -1; 3315 /* else: !WNOHANG, waitpid will block, can't short-circuit */
3304 } 3316 }
3305#endif 3317#endif
3306 3318
3307 attributes = WUNTRACED;
3308 if (fg_pipe == NULL)
3309 attributes |= WNOHANG;
3310
3311/* Do we do this right? 3319/* Do we do this right?
3312 * bash-3.00# sleep 20 | false 3320 * bash-3.00# sleep 20 | false
3313 * <ctrl-Z pressed> 3321 * <ctrl-Z pressed>
@@ -3330,7 +3338,7 @@ static int checkjobs(struct pipe* fg_pipe)
3330 bb_perror_msg("waitpid"); 3338 bb_perror_msg("waitpid");
3331#if ENABLE_HUSH_FAST 3339#if ENABLE_HUSH_FAST
3332 else { /* Until next SIGCHLD, waitpid's are useless */ 3340 else { /* Until next SIGCHLD, waitpid's are useless */
3333 G.last_waitpid_was_0 = (childpid == 0); 3341 G.we_have_children = (childpid == 0);
3334 G.handled_SIGCHLD = i; 3342 G.handled_SIGCHLD = i;
3335//bb_error_msg("[%d] checkjobs: waitpid returned <= 0, G.count_SIGCHLD:%d G.handled_SIGCHLD:%d", getpid(), G.count_SIGCHLD, G.handled_SIGCHLD); 3343//bb_error_msg("[%d] checkjobs: waitpid returned <= 0, G.count_SIGCHLD:%d G.handled_SIGCHLD:%d", getpid(), G.count_SIGCHLD, G.handled_SIGCHLD);
3336 } 3344 }