Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/bin/sh Fix a logic botch that prevented "wait -n" (with no p...
details: https://anonhg.NetBSD.org/src/rev/479192ae9f14
branches: trunk
changeset: 840167:479192ae9f14
user: kre <kre%NetBSD.org@localhost>
date: Tue Mar 26 13:32:26 2019 +0000
description:
Fix a logic botch that prevented "wait -n" (with no pid args) from
finding a job that had previously terminated.
Now in that case JOBWANTED is set on all jobs (since any will do)
which then simplifies a later test which no longer needs to special
case "wait -n". Further, we always look to see if any wanted
job has already terminated, even if there are still running jobs
we can wait upon - if anything is already ready, that's where we start
harvesting (and finish, if -n is specified).
diffstat:
bin/sh/jobs.c | 26 ++++++++++++++++++--------
1 files changed, 18 insertions(+), 8 deletions(-)
diffs (73 lines):
diff -r b2818347c952 -r 479192ae9f14 bin/sh/jobs.c
--- a/bin/sh/jobs.c Tue Mar 26 12:22:07 2019 +0000
+++ b/bin/sh/jobs.c Tue Mar 26 13:32:26 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: jobs.c,v 1.105 2019/02/09 09:31:33 kre Exp $ */
+/* $NetBSD: jobs.c,v 1.106 2019/03/26 13:32:26 kre Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)jobs.c 8.5 (Berkeley) 5/4/95";
#else
-__RCSID("$NetBSD: jobs.c,v 1.105 2019/02/09 09:31:33 kre Exp $");
+__RCSID("$NetBSD: jobs.c,v 1.106 2019/03/26 13:32:26 kre Exp $");
#endif
#endif /* not lint */
@@ -710,9 +710,15 @@
return (any || *argptr) ? 127 : 0;
}
- /* clear stray flags left from previous waitcmd */
+ /*
+ * clear stray flags left from previous waitcmd
+ * or set them instead if anything will do ("wait -n")
+ */
for (jp = jobtab, i = njobs ; --i >= 0 ; jp++) {
- jp->flags &= ~JOBWANTED;
+ if (any && *argptr == NULL)
+ jp->flags |= JOBWANTED;
+ else
+ jp->flags &= ~JOBWANTED;
jp->ref = NULL;
}
@@ -784,20 +790,24 @@
fpid = NULL;
for (;;) {
VTRACE(DBG_WAIT, ("wait waiting (%d remain): ", found));
+ job = NULL;
for (jp = jobtab, i = njobs; --i >= 0; jp++) {
if (jp->used && jp->flags & JOBWANTED &&
- jp->state == JOBDONE)
+ jp->state == JOBDONE) {
+ job = jp;
break;
+ }
if (jp->used && jp->state == JOBRUNNING)
- break;
+ job = jp;
}
- if (i < 0) {
+ if (i < 0 && job == NULL) {
CTRACE(DBG_WAIT, ("nothing running (ret: %d) fpid %s\n",
retval, fpid ? fpid : "unset"));
if (pid && fpid)
setvar(pid, fpid, 0);
return retval;
}
+ jp = job;
VTRACE(DBG_WAIT, ("found @%d/%d state: %d\n", njobs-i, njobs,
jp->state));
@@ -819,7 +829,7 @@
} else
job = jp; /* we want this, and it is done */
- if (job->flags & JOBWANTED || (*argptr == 0 && any)) {
+ if (job->flags & JOBWANTED) {
int rv;
job->flags &= ~JOBWANTED; /* got it */
Home |
Main Index |
Thread Index |
Old Index