hush: rename last_waitpid_was_0 to we_have_children
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
140def848c
commit
e2df5f46d0
36
shell/hush.c
36
shell/hush.c
@ -495,7 +495,7 @@ struct globals {
|
|||||||
#if ENABLE_HUSH_FAST
|
#if ENABLE_HUSH_FAST
|
||||||
unsigned count_SIGCHLD;
|
unsigned count_SIGCHLD;
|
||||||
unsigned handled_SIGCHLD;
|
unsigned handled_SIGCHLD;
|
||||||
smallint last_waitpid_was_0;
|
smallint we_have_children;
|
||||||
#endif
|
#endif
|
||||||
/* which signals have non-DFL handler (even with no traps set)? */
|
/* which signals have non-DFL handler (even with no traps set)? */
|
||||||
unsigned non_DFL_mask;
|
unsigned non_DFL_mask;
|
||||||
@ -3292,22 +3292,30 @@ static int checkjobs(struct pipe* fg_pipe)
|
|||||||
|
|
||||||
debug_printf_jobs("checkjobs %p\n", fg_pipe);
|
debug_printf_jobs("checkjobs %p\n", fg_pipe);
|
||||||
|
|
||||||
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)
|
|
||||||
return 0;
|
|
||||||
errno = ECHILD;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
attributes = WUNTRACED;
|
attributes = WUNTRACED;
|
||||||
if (fg_pipe == NULL)
|
if (fg_pipe == NULL)
|
||||||
attributes |= WNOHANG;
|
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 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;
|
||||||
|
}
|
||||||
|
/* else: !WNOHANG, waitpid will block, can't short-circuit */
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Do we do this right?
|
/* Do we do this right?
|
||||||
* bash-3.00# sleep 20 | false
|
* bash-3.00# sleep 20 | false
|
||||||
* <ctrl-Z pressed>
|
* <ctrl-Z pressed>
|
||||||
@ -3330,7 +3338,7 @@ static int checkjobs(struct pipe* fg_pipe)
|
|||||||
bb_perror_msg("waitpid");
|
bb_perror_msg("waitpid");
|
||||||
#if ENABLE_HUSH_FAST
|
#if ENABLE_HUSH_FAST
|
||||||
else { /* Until next SIGCHLD, waitpid's are useless */
|
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;
|
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);
|
//bb_error_msg("[%d] checkjobs: waitpid returned <= 0, G.count_SIGCHLD:%d G.handled_SIGCHLD:%d", getpid(), G.count_SIGCHLD, G.handled_SIGCHLD);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user