diff options
| author | kre <kre@NetBSD.org> | 2019-02-09 09:31:33 +0000 |
|---|---|---|
| committer | kre <kre@NetBSD.org> | 2019-02-09 09:31:33 +0000 |
| commit | 6e3cff0fcc4947b599e57dd7456d123b319917d1 (patch) | |
| tree | 5c5fa8debd213db0d0d2dc42fe72cbd862f3b70d /bin | |
| parent | f3c53d743dd181a0f3a241ea168cb93461bc232a (diff) | |
In the unlikely event that restarting a job fails (the fg bg and various
%x commands) generate the most useful error message (from errno value)
rather than whichever happened last.
In posix mode, cause the "jobs" command to delete records of completed
jobs it reports on (as posix requires) as is done in interactive shells.
We don't (won't) do this in !posix mode, as the ability to throw in a
"jobs" command in a script to debug what is happening is too useful to
lose -- and any script that is relying on "jobs" instead of "wait" to
cleanup background processes (from the sh jobs table, sh always collects
zombies from the kernel) is absurd and not worth considering (besides
which I've never seen one).
Diffstat (limited to 'bin')
| -rw-r--r-- | bin/sh/jobs.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/bin/sh/jobs.c b/bin/sh/jobs.c index fb78031d487..2c1171b5160 100644 --- a/bin/sh/jobs.c +++ b/bin/sh/jobs.c @@ -1,4 +1,4 @@ -/* $NetBSD: jobs.c,v 1.104 2019/02/09 03:35:55 kre Exp $ */ +/* $NetBSD: jobs.c,v 1.105 2019/02/09 09:31:33 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.104 2019/02/09 03:35:55 kre Exp $"); +__RCSID("$NetBSD: jobs.c,v 1.105 2019/02/09 09:31:33 kre Exp $"); #endif #endif /* not lint */ @@ -374,16 +374,19 @@ STATIC void restartjob(struct job *jp) { struct procstat *ps; - int i; + int i, e; if (jp->state == JOBDONE) return; INTOFF; - for (i = 0; i < jp->nprocs; i++) + for (e = i = 0; i < jp->nprocs; i++) { if (killpg(jp->ps[i].pid, SIGCONT) != -1) break; + if (e == 0 && errno != ESRCH) + e = errno; + } if (i >= jp->nprocs) - error("Cannot continue job (%s)", strerror(errno)); + error("Cannot continue job (%s)", strerror(e ? e : ESRCH)); for (ps = jp->ps, i = jp->nprocs ; --i >= 0 ; ps++) { if (WIFSTOPPED(ps->status)) { VTRACE(DBG_JOBS, ( @@ -535,13 +538,15 @@ jobscmd(int argc, char **argv) mode = SHOW_PID; else mode = SHOW_PGID; - if (!iflag) + + if (!iflag && !posix) mode |= SHOW_NO_FREE; - if (*argptr) + + if (*argptr) { do showjob(out1, getjob(*argptr,0), mode); while (*++argptr); - else + } else showjobs(out1, mode); return 0; } |
