diff options
author | Bryan Drewery <bryan@shatow.net> | 2017-05-09 00:04:32 +0300 |
---|---|---|
committer | Bryan Drewery <bryan@shatow.net> | 2017-05-09 00:04:32 +0300 |
commit | 47f45a0cace89cc1472e0915d1d5bc3bf0cbab05 (patch) | |
tree | 244a38eb26bfdccf2aaea9834406c007ff699747 /external | |
parent | ec677705ac749ab76e61261429d6dcc99a6cb97b (diff) |
Update sh from FreeBSD head @ r317912
Diffstat (limited to 'external')
-rw-r--r-- | external/sh/alias.c | 47 | ||||
-rw-r--r-- | external/sh/arith.h | 3 | ||||
-rw-r--r-- | external/sh/eval.c | 4 | ||||
-rw-r--r-- | external/sh/exec.c | 7 | ||||
-rw-r--r-- | external/sh/expand.c | 173 | ||||
-rw-r--r-- | external/sh/miscbltin.c | 4 | ||||
-rw-r--r-- | external/sh/options.c | 10 | ||||
-rw-r--r-- | external/sh/printf.c | 18 | ||||
-rw-r--r-- | external/sh/trap.c | 11 | ||||
-rw-r--r-- | external/sh/trap.h | 4 | ||||
-rw-r--r-- | external/sh/var.c | 4 |
11 files changed, 134 insertions, 151 deletions
diff --git a/external/sh/alias.c b/external/sh/alias.c index e1bac92b..a8fe82c9 100644 --- a/external/sh/alias.c +++ b/external/sh/alias.c @@ -36,7 +36,7 @@ static char sccsid[] = "@(#)alias.c 8.3 (Berkeley) 5/4/95"; #endif #endif /* not lint */ #include <sys/cdefs.h> -__FBSDID("$FreeBSD: head/bin/sh/alias.c 314436 2017-02-28 23:42:47Z imp $"); +__FBSDID("$FreeBSD: head/bin/sh/alias.c 317039 2017-04-16 22:10:02Z jilles $"); #include <stdlib.h> #include "shell.h" @@ -45,7 +45,7 @@ __FBSDID("$FreeBSD: head/bin/sh/alias.c 314436 2017-02-28 23:42:47Z imp $"); #include "memalloc.h" #include "mystring.h" #include "alias.h" -#include "options.h" /* XXX for argptr (should remove?) */ +#include "options.h" #include "builtins.h" #define ATABSIZE 39 @@ -63,17 +63,8 @@ setalias(const char *name, const char *val) { struct alias *ap, **app; + unalias(name); app = hashalias(name); - for (ap = *app; ap; ap = ap->next) { - if (equal(name, ap->name)) { - INTOFF; - ckfree(ap->val); - ap->val = savestr(val); - INTON; - return; - } - } - /* not found */ INTOFF; ap = ckmalloc(sizeof (struct alias)); ap->name = savestr(name); @@ -85,6 +76,14 @@ setalias(const char *name, const char *val) INTON; } +static void +freealias(struct alias *ap) +{ + ckfree(ap->name); + ckfree(ap->val); + ckfree(ap); +} + static int unalias(const char *name) { @@ -106,9 +105,7 @@ unalias(const char *name) else { INTOFF; *app = ap->next; - ckfree(ap->name); - ckfree(ap->val); - ckfree(ap); + freealias(ap); INTON; } aliases--; @@ -122,19 +119,21 @@ unalias(const char *name) static void rmaliases(void) { - struct alias *ap, *tmp; + struct alias *ap, **app; int i; INTOFF; for (i = 0; i < ATABSIZE; i++) { - ap = atab[i]; - atab[i] = NULL; - while (ap) { - ckfree(ap->name); - ckfree(ap->val); - tmp = ap; - ap = ap->next; - ckfree(tmp); + app = &atab[i]; + while (*app) { + ap = *app; + if (ap->flag & ALIASINUSE) { + *ap->name = '\0'; + app = &(*app)->next; + } else { + *app = ap->next; + freealias(ap); + } } } aliases = 0; diff --git a/external/sh/arith.h b/external/sh/arith.h index a42f1112..9c2ef394 100644 --- a/external/sh/arith.h +++ b/external/sh/arith.h @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * @(#)arith.h 1.1 (Berkeley) 5/4/95 - * $FreeBSD: head/bin/sh/arith.h 314436 2017-02-28 23:42:47Z imp $ + * $FreeBSD: head/bin/sh/arith.h 315511 2017-03-18 20:41:07Z jilles $ */ #include "shell.h" @@ -35,4 +35,3 @@ #define DIGITS(var) (3 + (2 + CHAR_BIT * sizeof((var))) / 3) arith_t arith(const char *); -void arith_lex_reset(void); diff --git a/external/sh/eval.c b/external/sh/eval.c index b7d1362a..e7598b6c 100644 --- a/external/sh/eval.c +++ b/external/sh/eval.c @@ -36,7 +36,7 @@ static char sccsid[] = "@(#)eval.c 8.9 (Berkeley) 6/8/95"; #endif #endif /* not lint */ #include <sys/cdefs.h> -__FBSDID("$FreeBSD: head/bin/sh/eval.c 314436 2017-02-28 23:42:47Z imp $"); +__FBSDID("$FreeBSD: head/bin/sh/eval.c 317882 2017-05-06 13:28:42Z jilles $"); #include <paths.h> #include <signal.h> @@ -1222,7 +1222,7 @@ bltincmd(int argc, char **argv) return 127; } /* - * Preserve exitstatus of a previous possible redirection + * Preserve exitstatus of a previous possible command substitution * as POSIX mandates */ return exitstatus; diff --git a/external/sh/exec.c b/external/sh/exec.c index 51ece8df..4b18c57f 100644 --- a/external/sh/exec.c +++ b/external/sh/exec.c @@ -36,7 +36,7 @@ static char sccsid[] = "@(#)exec.c 8.4 (Berkeley) 6/8/95"; #endif #endif /* not lint */ #include <sys/cdefs.h> -__FBSDID("$FreeBSD: head/bin/sh/exec.c 314436 2017-02-28 23:42:47Z imp $"); +__FBSDID("$FreeBSD: head/bin/sh/exec.c 317882 2017-05-06 13:28:42Z jilles $"); #include <sys/types.h> #include <sys/stat.h> @@ -338,7 +338,7 @@ find_command(const char *name, struct cmdentry *entry, int act, cd = 0; - /* If name is in the table, and not invalidated by cd, we're done */ + /* If name is in the table, we're done */ if ((cmdp = cmdlookup(name, 0)) != NULL) { if (cmdp->cmdtype == CMDFUNCTION && act & DO_NOFUNC) cmdp = NULL; @@ -485,8 +485,7 @@ changepath(const char *newval __unused) /* - * Clear out command entries. The argument specifies the first entry in - * PATH which has changed. + * Clear out cached utility locations. */ void diff --git a/external/sh/expand.c b/external/sh/expand.c index 78a34d2d..5884230c 100644 --- a/external/sh/expand.c +++ b/external/sh/expand.c @@ -40,7 +40,7 @@ static char sccsid[] = "@(#)expand.c 8.5 (Berkeley) 5/15/95"; #endif #endif /* not lint */ #include <sys/cdefs.h> -__FBSDID("$FreeBSD: head/bin/sh/expand.c 315005 2017-03-10 16:04:00Z jilles $"); +__FBSDID("$FreeBSD: head/bin/sh/expand.c 317882 2017-05-06 13:28:42Z jilles $"); #include <sys/types.h> #include <sys/time.h> @@ -89,15 +89,19 @@ struct worddest { }; static char *expdest; /* output of current string */ -static struct nodelist *argbackq; /* list of back quote expressions */ -static const char *argstr(const char *, int, struct worddest *); +static const char *argstr(const char *, struct nodelist **restrict, int, + struct worddest *); static const char *exptilde(const char *, int); -static const char *expari(const char *, int, struct worddest *); +static const char *expari(const char *, struct nodelist **restrict, int, + struct worddest *); static void expbackq(union node *, int, int, struct worddest *); -static void subevalvar_trim(const char *, int, int, int); -static int subevalvar_misc(const char *, const char *, int, int, int); -static const char *evalvar(const char *, int, struct worddest *); +static const char *subevalvar_trim(const char *, struct nodelist **restrict, + int, int, int); +static const char *subevalvar_misc(const char *, struct nodelist **restrict, + const char *, int, int, int); +static const char *evalvar(const char *, struct nodelist **restrict, int, + struct worddest *); static int varisset(const char *, int); static void strtodest(const char *, int, int, int, struct worddest *); static void reprocess(int, int, int, int, struct worddest *); @@ -141,10 +145,12 @@ appendarglist(struct arglist *list, char *str) static int collate_range_cmp(wchar_t c1, wchar_t c2) { - static wchar_t s1[2], s2[2]; + wchar_t s1[2], s2[2]; s1[0] = c1; + s1[1] = L'\0'; s2[0] = c2; + s2[1] = L'\0'; return (wcscoll(s1, s2)); } @@ -216,14 +222,15 @@ stputs_split(const char *data, const char *syntax, int flag, char *p, * The result is left in the stack string. * When arglist is NULL, perform here document expansion. * - * Caution: this function uses global state and is not reentrant. - * However, a new invocation after an interrupted invocation is safe - * and will reset the global state for the new call. + * When doing something that may cause this to be re-entered, make sure + * the stack string is empty via grabstackstr() and do not assume expdest + * remains valid. */ void expandarg(union node *arg, struct arglist *arglist, int flag) { struct worddest exparg; + struct nodelist *argbackq; if (fflag) flag &= ~EXP_GLOB; @@ -231,7 +238,7 @@ expandarg(union node *arg, struct arglist *arglist, int flag) exparg.list = arglist; exparg.state = WORD_IDLE; STARTSTACKSTR(expdest); - argstr(arg->narg.text, flag, &exparg); + argstr(arg->narg.text, &argbackq, flag, &exparg); if (arglist == NULL) { STACKSTRNUL(expdest); return; /* here document expanded */ @@ -263,7 +270,8 @@ expandarg(union node *arg, struct arglist *arglist, int flag) * If EXP_SPLIT is set, dst receives any complete words produced. */ static const char * -argstr(const char *p, int flag, struct worddest *dst) +argstr(const char *p, struct nodelist **restrict argbackq, int flag, + struct worddest *dst) { char c; int quotes = flag & (EXP_GLOB | EXP_CASE); /* do CTLESC */ @@ -308,15 +316,15 @@ argstr(const char *p, int flag, struct worddest *dst) USTPUTC(c, expdest); break; case CTLVAR: - p = evalvar(p, flag, dst); + p = evalvar(p, argbackq, flag, dst); break; case CTLBACKQ: case CTLBACKQ|CTLQUOTE: - expbackq(argbackq->n, c & CTLQUOTE, flag, dst); - argbackq = argbackq->next; + expbackq((*argbackq)->n, c & CTLQUOTE, flag, dst); + *argbackq = (*argbackq)->next; break; case CTLARI: - p = expari(p, flag, dst); + p = expari(p, argbackq, flag, dst); break; case ':': case '=': @@ -405,7 +413,8 @@ exptilde(const char *p, int flag) * Expand arithmetic expression. */ static const char * -expari(const char *p, int flag, struct worddest *dst) +expari(const char *p, struct nodelist **restrict argbackq, int flag, + struct worddest *dst) { char *q, *start; arith_t result; @@ -415,7 +424,7 @@ expari(const char *p, int flag, struct worddest *dst) quoted = *p++ == '"'; begoff = expdest - stackblock(); - p = argstr(p, 0, NULL); + p = argstr(p, argbackq, 0, NULL); STPUTC('\0', expdest); start = stackblock() + begoff; @@ -448,26 +457,26 @@ expbackq(union node *cmd, int quoted, int flag, struct worddest *dst) char buf[128]; char *p; char *dest = expdest; - struct nodelist *saveargbackq; char lastc; char const *syntax = quoted? DQSYNTAX : BASESYNTAX; int quotes = flag & (EXP_GLOB | EXP_CASE); size_t nnl; const char *ifs; + int startloc; INTOFF; - saveargbackq = argbackq; p = grabstackstr(dest); evalbackcmd(cmd, &in); ungrabstackstr(p, dest); p = in.buf; + startloc = dest - stackblock(); nnl = 0; if (!quoted && flag & EXP_SPLIT) ifs = ifsset() ? ifsval() : " \t\n"; else ifs = ""; - /* Don't copy trailing newlines */ + /* Remove trailing newlines */ for (;;) { if (--in.nleft < 0) { if (in.fd < 0) @@ -483,31 +492,24 @@ expbackq(union node *cmd, int quoted, int flag, struct worddest *dst) lastc = *p++; if (lastc == '\0') continue; - if (lastc == '\n') { - nnl++; - } else { - if (nnl > 0) { - if (strchr(ifs, '\n') != NULL) { - NEXTWORD('\n', flag, dest, dst); - nnl = 0; - } else { - CHECKSTRSPACE(nnl + 2, dest); - while (nnl > 0) { - nnl--; - USTPUTC('\n', dest); - } - } - } - if (strchr(ifs, lastc) != NULL) + if (nnl > 0 && lastc != '\n') { + NEXTWORD('\n', flag, dest, dst); + nnl = 0; + } + if (strchr(ifs, lastc) != NULL) { + if (lastc == '\n') + nnl++; + else NEXTWORD(lastc, flag, dest, dst); - else { - CHECKSTRSPACE(2, dest); - if (quotes && syntax[(int)lastc] == CCTL) - USTPUTC(CTLESC, dest); - USTPUTC(lastc, dest); - } + } else { + CHECKSTRSPACE(2, dest); + if (quotes && syntax[(int)lastc] == CCTL) + USTPUTC(CTLESC, dest); + USTPUTC(lastc, dest); } } + while (dest > stackblock() + startloc && STTOPC(dest) == '\n') + STUNPUTC(dest); if (in.fd >= 0) close(in.fd); @@ -518,11 +520,7 @@ expbackq(union node *cmd, int quoted, int flag, struct worddest *dst) exitstatus = waitforjob(in.jp, (int *)NULL); ungrabstackstr(p, dest); } - TRACE(("expbackq: size=%td: \"%.*s\"\n", - ((dest - stackblock()) - startloc), - (int)((dest - stackblock()) - startloc), - stackblock() + startloc)); - argbackq = saveargbackq; + TRACE(("expbackq: done\n")); expdest = dest; INTON; } @@ -540,19 +538,18 @@ recordleft(const char *str, const char *loc, char *startp) *startp++ = *loc++; } -static void -subevalvar_trim(const char *p, int strloc, int subtype, int startloc) +static const char * +subevalvar_trim(const char *p, struct nodelist **restrict argbackq, int strloc, + int subtype, int startloc) { char *startp; char *loc = NULL; char *str; int c = 0; - struct nodelist *saveargbackq = argbackq; int amount; - argstr(p, EXP_CASE | EXP_TILDE, NULL); + p = argstr(p, argbackq, EXP_CASE | EXP_TILDE, NULL); STACKSTRNUL(expdest); - argbackq = saveargbackq; startp = stackblock() + startloc; str = stackblock() + strloc; @@ -564,7 +561,7 @@ subevalvar_trim(const char *p, int strloc, int subtype, int startloc) if (patmatch(str, startp)) { *loc = c; recordleft(str, loc, startp); - return; + return p; } *loc = c; } @@ -577,7 +574,7 @@ subevalvar_trim(const char *p, int strloc, int subtype, int startloc) if (patmatch(str, startp)) { *loc = c; recordleft(str, loc, startp); - return; + return p; } *loc = c; loc--; @@ -589,7 +586,7 @@ subevalvar_trim(const char *p, int strloc, int subtype, int startloc) if (patmatch(str, loc)) { amount = loc - expdest; STADJUST(amount, expdest); - return; + return p; } loc--; } @@ -600,7 +597,7 @@ subevalvar_trim(const char *p, int strloc, int subtype, int startloc) if (patmatch(str, loc)) { amount = loc - expdest; STADJUST(amount, expdest); - return; + return p; } } break; @@ -611,20 +608,19 @@ subevalvar_trim(const char *p, int strloc, int subtype, int startloc) } amount = (expdest - stackblock() - strloc) + 1; STADJUST(-amount, expdest); + return p; } -static int -subevalvar_misc(const char *p, const char *var, int subtype, int startloc, - int varflags) +static const char * +subevalvar_misc(const char *p, struct nodelist **restrict argbackq, + const char *var, int subtype, int startloc, int varflags) { char *startp; - struct nodelist *saveargbackq = argbackq; int amount; - argstr(p, EXP_TILDE, NULL); + p = argstr(p, argbackq, EXP_TILDE, NULL); STACKSTRNUL(expdest); - argbackq = saveargbackq; startp = stackblock() + startloc; switch (subtype) { @@ -632,7 +628,7 @@ subevalvar_misc(const char *p, const char *var, int subtype, int startloc, setvar(var, startp, 0); amount = startp - expdest; STADJUST(amount, expdest); - return 1; + return p; case VSQUESTION: if (*p != CTLENDVAR) { @@ -641,7 +637,6 @@ subevalvar_misc(const char *p, const char *var, int subtype, int startloc, } error("%.*s: parameter %snot set", (int)(p - var - 1), var, (varflags & VSNUL) ? "null or " : ""); - return 0; default: abort(); @@ -655,7 +650,8 @@ subevalvar_misc(const char *p, const char *var, int subtype, int startloc, */ static const char * -evalvar(const char *p, int flag, struct worddest *dst) +evalvar(const char *p, struct nodelist **restrict argbackq, int flag, + struct worddest *dst) { int subtype; int varflags; @@ -677,7 +673,6 @@ evalvar(const char *p, int flag, struct worddest *dst) if (! is_name(*p)) special = 1; p = strchr(p, '=') + 1; -again: /* jump here after setting a variable with ${var=text} */ if (varflags & VSLINENO) { set = 1; special = 1; @@ -754,14 +749,14 @@ again: /* jump here after setting a variable with ${var=text} */ break; case VSNORMAL: - break; + return p; case VSPLUS: case VSMINUS: if (!set) { - argstr(p, flag | (flag & EXP_SPLIT ? EXP_SPLIT_LIT : 0) | + return argstr(p, argbackq, + flag | (flag & EXP_SPLIT ? EXP_SPLIT_LIT : 0) | (varflags & VSQUOTE ? EXP_LIT_QUOTED : 0), dst); - break; } break; @@ -769,31 +764,29 @@ again: /* jump here after setting a variable with ${var=text} */ case VSTRIMLEFTMAX: case VSTRIMRIGHT: case VSTRIMRIGHTMAX: - if (!set) { - set = 1; + if (!set) break; - } /* * Terminate the string and start recording the pattern * right after it */ STPUTC('\0', expdest); patloc = expdest - stackblock(); - subevalvar_trim(p, patloc, subtype, startloc); + p = subevalvar_trim(p, argbackq, patloc, subtype, startloc); reprocess(startloc, flag, VSNORMAL, varflags & VSQUOTE, dst); if (flag & EXP_SPLIT && *var == '@' && varflags & VSQUOTE) dst->state = WORD_QUOTEMARK; - break; + return p; case VSASSIGN: case VSQUESTION: if (!set) { - if (subevalvar_misc(p, var, subtype, startloc, - varflags)) { - varflags &= ~VSNUL; - goto again; - } - break; + p = subevalvar_misc(p, argbackq, var, subtype, + startloc, varflags); + /* assert(subtype == VSASSIGN); */ + val = lookupvar(var); + strtodest(val, flag, subtype, varflags & VSQUOTE, dst); + return p; } break; @@ -806,15 +799,14 @@ again: /* jump here after setting a variable with ${var=text} */ abort(); } - if (subtype != VSNORMAL) { /* skip to end of alternative */ + { /* skip to end of alternative */ int nesting = 1; for (;;) { if ((c = *p++) == CTLESC) p++; - else if (c == CTLBACKQ || c == (CTLBACKQ|CTLQUOTE)) { - if (set) - argbackq = argbackq->next; - } else if (c == CTLVAR) { + else if (c == CTLBACKQ || c == (CTLBACKQ|CTLQUOTE)) + *argbackq = (*argbackq)->next; + else if (c == CTLVAR) { if ((*p++ & VSTYPE) != VSNORMAL) nesting++; } else if (c == CTLENDVAR) { @@ -829,7 +821,7 @@ again: /* jump here after setting a variable with ${var=text} */ /* - * Test whether a specialized variable is set. + * Test whether a special or positional parameter is set. */ static int @@ -926,7 +918,7 @@ reprocess(int startloc, int flag, int subtype, int quoted, } /* - * Add the value of a specialized variable to the stack string. + * Add the value of a special or positional parameter to the stack string. */ static void @@ -1440,13 +1432,14 @@ int casematch(union node *pattern, const char *val) { struct stackmark smark; + struct nodelist *argbackq; int result; char *p; setstackmark(&smark); argbackq = pattern->narg.backquote; STARTSTACKSTR(expdest); - argstr(pattern->narg.text, EXP_TILDE | EXP_CASE, NULL); + argstr(pattern->narg.text, &argbackq, EXP_TILDE | EXP_CASE, NULL); STPUTC('\0', expdest); p = grabstackstr(expdest); result = patmatch(p, val); diff --git a/external/sh/miscbltin.c b/external/sh/miscbltin.c index ebbb0980..2e7a3a2b 100644 --- a/external/sh/miscbltin.c +++ b/external/sh/miscbltin.c @@ -36,7 +36,7 @@ static char sccsid[] = "@(#)miscbltin.c 8.4 (Berkeley) 5/4/95"; #endif #endif /* not lint */ #include <sys/cdefs.h> -__FBSDID("$FreeBSD: head/bin/sh/miscbltin.c 314436 2017-02-28 23:42:47Z imp $"); +__FBSDID("$FreeBSD: head/bin/sh/miscbltin.c 316744 2017-04-12 21:15:55Z jilles $"); /* * Miscellaneous builtins. @@ -367,7 +367,7 @@ struct limits { const char *name; const char *units; int cmd; - int factor; /* multiply by to get rlim_{cur,max} values */ + short factor; /* multiply by to get rlim_{cur,max} values */ char option; }; diff --git a/external/sh/options.c b/external/sh/options.c index d3222df0..81e48874 100644 --- a/external/sh/options.c +++ b/external/sh/options.c @@ -36,7 +36,7 @@ static char sccsid[] = "@(#)options.c 8.2 (Berkeley) 5/4/95"; #endif #endif /* not lint */ #include <sys/cdefs.h> -__FBSDID("$FreeBSD: head/bin/sh/options.c 314436 2017-02-28 23:42:47Z imp $"); +__FBSDID("$FreeBSD: head/bin/sh/options.c 317882 2017-05-06 13:28:42Z jilles $"); #include <signal.h> #include <unistd.h> @@ -131,7 +131,7 @@ procargs(int argc, char **argv) void optschanged(void) { - setinteractive(iflag); + setinteractive(); #ifndef NO_HISTORY histedit(); #endif @@ -141,6 +141,8 @@ optschanged(void) /* * Process shell options. The global variable argptr contains a pointer * to the argument list; we advance it past the options. + * If cmdline is true, process the shell's argv; otherwise, process arguments + * to the set special builtin. */ static void @@ -392,7 +394,7 @@ shiftcmd(int argc, char **argv) /* - * The set command builtin. + * The set builtin command. */ int @@ -558,7 +560,7 @@ out: /* * Standard option processing (a la getopt) for builtin routines. The * only argument that is passed to nextopt is the option string; the - * other arguments are unnecessary. It return the character, or '\0' on + * other arguments are unnecessary. It returns the option, or '\0' on * end of input. */ diff --git a/external/sh/printf.c b/external/sh/printf.c index 68985e0d..dea39695 100644 --- a/external/sh/printf.c +++ b/external/sh/printf.c @@ -46,7 +46,7 @@ static char const copyright[] = static char const sccsid[] = "@(#)printf.c 8.1 (Berkeley) 7/20/93"; #endif static const char rcsid[] = - "$FreeBSD: head/usr.bin/printf/printf.c 314436 2017-02-28 23:42:47Z imp $"; + "$FreeBSD: head/usr.bin/printf/printf.c 317598 2017-04-29 21:48:11Z jilles $"; #endif /* not lint */ #include <sys/types.h> @@ -70,20 +70,15 @@ static const char rcsid[] = #endif #define PF(f, func) do { \ - char *b = NULL; \ if (havewidth) \ if (haveprec) \ - (void)asprintf(&b, f, fieldwidth, precision, func); \ + (void)printf(f, fieldwidth, precision, func); \ else \ - (void)asprintf(&b, f, fieldwidth, func); \ + (void)printf(f, fieldwidth, func); \ else if (haveprec) \ - (void)asprintf(&b, f, precision, func); \ + (void)printf(f, precision, func); \ else \ - (void)asprintf(&b, f, func); \ - if (b) { \ - (void)fputs(b, stdout); \ - free(b); \ - } \ + (void)printf(f, func); \ } while (0) static int asciicode(void); @@ -394,7 +389,8 @@ printf_doformat(char *fmt, int *rval) char p; p = getchr(); - PF(start, p); + if (p != '\0') + PF(start, p); break; } case 's': { diff --git a/external/sh/trap.c b/external/sh/trap.c index 6523453e..a9499bfd 100644 --- a/external/sh/trap.c +++ b/external/sh/trap.c @@ -36,7 +36,7 @@ static char sccsid[] = "@(#)trap.c 8.5 (Berkeley) 6/5/95"; #endif #endif /* not lint */ #include <sys/cdefs.h> -__FBSDID("$FreeBSD: head/bin/sh/trap.c 314436 2017-02-28 23:42:47Z imp $"); +__FBSDID("$FreeBSD: head/bin/sh/trap.c 317298 2017-04-22 21:31:37Z jilles $"); #include <signal.h> #include <unistd.h> @@ -478,19 +478,14 @@ dotrap(void) /* - * Controls whether the shell is interactive or not. + * Controls whether the shell is interactive or not based on iflag. */ void -setinteractive(int on) +setinteractive(void) { - static int is_interactive = -1; - - if (on == is_interactive) - return; setsignal(SIGINT); setsignal(SIGQUIT); setsignal(SIGTERM); - is_interactive = on; } diff --git a/external/sh/trap.h b/external/sh/trap.h index dade9291..e4fa67ab 100644 --- a/external/sh/trap.h +++ b/external/sh/trap.h @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * @(#)trap.h 8.3 (Berkeley) 6/5/95 - * $FreeBSD: head/bin/sh/trap.h 314436 2017-02-28 23:42:47Z imp $ + * $FreeBSD: head/bin/sh/trap.h 317298 2017-04-22 21:31:37Z jilles $ */ extern volatile sig_atomic_t pendingsig; @@ -43,6 +43,6 @@ void ignoresig(int); int issigchldtrapped(void); void onsig(int); void dotrap(void); -void setinteractive(int); +void setinteractive(void); void exitshell(int) __dead2; void exitshell_savedstatus(void) __dead2; diff --git a/external/sh/var.c b/external/sh/var.c index 27d2edfd..9a293a2e 100644 --- a/external/sh/var.c +++ b/external/sh/var.c @@ -36,7 +36,7 @@ static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 5/4/95"; #endif #endif /* not lint */ #include <sys/cdefs.h> -__FBSDID("$FreeBSD: head/bin/sh/var.c 314436 2017-02-28 23:42:47Z imp $"); +__FBSDID("$FreeBSD: head/bin/sh/var.c 317912 2017-05-07 19:49:46Z jilles $"); #include <unistd.h> #include <stdlib.h> @@ -513,7 +513,7 @@ bltinunsetlocale(void) if (localevar(cmdenviron->args[i])) { setlocale(LC_ALL, ""); updatecharset(); - return; + break; } } INTON; |