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).
This commit is contained in:
kre 2019-02-09 09:31:33 +00:00
parent b4a242b5e2
commit ccf5ffdbe9
1 changed files with 13 additions and 8 deletions

View File

@ -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;
}