diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2016-10-27 20:08:28 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2016-10-27 21:13:24 +0200 |
commit | b543bdadb3014661b6052c82b31e0012abc1e210 (patch) | |
tree | f8c02fde699f0f2c5721bbe569cee4f7f6fe8dea | |
parent | 3f44a6be58805ff628c03b81597fbf15df88c098 (diff) | |
download | busybox-w32-b543bdadb3014661b6052c82b31e0012abc1e210.tar.gz busybox-w32-b543bdadb3014661b6052c82b31e0012abc1e210.tar.bz2 busybox-w32-b543bdadb3014661b6052c82b31e0012abc1e210.zip |
ash: return to DOWAIT_* constants similar to dash, no logic changes
This loses an insignificant optimization, but may allow backporting
of some recent-ish dash fixes.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/ash.c | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/shell/ash.c b/shell/ash.c index 05de8660d..3a364dc2c 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -3512,8 +3512,8 @@ setsignal(int signo) | |||
3512 | #define CUR_STOPPED 0 | 3512 | #define CUR_STOPPED 0 |
3513 | 3513 | ||
3514 | /* mode flags for dowait */ | 3514 | /* mode flags for dowait */ |
3515 | #define DOWAIT_NONBLOCK WNOHANG | 3515 | #define DOWAIT_NONBLOCK 0 |
3516 | #define DOWAIT_BLOCK 0 | 3516 | #define DOWAIT_BLOCK 1 |
3517 | 3517 | ||
3518 | #if JOBS | 3518 | #if JOBS |
3519 | /* pgrp of shell on invocation */ | 3519 | /* pgrp of shell on invocation */ |
@@ -3935,18 +3935,23 @@ sprint_status48(char *s, int status, int sigonly) | |||
3935 | } | 3935 | } |
3936 | 3936 | ||
3937 | static int | 3937 | static int |
3938 | dowait(int wait_flags, struct job *job) | 3938 | dowait(int block, struct job *job) |
3939 | { | 3939 | { |
3940 | int wait_flags; | ||
3940 | int pid; | 3941 | int pid; |
3941 | int status; | 3942 | int status; |
3942 | struct job *jp; | 3943 | struct job *jp; |
3943 | struct job *thisjob; | 3944 | struct job *thisjob; |
3944 | 3945 | ||
3945 | TRACE(("dowait(0x%x) called\n", wait_flags)); | 3946 | TRACE(("dowait(0x%x) called\n", block)); |
3946 | 3947 | ||
3947 | /* Do a wait system call. If job control is compiled in, we accept | 3948 | /* Do a wait system call. If job control is compiled in, we accept |
3948 | * stopped processes. wait_flags may have WNOHANG, preventing blocking. | 3949 | * stopped processes. |
3949 | * NB: _not_ safe_waitpid, we need to detect EINTR */ | 3950 | * NB: _not_ safe_waitpid, we need to detect EINTR. |
3951 | */ | ||
3952 | wait_flags = 0; | ||
3953 | if (block == DOWAIT_NONBLOCK) | ||
3954 | wait_flags = WNOHANG; | ||
3950 | if (doing_jobctl) | 3955 | if (doing_jobctl) |
3951 | wait_flags |= WUNTRACED; | 3956 | wait_flags |= WUNTRACED; |
3952 | pid = waitpid(-1, &status, wait_flags); | 3957 | pid = waitpid(-1, &status, wait_flags); |
@@ -4028,7 +4033,7 @@ dowait(int wait_flags, struct job *job) | |||
4028 | } | 4033 | } |
4029 | 4034 | ||
4030 | static int | 4035 | static int |
4031 | blocking_wait_with_raise_on_sig(void) | 4036 | blocking_dowait_with_raise_on_sig(void) |
4032 | { | 4037 | { |
4033 | pid_t pid = dowait(DOWAIT_BLOCK, NULL); | 4038 | pid_t pid = dowait(DOWAIT_BLOCK, NULL); |
4034 | if (pid <= 0 && pending_sig) | 4039 | if (pid <= 0 && pending_sig) |
@@ -4224,7 +4229,7 @@ waitcmd(int argc UNUSED_PARAM, char **argv) | |||
4224 | jp->waited = 1; | 4229 | jp->waited = 1; |
4225 | jp = jp->prev_job; | 4230 | jp = jp->prev_job; |
4226 | } | 4231 | } |
4227 | blocking_wait_with_raise_on_sig(); | 4232 | blocking_dowait_with_raise_on_sig(); |
4228 | /* man bash: | 4233 | /* man bash: |
4229 | * "When bash is waiting for an asynchronous command via | 4234 | * "When bash is waiting for an asynchronous command via |
4230 | * the wait builtin, the reception of a signal for which a trap | 4235 | * the wait builtin, the reception of a signal for which a trap |
@@ -4232,10 +4237,10 @@ waitcmd(int argc UNUSED_PARAM, char **argv) | |||
4232 | * with an exit status greater than 128, immediately after which | 4237 | * with an exit status greater than 128, immediately after which |
4233 | * the trap is executed." | 4238 | * the trap is executed." |
4234 | * | 4239 | * |
4235 | * blocking_wait_with_raise_on_sig raises signal handlers | 4240 | * blocking_dowait_with_raise_on_sig raises signal handlers |
4236 | * if it gets no pid (pid < 0). However, | 4241 | * if it gets no pid (pid < 0). However, |
4237 | * if child sends us a signal *and immediately exits*, | 4242 | * if child sends us a signal *and immediately exits*, |
4238 | * blocking_wait_with_raise_on_sig gets pid > 0 | 4243 | * blocking_dowait_with_raise_on_sig gets pid > 0 |
4239 | * and does not handle pending_sig. Check this case: */ | 4244 | * and does not handle pending_sig. Check this case: */ |
4240 | if (pending_sig) | 4245 | if (pending_sig) |
4241 | raise_exception(EXSIG); | 4246 | raise_exception(EXSIG); |
@@ -4259,7 +4264,7 @@ waitcmd(int argc UNUSED_PARAM, char **argv) | |||
4259 | } | 4264 | } |
4260 | /* loop until process terminated or stopped */ | 4265 | /* loop until process terminated or stopped */ |
4261 | while (job->state == JOBRUNNING) | 4266 | while (job->state == JOBRUNNING) |
4262 | blocking_wait_with_raise_on_sig(); | 4267 | blocking_dowait_with_raise_on_sig(); |
4263 | job->waited = 1; | 4268 | job->waited = 1; |
4264 | retval = getstatus(job); | 4269 | retval = getstatus(job); |
4265 | repeat: ; | 4270 | repeat: ; |