ash: distinguish 'wait -n' from other bashisms
Add a specific define to indicate which bash compatibility code implements 'wait -n'. Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
8939359180
commit
e48559eae3
15
shell/ash.c
15
shell/ash.c
@ -224,6 +224,7 @@
|
|||||||
#define BASH_XTRACEFD ENABLE_ASH_BASH_COMPAT
|
#define BASH_XTRACEFD ENABLE_ASH_BASH_COMPAT
|
||||||
#define BASH_READ_D ENABLE_ASH_BASH_COMPAT
|
#define BASH_READ_D ENABLE_ASH_BASH_COMPAT
|
||||||
#define IF_BASH_READ_D IF_ASH_BASH_COMPAT
|
#define IF_BASH_READ_D IF_ASH_BASH_COMPAT
|
||||||
|
#define BASH_WAIT_N ENABLE_ASH_BASH_COMPAT
|
||||||
|
|
||||||
#if defined(__ANDROID_API__) && __ANDROID_API__ <= 24
|
#if defined(__ANDROID_API__) && __ANDROID_API__ <= 24
|
||||||
/* Bionic at least up to version 24 has no glob() */
|
/* Bionic at least up to version 24 has no glob() */
|
||||||
@ -4235,7 +4236,7 @@ wait_block_or_sig(int *status)
|
|||||||
#define DOWAIT_NONBLOCK 0
|
#define DOWAIT_NONBLOCK 0
|
||||||
#define DOWAIT_BLOCK 1
|
#define DOWAIT_BLOCK 1
|
||||||
#define DOWAIT_BLOCK_OR_SIG 2
|
#define DOWAIT_BLOCK_OR_SIG 2
|
||||||
#if ENABLE_ASH_BASH_COMPAT
|
#if BASH_WAIT_N
|
||||||
# define DOWAIT_JOBSTATUS 0x10 /* OR this to get job's exitstatus instead of pid */
|
# define DOWAIT_JOBSTATUS 0x10 /* OR this to get job's exitstatus instead of pid */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -4246,7 +4247,7 @@ dowait(int block, struct job *job)
|
|||||||
int status;
|
int status;
|
||||||
struct job *jp;
|
struct job *jp;
|
||||||
struct job *thisjob;
|
struct job *thisjob;
|
||||||
#if ENABLE_ASH_BASH_COMPAT
|
#if BASH_WAIT_N
|
||||||
bool want_jobexitstatus = (block & DOWAIT_JOBSTATUS);
|
bool want_jobexitstatus = (block & DOWAIT_JOBSTATUS);
|
||||||
block = (block & ~DOWAIT_JOBSTATUS);
|
block = (block & ~DOWAIT_JOBSTATUS);
|
||||||
#endif
|
#endif
|
||||||
@ -4348,7 +4349,7 @@ dowait(int block, struct job *job)
|
|||||||
out:
|
out:
|
||||||
INT_ON;
|
INT_ON;
|
||||||
|
|
||||||
#if ENABLE_ASH_BASH_COMPAT
|
#if BASH_WAIT_N
|
||||||
if (want_jobexitstatus) {
|
if (want_jobexitstatus) {
|
||||||
pid = -1;
|
pid = -1;
|
||||||
if (thisjob && thisjob->state == JOBDONE)
|
if (thisjob && thisjob->state == JOBDONE)
|
||||||
@ -4537,7 +4538,7 @@ waitcmd(int argc UNUSED_PARAM, char **argv)
|
|||||||
struct job *job;
|
struct job *job;
|
||||||
int retval;
|
int retval;
|
||||||
struct job *jp;
|
struct job *jp;
|
||||||
#if ENABLE_ASH_BASH_COMPAT
|
#if BASH_WAIT_N
|
||||||
int status;
|
int status;
|
||||||
char one = nextopt("n");
|
char one = nextopt("n");
|
||||||
#else
|
#else
|
||||||
@ -4550,7 +4551,7 @@ waitcmd(int argc UNUSED_PARAM, char **argv)
|
|||||||
/* wait for all jobs / one job if -n */
|
/* wait for all jobs / one job if -n */
|
||||||
for (;;) {
|
for (;;) {
|
||||||
jp = curjob;
|
jp = curjob;
|
||||||
#if ENABLE_ASH_BASH_COMPAT
|
#if BASH_WAIT_N
|
||||||
if (one && !jp)
|
if (one && !jp)
|
||||||
/* exitcode of "wait -n" with nothing to wait for is 127, not 0 */
|
/* exitcode of "wait -n" with nothing to wait for is 127, not 0 */
|
||||||
retval = 127;
|
retval = 127;
|
||||||
@ -4570,7 +4571,7 @@ waitcmd(int argc UNUSED_PARAM, char **argv)
|
|||||||
* with an exit status greater than 128, immediately after which
|
* with an exit status greater than 128, immediately after which
|
||||||
* the trap is executed."
|
* the trap is executed."
|
||||||
*/
|
*/
|
||||||
#if ENABLE_ASH_BASH_COMPAT
|
#if BASH_WAIT_N
|
||||||
status = dowait(DOWAIT_BLOCK_OR_SIG | DOWAIT_JOBSTATUS, NULL);
|
status = dowait(DOWAIT_BLOCK_OR_SIG | DOWAIT_JOBSTATUS, NULL);
|
||||||
#else
|
#else
|
||||||
dowait(DOWAIT_BLOCK_OR_SIG, NULL);
|
dowait(DOWAIT_BLOCK_OR_SIG, NULL);
|
||||||
@ -4581,7 +4582,7 @@ waitcmd(int argc UNUSED_PARAM, char **argv)
|
|||||||
*/
|
*/
|
||||||
if (pending_sig)
|
if (pending_sig)
|
||||||
goto sigout;
|
goto sigout;
|
||||||
#if ENABLE_ASH_BASH_COMPAT
|
#if BASH_WAIT_N
|
||||||
if (one) {
|
if (one) {
|
||||||
/* wait -n waits for one _job_, not one _process_.
|
/* wait -n waits for one _job_, not one _process_.
|
||||||
* date; sleep 3 & sleep 2 | sleep 1 & wait -n; date
|
* date; sleep 3 & sleep 2 | sleep 1 & wait -n; date
|
||||||
|
Loading…
x
Reference in New Issue
Block a user