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:
parent
b4a242b5e2
commit
ccf5ffdbe9
|
@ -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
|
* Copyright (c) 1991, 1993
|
||||||
|
@ -37,7 +37,7 @@
|
||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)jobs.c 8.5 (Berkeley) 5/4/95";
|
static char sccsid[] = "@(#)jobs.c 8.5 (Berkeley) 5/4/95";
|
||||||
#else
|
#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
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
|
@ -374,16 +374,19 @@ STATIC void
|
||||||
restartjob(struct job *jp)
|
restartjob(struct job *jp)
|
||||||
{
|
{
|
||||||
struct procstat *ps;
|
struct procstat *ps;
|
||||||
int i;
|
int i, e;
|
||||||
|
|
||||||
if (jp->state == JOBDONE)
|
if (jp->state == JOBDONE)
|
||||||
return;
|
return;
|
||||||
INTOFF;
|
INTOFF;
|
||||||
for (i = 0; i < jp->nprocs; i++)
|
for (e = i = 0; i < jp->nprocs; i++) {
|
||||||
if (killpg(jp->ps[i].pid, SIGCONT) != -1)
|
if (killpg(jp->ps[i].pid, SIGCONT) != -1)
|
||||||
break;
|
break;
|
||||||
|
if (e == 0 && errno != ESRCH)
|
||||||
|
e = errno;
|
||||||
|
}
|
||||||
if (i >= jp->nprocs)
|
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++) {
|
for (ps = jp->ps, i = jp->nprocs ; --i >= 0 ; ps++) {
|
||||||
if (WIFSTOPPED(ps->status)) {
|
if (WIFSTOPPED(ps->status)) {
|
||||||
VTRACE(DBG_JOBS, (
|
VTRACE(DBG_JOBS, (
|
||||||
|
@ -535,13 +538,15 @@ jobscmd(int argc, char **argv)
|
||||||
mode = SHOW_PID;
|
mode = SHOW_PID;
|
||||||
else
|
else
|
||||||
mode = SHOW_PGID;
|
mode = SHOW_PGID;
|
||||||
if (!iflag)
|
|
||||||
|
if (!iflag && !posix)
|
||||||
mode |= SHOW_NO_FREE;
|
mode |= SHOW_NO_FREE;
|
||||||
if (*argptr)
|
|
||||||
|
if (*argptr) {
|
||||||
do
|
do
|
||||||
showjob(out1, getjob(*argptr,0), mode);
|
showjob(out1, getjob(*argptr,0), mode);
|
||||||
while (*++argptr);
|
while (*++argptr);
|
||||||
else
|
} else
|
||||||
showjobs(out1, mode);
|
showjobs(out1, mode);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue