diff options
author | Bryan Drewery <bryan@shatow.net> | 2019-02-27 03:32:55 +0300 |
---|---|---|
committer | Bryan Drewery <bryan@shatow.net> | 2019-02-27 03:33:14 +0300 |
commit | 971e870af31dbc021ed47dd62d0bdacf46dc390a (patch) | |
tree | d8fe5a1a61b6adf862d77077c1b3df6a99b2685d /external | |
parent | f1e68f5f761dc2158a08a64d0d1eabd35d4bc99a (diff) |
Update sh from FreeBSD r344502.
This brings in pipefail support.
Diffstat (limited to 'external')
-rw-r--r-- | external/sh/histedit.c | 25 | ||||
-rw-r--r-- | external/sh/jobs.c | 25 | ||||
-rw-r--r-- | external/sh/options.h | 6 | ||||
-rw-r--r-- | external/sh/output.c | 8 | ||||
-rw-r--r-- | external/sh/output.h | 4 |
5 files changed, 58 insertions, 10 deletions
diff --git a/external/sh/histedit.c b/external/sh/histedit.c index 81a7996b..4d028518 100644 --- a/external/sh/histedit.c +++ b/external/sh/histedit.c @@ -36,7 +36,7 @@ static char sccsid[] = "@(#)histedit.c 8.2 (Berkeley) 5/4/95"; #endif #endif /* not lint */ #include <sys/cdefs.h> -__FBSDID("$FreeBSD: head/bin/sh/histedit.c 343215 2019-01-20 14:25:25Z jilles $"); +__FBSDID("$FreeBSD: head/bin/sh/histedit.c 344306 2019-02-19 21:27:30Z jilles $"); #include <sys/param.h> #include <limits.h> @@ -472,10 +472,31 @@ str_to_event(const char *str, int last) int bindcmd(int argc, char **argv) { + int ret; + FILE *old; + FILE *out; if (el == NULL) error("line editing is disabled"); - return (el_parse(el, argc, __DECONST(const char **, argv))); + + INTOFF; + + out = out1fp(); + if (out == NULL) + error("Out of space"); + + el_get(el, EL_GETFP, 1, &old); + el_set(el, EL_SETFP, 1, out); + + ret = el_parse(el, argc, __DECONST(const char **, argv)); + + el_set(el, EL_SETFP, 1, old); + + fclose(out); + + INTON; + + return ret; } #else diff --git a/external/sh/jobs.c b/external/sh/jobs.c index 77699985..265ddaf7 100644 --- a/external/sh/jobs.c +++ b/external/sh/jobs.c @@ -36,7 +36,7 @@ static char sccsid[] = "@(#)jobs.c 8.5 (Berkeley) 5/4/95"; #endif #endif /* not lint */ #include <sys/cdefs.h> -__FBSDID("$FreeBSD: head/bin/sh/jobs.c 340284 2018-11-09 14:58:24Z jilles $"); +__FBSDID("$FreeBSD: head/bin/sh/jobs.c 344502 2019-02-24 21:05:13Z jilles $"); #include <sys/ioctl.h> #include <sys/param.h> @@ -105,6 +105,7 @@ struct job { char changed; /* true if status has changed */ char foreground; /* true if running in the foreground */ char remembered; /* true if $! referenced */ + char pipefail; /* pass any non-zero status */ #if JOBS char jobctl; /* job running under job control */ struct job *next; /* job used after this one */ @@ -144,6 +145,7 @@ static void setcurjob(struct job *); static void deljob(struct job *); static struct job *getcurjob(struct job *); #endif +static int getjobstatus(const struct job *); static void printjobcmd(struct job *); static void showjob(struct job *, int); @@ -341,6 +343,20 @@ jobscmd(int argc __unused, char *argv[] __unused) return (0); } +static int getjobstatus(const struct job *jp) +{ + int i, status; + + if (!jp->pipefail) + return (jp->ps[jp->nprocs - 1].status); + for (i = jp->nprocs - 1; i >= 0; i--) { + status = jp->ps[i].status; + if (status != 0) + return (status); + } + return (0); +} + static void printjobcmd(struct job *jp) { @@ -377,7 +393,7 @@ showjob(struct job *jp, int mode) } #endif coredump = ""; - status = jp->ps[jp->nprocs - 1].status; + status = getjobstatus(jp); if (jp->state == 0) { statestr = "Running"; #if JOBS @@ -556,7 +572,7 @@ waitcmdloop(struct job *job) do { if (job != NULL) { if (job->state == JOBDONE) { - status = job->ps[job->nprocs - 1].status; + status = getjobstatus(job); if (WIFEXITED(status)) retval = WEXITSTATUS(status); else @@ -781,6 +797,7 @@ makejob(union node *node __unused, int nprocs) jp->nprocs = 0; jp->foreground = 0; jp->remembered = 0; + jp->pipefail = pipefailflag; #if JOBS jp->jobctl = jobctl; jp->next = NULL; @@ -1076,7 +1093,7 @@ waitforjob(struct job *jp, int *signaled) if (jp->state == JOBSTOPPED) setcurjob(jp); #endif - status = jp->ps[jp->nprocs - 1].status; + status = getjobstatus(jp); if (signaled != NULL) *signaled = WIFSIGNALED(status); /* convert to 8 bits */ diff --git a/external/sh/options.h b/external/sh/options.h index 233e9c62..ac772290 100644 --- a/external/sh/options.h +++ b/external/sh/options.h @@ -32,7 +32,7 @@ * SUCH DAMAGE. * * @(#)options.h 8.2 (Berkeley) 5/4/95 - * $FreeBSD: head/bin/sh/options.h 326025 2017-11-20 19:49:47Z pfg $ + * $FreeBSD: head/bin/sh/options.h 344502 2019-02-24 21:05:13Z jilles $ */ struct shparam { @@ -67,9 +67,10 @@ struct shparam { #define Pflag optval[17] #define hflag optval[18] #define nologflag optval[19] +#define pipefailflag optval[20] #define NSHORTOPTS 19 -#define NOPTS 20 +#define NOPTS 21 extern char optval[NOPTS]; extern const char optletter[NSHORTOPTS]; @@ -97,6 +98,7 @@ static const unsigned char optname[] = "\010physical" "\010trackall" "\005nolog" + "\010pipefail" ; #endif diff --git a/external/sh/output.c b/external/sh/output.c index 737eb91c..6f9fb45f 100644 --- a/external/sh/output.c +++ b/external/sh/output.c @@ -38,7 +38,7 @@ static char sccsid[] = "@(#)output.c 8.2 (Berkeley) 5/4/95"; #endif #endif /* not lint */ #include <sys/cdefs.h> -__FBSDID("$FreeBSD: head/bin/sh/output.c 326025 2017-11-20 19:49:47Z pfg $"); +__FBSDID("$FreeBSD: head/bin/sh/output.c 344306 2019-02-19 21:27:30Z jilles $"); /* * Shell output routines. We use our own output routines because: @@ -340,6 +340,12 @@ doformat(struct output *dest, const char *f, va_list ap) } } +FILE * +out1fp(void) +{ + return fwopen(out1, doformat_wr); +} + /* * Version of write which resumes after a signal is caught. */ diff --git a/external/sh/output.h b/external/sh/output.h index 652187a1..83cb8acb 100644 --- a/external/sh/output.h +++ b/external/sh/output.h @@ -32,13 +32,14 @@ * SUCH DAMAGE. * * @(#)output.h 8.2 (Berkeley) 5/4/95 - * $FreeBSD: head/bin/sh/output.h 326025 2017-11-20 19:49:47Z pfg $ + * $FreeBSD: head/bin/sh/output.h 344306 2019-02-19 21:27:30Z jilles $ */ #ifndef OUTPUT_INCL #include <stdarg.h> #include <stddef.h> +#include <stdio.h> struct output { char *nextc; @@ -75,6 +76,7 @@ void out1fmt(const char *, ...) __printflike(1, 2); void out2fmt_flush(const char *, ...) __printflike(1, 2); void fmtstr(char *, int, const char *, ...) __printflike(3, 4); void doformat(struct output *, const char *, va_list) __printflike(2, 0); +FILE *out1fp(void); int xwrite(int, const char *, int); #define outc(c, file) ((file)->nextc == (file)->bufend ? (emptyoutbuf(file), *(file)->nextc++ = (c)) : (*(file)->nextc++ = (c))) |