[git commit] ash: fix !BASH_COMPAT build, tweak variable names, add comments

Denys Vlasenko vda.linux at googlemail.com
Fri Oct 9 10:26:51 UTC 2026


commit: https://git.busybox.net/busybox/commit/?id=4a9fe5a0c27a10e2af7b71392c6a8cfb488e146e
branch: https://git.busybox.net/busybox/log/?h=master

The work to improve "wait -n" is based on patches by
    Luiz Angelo Daros de Luca <luizluca at gmail.com>
and
    Dominique Martinet <dominique.martinet at atmark-techno.com>

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 shell/ash.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/shell/ash.c b/shell/ash.c
index 18b80fe4d..88c16487f 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -4547,6 +4547,7 @@ static int dowait_n(int block, struct job *jp, int *pstatus, struct job **done_j
 
 	return pid;
 }
+/* nake dowait() calls look the same as in dash: */
 #if !BASH_WAIT_N
 # define dowait(block, jp) dowait_n((block), (jp), UNUSED, UNUSED)
 #else
@@ -4855,14 +4856,13 @@ stoppedjobs(void)
 #define stoppedjobs() 0
 #endif
 
-#if BASH_WAIT_N
 static struct job*
 getjob_match_last_pid(pid_t pid)
 {
 	struct job *jp = curjob;
 	while (jp) {
-		// WRONG: "wait -n $PID;echo $?;wait -n $PID;echo $?" should work
-		// and produce the same exitcode the second time
+		// WRONG: "wait -n $PID;echo $?;wait -n $PID;echo $?"
+		// should work and produce the same exitcode the second time
 		//if (/* jp->state == JOBDONE && */ jp->waited)
 		//	; /* these never match (pids can be very stale) */
 		//else
@@ -4872,24 +4872,25 @@ getjob_match_last_pid(pid_t pid)
 	}
 	return jp;
 }
+#if BASH_WAIT_N
 static int
-match_pid_or_jobspecs(pid_t pid, struct job *done_job, char **name, int status)
+match_pid_or_jobspecs(pid_t pid, struct job *done_job, char **argp, int status)
 {
-	while (*name) {
-		if (**name != '%') {
+	while (*argp) {
+		if (**argp != '%') {
 			/* number() can't fail here: known to be valid number */
-			if (pid == number(*name)) {
+			if (pid == number(*argp)) {
 				if (WIFEXITED(status))
 					return WEXITSTATUS(status);
 				return 128 | WTERMSIG(status);
 			}
 		} else if (done_job) {
 			/* getjob() can't fail here either */
-			struct job *jp = getjob(*name, /*must_be_jobctl:*/ 0);
+			struct job *jp = getjob(*argp, /*must_be_jobctl:*/ 0);
 			if (jp == done_job)
 				return getstatus(jp);
 		}
-		name++;
+		argp++;
 	}
 	return -1;
 }
@@ -5015,6 +5016,7 @@ waitcmd(int argc UNUSED_PARAM, char **argv)
 				status = match_pid_or_jobspecs(pid, done_job, argv, status);
 				if (status >= 0) {
 					/* even if we did "wait -n PID", not %JOB, if this matches exited job's last pid... */
+					/* ("CMD1|CMD2 & bg=$!; wait -n $bg" idiom uses pid of CMD2 intending to wait for the whole job) */
 					if (done_job && done_job->ps[done_job->nprocs - 1].ps_pid == pid)
 						done_job->waited = 1; /* ...the job is now "waited for" */
 					retval = status;


More information about the busybox-cvs mailing list