Source-Changes-HG archive

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

[src/trunk]: src/bin/sh Change the way the pipefail option works. Now it is...



details:   https://anonhg.NetBSD.org/src/rev/d32ad5c2d0bb
branches:  trunk
changeset: 993326:d32ad5c2d0bb
user:      kre <kre%NetBSD.org@localhost>
date:      Tue Sep 04 23:16:30 2018 +0000

description:
Change the way the pipefail option works.   Now it is the setting of
the option when a pipeline is created that controls the way the exit
status of the pipeline is calculated.  Previously it was the state of
the option when the exit status of the pipeline was collected.

This makes no difference at all for foreground pipelines (there is
no way to change the option between starting and completing the
pipeline) but it does for asynchronous (background) pipelines.

This was always the right way to implement it - it was originally
done the other way as I could not find any other shell implemented
this way - they all seemed to do it our previous way, and I could
not see a good reason to be the sole different shell.

However, now I know that ksh93 works as we will now work, and I
am told that if the option is added to the FreeBSD shell (apparently
the code exists, uncommitted) it will be the same.

diffstat:

 bin/sh/jobs.c |  12 ++++++------
 bin/sh/jobs.h |   3 ++-
 bin/sh/sh.1   |  19 ++++++++++---------
 3 files changed, 18 insertions(+), 16 deletions(-)

diffs (107 lines):

diff -r 3db71e13ddeb -r d32ad5c2d0bb bin/sh/jobs.c
--- a/bin/sh/jobs.c     Tue Sep 04 22:57:25 2018 +0000
+++ b/bin/sh/jobs.c     Tue Sep 04 23:16:30 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: jobs.c,v 1.99 2018/09/04 01:09:28 kre Exp $    */
+/*     $NetBSD: jobs.c,v 1.100 2018/09/04 23:16:30 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.99 2018/09/04 01:09:28 kre Exp $");
+__RCSID("$NetBSD: jobs.c,v 1.100 2018/09/04 23:16:30 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -635,7 +635,7 @@
        int status = 0;
        int retval;
 
-       if (pipefail && jp->nprocs) {
+       if ((jp->flags & JPIPEFAIL) && jp->nprocs) {
                int i;
 
                for (i = 0; i < jp->nprocs; i++)
@@ -1068,7 +1068,7 @@
        INTOFF;
        jp->state = JOBRUNNING;
        jp->used = 1;
-       jp->flags = 0;
+       jp->flags = pipefail ? JPIPEFAIL : 0;
        jp->nprocs = 0;
        jp->pgrp = 0;
 #if JOBS
@@ -1081,8 +1081,8 @@
                jp->ps = &jp->ps0;
        }
        INTON;
-       VTRACE(DBG_JOBS, ("makejob(0x%lx, %d) returns %%%d\n",
-           (long)node, nprocs, jp - jobtab + 1));
+       VTRACE(DBG_JOBS, ("makejob(%p, %d)%s returns %%%d\n", (void *)node,
+           nprocs, (jp->flags&JPIPEFAIL)?" PF":"", jp - jobtab + 1));
        return jp;
 }
 
diff -r 3db71e13ddeb -r d32ad5c2d0bb bin/sh/jobs.h
--- a/bin/sh/jobs.h     Tue Sep 04 22:57:25 2018 +0000
+++ b/bin/sh/jobs.h     Tue Sep 04 23:16:30 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: jobs.h,v 1.21 2017/10/28 06:36:17 kre Exp $    */
+/*     $NetBSD: jobs.h,v 1.22 2018/09/04 23:16:30 kre Exp $    */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -79,6 +79,7 @@
        char    flags;  
 #define        JOBCHANGED      1       /* set if status has changed */
 #define        JOBWANTED       2       /* set if this is a job being sought */
+#define JPIPEFAIL      4       /* set if -o pipefail when job created */
 #if JOBS
        char    jobctl;         /* job running under job control */
        int     prev_job;       /* previous job index */
diff -r 3db71e13ddeb -r d32ad5c2d0bb bin/sh/sh.1
--- a/bin/sh/sh.1       Tue Sep 04 22:57:25 2018 +0000
+++ b/bin/sh/sh.1       Tue Sep 04 23:16:30 2018 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: sh.1,v 1.207 2018/08/25 17:35:31 kre Exp $
+.\"    $NetBSD: sh.1,v 1.208 2018/09/04 23:16:30 kre Exp $
 .\" Copyright (c) 1991, 1993
 .\"    The Regents of the University of California.  All rights reserved.
 .\"
@@ -488,7 +488,8 @@
 section.)
 (Not implemented.)
 .It "\ \ " Em pipefail
-If set, the way the exit status of a pipeline is determined
+If set when a pipeline is created,
+the way the exit status of the pipeline is determined
 is altered.
 See
 .Sx Pipelines
@@ -1155,16 +1156,16 @@
 .Pp
 If the
 .Ic pipefail
-option is set when the pipeline completes and its status is
-collected, the pipeline status is the status of
-the last (rightmost) command in the pipeline to exit with non-zero exit
-status, or zero, if, and only if, all commands in the pipeline
-exited with a status of zero.
+option was set when a pipeline was started,
+the pipeline status is the status of
+the last (lexically last, i.e.: rightmost) command in the
+pipeline to exit with non-zero exit status, or zero, if,
+and only if, all commands in the pipeline exited with a status of zero.
 If the
 .Ic pipefail
-option is not set, which is the default state,
+option was not set, which is the default state,
 the pipeline status is the exit
-status of the last command in the pipeline,
+status of the last (rightmost) command in the pipeline,
 and the exit status of any other commands in the pipeline is ignored.
 .Pp
 If the reserved word



Home | Main Index | Thread Index | Old Index