Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/sh In the unlikely event that restarting a job fails (th...



details:   https://anonhg.NetBSD.org/src/rev/d5ff7ef939bd
branches:  trunk
changeset: 448800:d5ff7ef939bd
user:      kre <kre%NetBSD.org@localhost>
date:      Sat Feb 09 09:31:33 2019 +0000

description:
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:

 bin/sh/jobs.c |  21 +++++++++++++--------
 1 files changed, 13 insertions(+), 8 deletions(-)

diffs (60 lines):

diff -r 63350208d847 -r d5ff7ef939bd bin/sh/jobs.c
--- a/bin/sh/jobs.c     Sat Feb 09 09:20:47 2019 +0000
+++ b/bin/sh/jobs.c     Sat Feb 09 09:31:33 2019 +0000
@@ -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 @@
 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 @@
                        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;
 }



Home | Main Index | Thread Index | Old Index