From 254f12f71a85dc64a2552ac4af43a6bdb4a80b05 Mon Sep 17 00:00:00 2001 From: Apple Date: Wed, 21 Aug 2019 07:30:03 +0000 Subject: [PATCH] shell_cmds-207.11.1.tar.gz --- .gitignore | 5 +- alias/builtin.1 | 4 +- find/misc.c | 7 +- killall/killall.c | 10 +- locate/locate/com.apple.locate.plist | 6 +- locate/locate/updatedb.sh | 15 ++- nohup/nohup.c | 2 +- sh/Makefile | 13 +- sh/Makefile.depend | 3 +- sh/TOUR | 79 ++++++----- sh/alias.c | 49 ++++--- sh/alias.h | 4 +- sh/arith.h | 5 +- sh/bltin/bltin.h | 6 +- sh/bltin/echo.c | 6 +- sh/builtins.def | 33 ++--- sh/cd.c | 15 ++- sh/cd.h | 4 +- sh/error.c | 4 +- sh/error.h | 6 +- sh/eval.c | 29 ++--- sh/eval.h | 4 +- sh/exec.c | 10 +- sh/exec.h | 4 +- sh/expand.c | 187 ++++++++++++++------------- sh/expand.h | 4 +- sh/funcs/cmv | 4 +- sh/funcs/dirs | 4 +- sh/funcs/login | 4 +- sh/funcs/newgrp | 4 +- sh/funcs/popd | 4 +- sh/funcs/pushd | 4 +- sh/funcs/suspend | 4 +- sh/histedit.c | 6 +- sh/input.c | 4 +- sh/input.h | 4 +- sh/jobs.c | 61 +++++++-- sh/jobs.h | 39 +----- sh/mail.c | 4 +- sh/mail.h | 6 +- sh/main.c | 6 +- sh/main.h | 6 +- sh/memalloc.c | 6 +- sh/memalloc.h | 6 +- sh/miscbltin.c | 8 +- sh/mkbuiltins | 50 ++++++- sh/mknodes.c | 6 +- sh/mksyntax.c | 6 +- sh/mktokens | 6 +- sh/myhistedit.h | 6 +- sh/mystring.c | 6 +- sh/mystring.h | 6 +- sh/nodes.c.pat | 4 +- sh/nodetypes | 4 +- sh/options.c | 23 ++-- sh/options.h | 6 +- sh/output.c | 35 +++-- sh/output.h | 10 +- sh/parser.c | 6 +- sh/parser.h | 6 +- sh/redir.c | 6 +- sh/redir.h | 6 +- sh/sh.1 | 15 ++- sh/shell.h | 6 +- sh/show.c | 6 +- sh/show.h | 6 +- sh/tests/Makefile | 3 +- sh/tests/builtins/Makefile | 6 +- sh/tests/builtins/case21.0 | 10 ++ sh/tests/builtins/case22.0 | 10 ++ sh/tests/builtins/cd10.0 | 6 + sh/tests/builtins/locale2.0 | 5 + sh/tests/builtins/var-assign.0 | 4 +- sh/tests/errors/Makefile | 3 +- sh/tests/errors/redirection-error8.0 | 5 + sh/tests/execution/Makefile | 3 +- sh/tests/execution/set-C1.0 | 12 ++ sh/tests/expansion/Makefile | 11 +- sh/tests/expansion/cmdsubst18.0 | 6 + sh/tests/expansion/cmdsubst19.0 | 5 + sh/tests/expansion/cmdsubst20.0 | 6 + sh/tests/expansion/cmdsubst21.0 | 6 + sh/tests/expansion/cmdsubst22.0 | 6 + sh/tests/expansion/cmdsubst23.0 | 5 + sh/tests/expansion/cmdsubst24.0 | 24 ++++ sh/tests/expansion/cmdsubst25.0 | 7 + sh/tests/expansion/cmdsubst26.0 | 6 + sh/tests/invocation/Makefile | 16 +++ sh/tests/invocation/Makefile.depend | 11 ++ sh/tests/invocation/sh-ac1.0 | 7 + sh/tests/invocation/sh-c-missing1.0 | 3 + sh/tests/invocation/sh-c1.0 | 4 + sh/tests/invocation/sh-ca1.0 | 7 + sh/tests/invocation/sh-fca1.0 | 7 + sh/tests/parser/Makefile | 5 +- sh/tests/parser/alias16.0 | 7 + sh/tests/parser/alias17.0 | 7 + sh/tests/parser/alias18.0 | 8 ++ sh/trap.c | 17 ++- sh/trap.h | 8 +- sh/var.c | 10 +- sh/var.h | 6 +- shell_cmds.xcodeproj/project.pbxproj | 80 +++++++++++- time/time.c | 23 +++- w/w.c | 2 +- 105 files changed, 864 insertions(+), 436 deletions(-) create mode 100644 sh/tests/builtins/case21.0 create mode 100644 sh/tests/builtins/case22.0 create mode 100644 sh/tests/builtins/cd10.0 create mode 100644 sh/tests/builtins/locale2.0 create mode 100644 sh/tests/errors/redirection-error8.0 create mode 100644 sh/tests/execution/set-C1.0 create mode 100644 sh/tests/expansion/cmdsubst18.0 create mode 100644 sh/tests/expansion/cmdsubst19.0 create mode 100644 sh/tests/expansion/cmdsubst20.0 create mode 100644 sh/tests/expansion/cmdsubst21.0 create mode 100644 sh/tests/expansion/cmdsubst22.0 create mode 100644 sh/tests/expansion/cmdsubst23.0 create mode 100644 sh/tests/expansion/cmdsubst24.0 create mode 100644 sh/tests/expansion/cmdsubst25.0 create mode 100644 sh/tests/expansion/cmdsubst26.0 create mode 100644 sh/tests/invocation/Makefile create mode 100644 sh/tests/invocation/Makefile.depend create mode 100644 sh/tests/invocation/sh-ac1.0 create mode 100644 sh/tests/invocation/sh-c-missing1.0 create mode 100644 sh/tests/invocation/sh-c1.0 create mode 100644 sh/tests/invocation/sh-ca1.0 create mode 100644 sh/tests/invocation/sh-fca1.0 create mode 100644 sh/tests/parser/alias16.0 create mode 100644 sh/tests/parser/alias17.0 create mode 100644 sh/tests/parser/alias18.0 diff --git a/.gitignore b/.gitignore index 9bce6af..9e7ce41 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ -xcuserdata +*~ +xcuserdata/ +build/ +project.xcworkspace/ diff --git a/alias/builtin.1 b/alias/builtin.1 index 562e855..0fae99a 100644 --- a/alias/builtin.1 +++ b/alias/builtin.1 @@ -307,6 +307,7 @@ but are implemented as scripts using a builtin command of the same name. .El .Sh SEE ALSO .Xr csh 1 , +.Xr dash 1 , .Xr echo 1 , .Xr false 1 , .Xr info 1 , @@ -320,7 +321,8 @@ but are implemented as scripts using a builtin command of the same name. .Xr test 1 , .Xr time 1 , .Xr true 1 , -.Xr which 1 +.Xr which 1 , +.Xr zsh 1 .Sh HISTORY The .Nm diff --git a/find/misc.c b/find/misc.c index d6b1123..a165c5e 100644 --- a/find/misc.c +++ b/find/misc.c @@ -101,9 +101,6 @@ queryuser(char *argv[]) (void)fprintf(stderr, "\n"); (void)fflush(stderr); } -#ifdef __APPLE__ - return (resp[0] == 'y'); -#else - return (rpmatch(resp) == 1); -#endif + + return (rpmatch(resp) == 1); } diff --git a/killall/killall.c b/killall/killall.c index cf2aabb..4ef96a9 100644 --- a/killall/killall.c +++ b/killall/killall.c @@ -333,8 +333,12 @@ main(int ac, char **av) miblen = 4; } - st = sysctl(mib, miblen, NULL, &size, NULL, 0); do { + st = sysctl(mib, miblen, NULL, &size, NULL, 0); + if (st == -1) + err(1, "could not sysctl(KERN_PROC)"); + if (!size) + errx(1, "could not get size from sysctl(KERN_PROC)"); size += size / 10; newprocs = realloc(procs, size); if (newprocs == 0) { @@ -380,11 +384,7 @@ main(int ac, char **av) continue; mib[0] = CTL_KERN; -#if defined(__APPLE__) && TARGET_OS_EMBEDDED mib[1] = KERN_PROCARGS2; -#else - mib[1] = KERN_PROCARGS; -#endif mib[2] = thispid; syssize = (size_t)argmax; diff --git a/locate/locate/com.apple.locate.plist b/locate/locate/com.apple.locate.plist index 98703ab..ceb9078 100644 --- a/locate/locate/com.apple.locate.plist +++ b/locate/locate/com.apple.locate.plist @@ -10,10 +10,8 @@ /usr/libexec/locate.updatedb - LowPriorityIO - - Nice - 5 + ProcessType + Background KeepAlive PathState diff --git a/locate/locate/updatedb.sh b/locate/locate/updatedb.sh index 3bbddea..2506f22 100644 --- a/locate/locate/updatedb.sh +++ b/locate/locate/updatedb.sh @@ -72,22 +72,27 @@ case X"$FILESYSTEMS" in excludes="! (" or="" for fstype in $FILESYSTEMS do - excludes="$excludes $or -fstype $fstype" - or="-or" + excludes="$excludes $or -fstype $fstype" + or="-or" done excludes="$excludes ) -prune" case X"$PRUNEPATHS" in X) ;; *) for path in $PRUNEPATHS - do + do excludes="$excludes -or -path $path -prune" - done;; + done;; esac +# Ignore the target of firmlinks +while read firmlink; do + excludes="$excludes -or -path $firmlink -prune" +done <<< "$(awk -F'\t' '{print "/System/Volumes/Data/" $2}' /usr/share/firmlinks)" + tmp=$TMPDIR/_updatedb$$ trap 'rm -f $tmp; rmdir $TMPDIR; exit' 0 1 2 3 5 10 15 - + # search locally # echo $find $SEARCHPATHS $excludes -or -print && exit if $find -s $SEARCHPATHS $excludes -or -print 2>/dev/null | diff --git a/nohup/nohup.c b/nohup/nohup.c index f77dce5..021361c 100644 --- a/nohup/nohup.c +++ b/nohup/nohup.c @@ -95,7 +95,7 @@ main(int argc, char *argv[]) (void)signal(SIGHUP, SIG_IGN); -#if defined(__APPLE__) && !TARGET_OS_EMBEDDED +#if defined(__APPLE__) && !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) if (_vprocmgr_detach_from_console(0) != NULL) err(EXIT_MISC, "can't detach from console"); #endif diff --git a/sh/Makefile b/sh/Makefile index 08fa278..8d08662 100644 --- a/sh/Makefile +++ b/sh/Makefile @@ -1,5 +1,5 @@ # @(#)Makefile 8.4 (Berkeley) 5/5/95 -# $FreeBSD: head/bin/sh/Makefile 301285 2016-06-03 19:25:41Z bdrewery $ +# $FreeBSD: head/bin/sh/Makefile 322515 2017-08-14 19:21:37Z ngie $ .include @@ -28,9 +28,9 @@ WARNS?= 2 WFORMAT=0 .PATH: ${.CURDIR}/bltin \ - ${.CURDIR}/../kill \ - ${.CURDIR}/../test \ - ${.CURDIR}/../../usr.bin/printf + ${.CURDIR:H}/kill \ + ${.CURDIR:H}/test \ + ${SRCTOP}/usr.bin/printf CLEANFILES+= mknodes mknodes.o \ mksyntax mksyntax.o @@ -64,8 +64,7 @@ syntax.c syntax.h: mksyntax token.h: mktokens sh ${.CURDIR}/mktokens -.if ${MK_TESTS} != "no" -SUBDIR+= tests -.endif +HAS_TESTS= +SUBDIR.${MK_TESTS}+= tests .include diff --git a/sh/Makefile.depend b/sh/Makefile.depend index e33ea1e..189c031 100644 --- a/sh/Makefile.depend +++ b/sh/Makefile.depend @@ -1,9 +1,8 @@ -# $FreeBSD: head/bin/sh/Makefile.depend 295989 2016-02-24 17:20:11Z bdrewery $ +# $FreeBSD: head/bin/sh/Makefile.depend 325188 2017-10-31 00:07:04Z bdrewery $ # Autogenerated - do NOT edit! DIRDEPS = \ gnu/lib/csu \ - gnu/lib/libgcc \ include \ include/xlocale \ lib/${CSU_DIR} \ diff --git a/sh/TOUR b/sh/TOUR index 6d180ed..82215f3 100644 --- a/sh/TOUR +++ b/sh/TOUR @@ -1,5 +1,5 @@ # @(#)TOUR 8.1 (Berkeley) 5/31/93 -# $FreeBSD: head/bin/sh/TOUR 253650 2013-07-25 15:08:41Z jilles $ +# $FreeBSD: head/bin/sh/TOUR 317882 2017-05-06 13:28:42Z jilles $ NOTE -- This is the original TOUR paper distributed with ash and does not represent the current state of the shell. It is provided anyway @@ -24,7 +24,7 @@ programs is: program input files generates ------- ----------- --------- - mkbuiltins builtins builtins.h builtins.c + mkbuiltins builtins.def builtins.h builtins.c mknodes nodetypes nodes.h nodes.c mksyntax - syntax.h syntax.c mktokens - token.h @@ -108,10 +108,12 @@ The text field of a NARG structure points to the text of the word. The text consists of ordinary characters and a number of special codes defined in parser.h. The special codes are: - CTLVAR Variable substitution - CTLENDVAR End of variable substitution + CTLVAR Parameter expansion + CTLENDVAR End of parameter expansion CTLBACKQ Command substitution CTLBACKQ|CTLQUOTE Command substitution inside double quotes + CTLARI Arithmetic expansion + CTLENDARI End of arithmetic expansion CTLESC Escape next character A variable substitution contains the following elements: @@ -130,18 +132,31 @@ stitution. The possible types are: VSQUESTION|VSNUL ${var:?text} VSASSIGN ${var=text} VSASSIGN|VSNUL ${var:=text} + VSTRIMLEFT ${var#text} + VSTRIMLEFTMAX ${var##text} + VSTRIMRIGHT ${var%text} + VSTRIMRIGHTMAX ${var%%text} + VSLENGTH ${#var} + VSERROR delayed error In addition, the type field will have the VSQUOTE flag set if the -variable is enclosed in double quotes. The name of the variable -comes next, terminated by an equals sign. If the type is not -VSNORMAL, then the text field in the substitution follows, ter- -minated by a CTLENDVAR byte. +variable is enclosed in double quotes and the VSLINENO flag if +LINENO is being expanded (the parameter name is the decimal line +number). The parameter's name comes next, terminated by an equals +sign. If the type is not VSNORMAL (including when it is VSLENGTH), +then the text field in the substitution follows, terminated by a +CTLENDVAR byte. + +The type VSERROR is used to allow parsing bad substitutions like +${var[7]} and generate an error when they are expanded. Commands in back quotes are parsed and stored in a linked list. The locations of these commands in the string are indicated by CTLBACKQ and CTLBACKQ+CTLQUOTE characters, depending upon whether the back quotes were enclosed in double quotes. +Arithmetic expansion starts with CTLARI and ends with CTLENDARI. + The character CTLESC escapes the next character, so that in case any of the CTL characters mentioned above appear in the input, they can be passed through transparently. CTLESC is also used to @@ -153,11 +168,11 @@ right. In the case of here documents which are not subject to variable and command substitution, the parser doesn't insert any CTLESC characters to begin with (so the contents of the text field can be written without any processing). Other here docu- -ments, and words which are not subject to splitting and file name -generation, have the CTLESC characters removed during the vari- -able and command substitution phase. Words which are subject to -splitting and file name generation have the CTLESC characters re- -moved as part of the file name phase. +ments, and words which are not subject to file name generation, +have the CTLESC characters removed during the variable and command +substitution phase. Words which are subject to file name +generation have the CTLESC characters removed as part of the file +name phase. EXECUTION: Command execution is handled by the following files: eval.c The top level routines. @@ -199,10 +214,10 @@ later.) The routine shellexec is the interface to the exec system call. -EXPAND.C: Arguments are processed in three passes. The first -(performed by the routine argstr) performs variable and command -substitution. The second (ifsbreakup) performs word splitting -and the third (expandmeta) performs file name generation. +EXPAND.C: As the routine argstr generates words by parameter +expansion, command substitution and arithmetic expansion, it +performs word splitting on the result. As each word is output, +the routine expandmeta performs file name generation (if enabled). VAR.C: Variables are stored in a hash table. Probably we should switch to extensible hashing. The variable name is stored in the @@ -221,8 +236,8 @@ BUILTIN COMMANDS: The procedures for handling these are scat- tered throughout the code, depending on which location appears most appropriate. They can be recognized because their names al- ways end in "cmd". The mapping from names to procedures is -specified in the file builtins, which is processed by the mkbuilt- -ins command. +specified in the file builtins.def, which is processed by the +mkbuiltins command. A builtin command is invoked with argc and argv set up like a normal program. A builtin command is allowed to overwrite its @@ -230,22 +245,20 @@ arguments. Builtin routines can call nextopt to do option pars- ing. This is kind of like getopt, but you don't pass argc and argv to it. Builtin routines can also call error. This routine normally terminates the shell (or returns to the main command -loop if the shell is interactive), but when called from a builtin -command it causes the builtin command to terminate with an exit -status of 2. +loop if the shell is interactive), but when called from a non- +special builtin command it causes the builtin command to +terminate with an exit status of 2. The directory bltins contains commands which can be compiled in- dependently but can also be built into the shell for efficiency -reasons. The makefile in this directory compiles these programs -in the normal fashion (so that they can be run regardless of -whether the invoker is ash), but also creates a library named -bltinlib.a which can be linked with ash. The header file bltin.h -takes care of most of the differences between the ash and the -stand-alone environment. The user should call the main routine -"main", and #define main to be the name of the routine to use -when the program is linked into ash. This #define should appear -before bltin.h is included; bltin.h will #undef main if the pro- -gram is to be compiled stand-alone. +reasons. The header file bltin.h takes care of most of the +differences between the ash and the stand-alone environment. +The user should call the main routine "main", and #define main to +be the name of the routine to use when the program is linked into +ash. This #define should appear before bltin.h is included; +bltin.h will #undef main if the program is to be compiled +stand-alone. A similar approach is used for a few utilities from +bin and usr.bin. CD.C: This file defines the cd and pwd builtins. @@ -258,7 +271,7 @@ is called at appropriate points to actually handle the signal. When an interrupt is caught and no trap has been set for that signal, the routine "onint" in error.c is called. -OUTPUT: Ash uses it's own output routines. There are three out- +OUTPUT: Ash uses its own output routines. There are three out- put structures allocated. "Output" represents the standard out- put, "errout" the standard error, and "memout" contains output which is to be stored in memory. This last is used when a buil- diff --git a/sh/alias.c b/sh/alias.c index 4eb6f9e..a8fe82c 100644 --- a/sh/alias.c +++ b/sh/alias.c @@ -13,7 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -36,7 +36,7 @@ static char sccsid[] = "@(#)alias.c 8.3 (Berkeley) 5/4/95"; #endif #endif /* not lint */ #include -__FBSDID("$FreeBSD: head/bin/sh/alias.c 295868 2016-02-21 20:58:24Z jilles $"); +__FBSDID("$FreeBSD: head/bin/sh/alias.c 317039 2017-04-16 22:10:02Z jilles $"); #include #include "shell.h" @@ -45,7 +45,7 @@ __FBSDID("$FreeBSD: head/bin/sh/alias.c 295868 2016-02-21 20:58:24Z jilles $"); #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/sh/alias.h b/sh/alias.h index 95a20ea..e08a9e8 100644 --- a/sh/alias.h +++ b/sh/alias.h @@ -13,7 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * @(#)alias.h 8.2 (Berkeley) 5/4/95 - * $FreeBSD: head/bin/sh/alias.h 223060 2011-06-13 21:03:27Z jilles $ + * $FreeBSD: head/bin/sh/alias.h 314436 2017-02-28 23:42:47Z imp $ */ #define ALIASINUSE 1 diff --git a/sh/arith.h b/sh/arith.h index 3771fe1..9c2ef39 100644 --- a/sh/arith.h +++ b/sh/arith.h @@ -10,7 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * @(#)arith.h 1.1 (Berkeley) 5/4/95 - * $FreeBSD: head/bin/sh/arith.h 223060 2011-06-13 21:03:27Z jilles $ + * $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/sh/bltin/bltin.h b/sh/bltin/bltin.h index b79cc43..b8c2087 100644 --- a/sh/bltin/bltin.h +++ b/sh/bltin/bltin.h @@ -1,4 +1,6 @@ /*- + * SPDX-License-Identifier: BSD-3-Clause + * * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * @@ -13,7 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -30,7 +32,7 @@ * SUCH DAMAGE. * * @(#)bltin.h 8.2 (Berkeley) 5/4/95 - * $FreeBSD: head/bin/sh/bltin/bltin.h 279503 2015-03-01 21:46:55Z jilles $ + * $FreeBSD: head/bin/sh/bltin/bltin.h 326025 2017-11-20 19:49:47Z pfg $ */ /* diff --git a/sh/bltin/echo.c b/sh/bltin/echo.c index 3de6589..1bb64c6 100644 --- a/sh/bltin/echo.c +++ b/sh/bltin/echo.c @@ -1,4 +1,6 @@ /*- + * SPDX-License-Identifier: BSD-3-Clause + * * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * @@ -13,7 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -33,7 +35,7 @@ */ #include -__FBSDID("$FreeBSD: head/bin/sh/bltin/echo.c 127958 2004-04-06 20:06:54Z markm $"); +__FBSDID("$FreeBSD: head/bin/sh/bltin/echo.c 326025 2017-11-20 19:49:47Z pfg $"); /* * Echo command. diff --git a/sh/builtins.def b/sh/builtins.def index dd113b6..39cab13 100644 --- a/sh/builtins.def +++ b/sh/builtins.def @@ -15,7 +15,7 @@ # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. -# 4. Neither the name of the University nor the names of its contributors +# 3. Neither the name of the University nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # @@ -32,7 +32,7 @@ # SUCH DAMAGE. # # @(#)builtins.def 8.4 (Berkeley) 5/4/95 -# $FreeBSD: head/bin/sh/builtins.def 288430 2015-09-30 21:32:29Z jilles $ +# $FreeBSD: head/bin/sh/builtins.def 319576 2017-06-04 21:02:48Z bdrewery $ # # This file lists all the builtin commands. The first column is the name @@ -41,6 +41,9 @@ # without job control. # The -h flag specifies that this command is to be excluded from systems # based on the NO_HISTORY compile-time symbol. +# The -n flag specifies that this command can safely be run in the same +# process when it is the only command in a command substitution. Some +# commands have special logic defined in safe_builtin(). # The -s flag specifies that this is a POSIX 'special built-in' command. # The rest of the line specifies the command name or names used to run the # command. The entry for bltincmd, which is run when the user does not specify @@ -48,43 +51,43 @@ # # NOTE: bltincmd must come first! -bltincmd builtin +bltincmd -n builtin aliascmd alias bgcmd -j bg bindcmd bind breakcmd -s break -s continue cdcmd cd chdir -commandcmd command +commandcmd -n command dotcmd -s . -echocmd echo +echocmd -n echo evalcmd -s eval execcmd -s exec exitcmd -s exit letcmd let exportcmd -s export -s readonly #exprcmd expr -falsecmd false +falsecmd -n false fgcmd -j fg freebsd_wordexpcmd freebsd_wordexp getoptscmd getopts hashcmd hash histcmd -h fc -jobidcmd jobid -jobscmd jobs -killcmd kill +jobidcmd -n jobid +jobscmd -n jobs +killcmd -n kill localcmd local -printfcmd printf -pwdcmd pwd +printfcmd -n printf +pwdcmd -n pwd readcmd read returncmd -s return setcmd -s set setvarcmd setvar shiftcmd -s shift -testcmd test [ -timescmd -s times +testcmd -n test [ +timescmd -n -s times trapcmd -s trap -truecmd -s : true -typecmd type +truecmd -n -s : true +typecmd -n type ulimitcmd ulimit umaskcmd umask unaliascmd unalias diff --git a/sh/cd.c b/sh/cd.c index 67a80bd..cf63681 100644 --- a/sh/cd.c +++ b/sh/cd.c @@ -13,7 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -36,7 +36,7 @@ static char sccsid[] = "@(#)cd.c 8.2 (Berkeley) 5/4/95"; #endif #endif /* not lint */ #include -__FBSDID("$FreeBSD: head/bin/sh/cd.c 294667 2016-01-24 17:01:34Z jilles $"); +__FBSDID("$FreeBSD: head/bin/sh/cd.c 320340 2017-06-25 21:53:08Z jilles $"); #include #include @@ -164,8 +164,17 @@ docd(char *dest, int print, int phys) if ((phys || (rc = cdlogical(dest)) < 0) && (rc = cdphysical(dest)) < 0) return (-1); - if (print && iflag && curdir) + if (print && iflag && curdir) { out1fmt("%s\n", curdir); + /* + * Ignore write errors to preserve the invariant that the + * current directory is changed iff the exit status is 0 + * (or 1 if -e was given and the full pathname could not be + * determined). + */ + flushout(out1); + outclearerror(out1); + } return (rc); } diff --git a/sh/cd.h b/sh/cd.h index 6a2c5d3..0745d97 100644 --- a/sh/cd.h +++ b/sh/cd.h @@ -10,7 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: head/bin/sh/cd.h 223060 2011-06-13 21:03:27Z jilles $ + * $FreeBSD: head/bin/sh/cd.h 314436 2017-02-28 23:42:47Z imp $ */ void pwd_init(int); diff --git a/sh/error.c b/sh/error.c index 65198dd..7f184ac 100644 --- a/sh/error.c +++ b/sh/error.c @@ -13,7 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -36,7 +36,7 @@ static char sccsid[] = "@(#)error.c 8.2 (Berkeley) 5/4/95"; #endif #endif /* not lint */ #include -__FBSDID("$FreeBSD: head/bin/sh/error.c 279569 2015-03-03 21:21:43Z jilles $"); +__FBSDID("$FreeBSD: head/bin/sh/error.c 314436 2017-02-28 23:42:47Z imp $"); /* * Errors and exceptions. diff --git a/sh/error.h b/sh/error.h index 4aa7f37..e962c4f 100644 --- a/sh/error.h +++ b/sh/error.h @@ -13,7 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * @(#)error.h 8.2 (Berkeley) 5/4/95 - * $FreeBSD: head/bin/sh/error.h 276038 2014-12-21 23:09:59Z jilles $ + * $FreeBSD: head/bin/sh/error.h 319591 2017-06-04 21:58:02Z jilles $ */ /* @@ -73,7 +73,7 @@ extern volatile sig_atomic_t intpending; #define INTOFF suppressint++ #define INTON { if (--suppressint == 0 && intpending) onint(); } #define is_int_on() suppressint -#define SETINTON(s) suppressint = (s) +#define SETINTON(s) do { suppressint = (s); if (suppressint == 0 && intpending) onint(); } while (0) #define FORCEINTON {suppressint = 0; if (intpending) onint();} #define SET_PENDING_INT intpending = 1 #define CLEAR_PENDING_INT intpending = 0 diff --git a/sh/eval.c b/sh/eval.c index 4184c06..bb5f3cc 100644 --- a/sh/eval.c +++ b/sh/eval.c @@ -13,7 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -36,14 +36,13 @@ static char sccsid[] = "@(#)eval.c 8.9 (Berkeley) 6/8/95"; #endif #endif /* not lint */ #include -__FBSDID("$FreeBSD: head/bin/sh/eval.c 293635 2016-01-10 16:31:28Z jilles $"); +__FBSDID("$FreeBSD: head/bin/sh/eval.c 327212 2017-12-26 16:23:18Z jilles $"); #include #include #include #include #include -#include /* For WIFSIGNALED(status) */ #include /* @@ -470,6 +469,7 @@ evalredir(union node *n, int flags) if (e == EXERROR || e == EXEXEC) { if (in_redirect) { exitstatus = 2; + FORCEINTON; return; } } @@ -799,11 +799,8 @@ xtracecommand(struct arglist *varlist, int argc, char **argv) static int safe_builtin(int idx, int argc, char **argv) { - if (idx == BLTINCMD || idx == COMMANDCMD || idx == ECHOCMD || - idx == FALSECMD || idx == JOBIDCMD || idx == JOBSCMD || - idx == KILLCMD || idx == PRINTFCMD || idx == PWDCMD || - idx == TESTCMD || idx == TIMESCMD || idx == TRUECMD || - idx == TYPECMD) + /* Generated from builtins.def. */ + if (safe_builtin_always(idx)) return (1); if (idx == EXPORTCMD || idx == TRAPCMD || idx == ULIMITCMD || idx == UMASKCMD) @@ -842,7 +839,7 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd) struct parsefile *savetopfile; volatile int e; char *lastarg; - int realstatus; + int signaled; int do_clearcmdentry; const char *path = pathval(); int i; @@ -1080,9 +1077,7 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd) #endif mode = (cmdentry.u.index == EXECCMD)? 0 : REDIR_PUSH; if (flags == EV_BACKCMD) { - memout.nleft = 0; memout.nextc = memout.buf; - memout.bufsize = 64; mode |= REDIR_BACKQ; } savecmdname = commandname; @@ -1134,8 +1129,12 @@ cmddone: exitshell(exitstatus); if (flags == EV_BACKCMD) { backcmd->buf = memout.buf; - backcmd->nleft = memout.nextc - memout.buf; + backcmd->nleft = memout.buf != NULL ? + memout.nextc - memout.buf : 0; memout.buf = NULL; + memout.nextc = NULL; + memout.bufend = NULL; + memout.bufsize = 64; } if (cmdentry.u.index != EXECCMD) popredir(); @@ -1163,9 +1162,9 @@ cmddone: parent: /* parent process gets here (if we forked) */ if (mode == FORK_FG) { /* argument to fork */ INTOFF; - exitstatus = waitforjob(jp, &realstatus); + exitstatus = waitforjob(jp, &signaled); INTON; - if (iflag && loopnest > 0 && WIFSIGNALED(realstatus)) { + if (iflag && loopnest > 0 && signaled) { evalskip = SKIPBREAK; skipcount = loopnest; } @@ -1222,7 +1221,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/sh/eval.h b/sh/eval.h index c1045e3..18b39f9 100644 --- a/sh/eval.h +++ b/sh/eval.h @@ -13,7 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * @(#)eval.h 8.2 (Berkeley) 5/4/95 - * $FreeBSD: head/bin/sh/eval.h 289159 2015-10-11 21:33:00Z jilles $ + * $FreeBSD: head/bin/sh/eval.h 314436 2017-02-28 23:42:47Z imp $ */ extern char *commandname; /* currently executing command */ diff --git a/sh/exec.c b/sh/exec.c index 6544d70..ae3cf6e 100644 --- a/sh/exec.c +++ b/sh/exec.c @@ -13,7 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -36,7 +36,7 @@ static char sccsid[] = "@(#)exec.c 8.4 (Berkeley) 6/8/95"; #endif #endif /* not lint */ #include -__FBSDID("$FreeBSD: head/bin/sh/exec.c 296813 2016-03-13 22:54:14Z jilles $"); +__FBSDID("$FreeBSD: head/bin/sh/exec.c 317882 2017-05-06 13:28:42Z jilles $"); #include #include @@ -75,6 +75,7 @@ __FBSDID("$FreeBSD: head/bin/sh/exec.c 296813 2016-03-13 22:54:14Z jilles $"); #include "jobs.h" #include "alias.h" + #ifdef __APPLE__ #define eaccess(path, mode) faccessat(AT_FDCWD, path, mode, AT_EACCESS) #endif /* __APPLE__ */ @@ -341,7 +342,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; @@ -488,8 +489,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/sh/exec.h b/sh/exec.h index 0bd6df3..352077f 100644 --- a/sh/exec.h +++ b/sh/exec.h @@ -13,7 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * @(#)exec.h 8.3 (Berkeley) 6/8/95 - * $FreeBSD: head/bin/sh/exec.h 238468 2012-07-15 10:19:43Z jilles $ + * $FreeBSD: head/bin/sh/exec.h 314436 2017-02-28 23:42:47Z imp $ */ /* values of cmdtype */ diff --git a/sh/expand.c b/sh/expand.c index d29237b..7a31c95 100644 --- a/sh/expand.c +++ b/sh/expand.c @@ -17,7 +17,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -40,7 +40,7 @@ static char sccsid[] = "@(#)expand.c 8.5 (Berkeley) 5/15/95"; #endif #endif /* not lint */ #include -__FBSDID("$FreeBSD: head/bin/sh/expand.c 303586 2016-07-31 13:11:34Z jilles $"); +__FBSDID("$FreeBSD: head/bin/sh/expand.c 318269 2017-05-14 13:14:19Z jilles $"); #include #include @@ -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; @@ -431,8 +440,15 @@ expari(const char *p, int flag, struct worddest *dst) fmtstr(expdest, DIGITS(result), ARITH_FORMAT_STR, result); adj = strlen(expdest); STADJUST(adj, expdest); - if (!quoted) - reprocess(expdest - adj - stackblock(), flag, VSNORMAL, 0, dst); + /* + * If this is quoted, a '-' must not indicate a range in [...]. + * If this is not quoted, splitting may occur. + */ + if (quoted ? + result < 0 && begoff > 1 && flag & (EXP_GLOB | EXP_CASE) : + flag & EXP_SPLIT) + reprocess(expdest - adj - stackblock(), flag, VSNORMAL, quoted, + dst); return p; } @@ -448,27 +464,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); - argbackq = saveargbackq; 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) @@ -484,42 +499,35 @@ 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); if (in.buf) ckfree(in.buf); - if (in.jp) + if (in.jp) { + p = grabstackstr(dest); exitstatus = waitforjob(in.jp, (int *)NULL); - TRACE(("expbackq: size=%td: \"%.*s\"\n", - ((dest - stackblock()) - startloc), - (int)((dest - stackblock()) - startloc), - stackblock() + startloc)); + ungrabstackstr(p, dest); + } + TRACE(("expbackq: done\n")); expdest = dest; INTON; } @@ -537,19 +545,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; @@ -561,7 +568,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; } @@ -574,7 +581,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--; @@ -586,7 +593,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--; } @@ -597,7 +604,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; @@ -608,20 +615,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) { @@ -629,7 +635,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) { @@ -638,7 +644,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(); @@ -652,7 +657,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; @@ -674,7 +680,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; @@ -751,14 +756,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; @@ -774,21 +779,21 @@ again: /* jump here after setting a variable with ${var=text} */ */ 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; @@ -801,15 +806,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) { @@ -824,7 +828,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 @@ -921,7 +925,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 @@ -1435,13 +1439,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/sh/expand.h b/sh/expand.h index 0de4c02..e959174 100644 --- a/sh/expand.h +++ b/sh/expand.h @@ -13,7 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * @(#)expand.h 8.2 (Berkeley) 5/4/95 - * $FreeBSD: head/bin/sh/expand.h 292994 2015-12-31 18:47:54Z jilles $ + * $FreeBSD: head/bin/sh/expand.h 314436 2017-02-28 23:42:47Z imp $ */ struct arglist { diff --git a/sh/funcs/cmv b/sh/funcs/cmv index 307e32f..01728ca 100644 --- a/sh/funcs/cmv +++ b/sh/funcs/cmv @@ -15,7 +15,7 @@ # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. -# 4. Neither the name of the University nor the names of its contributors +# 3. Neither the name of the University nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # @@ -32,7 +32,7 @@ # SUCH DAMAGE. # # @(#)cmv 8.2 (Berkeley) 5/4/95 -# $FreeBSD: head/bin/sh/funcs/cmv 139969 2005-01-10 08:39:26Z imp $ +# $FreeBSD: head/bin/sh/funcs/cmv 314436 2017-02-28 23:42:47Z imp $ # Conditional move--don't replace an existing file. diff --git a/sh/funcs/dirs b/sh/funcs/dirs index 2a1fba5..88c20f4 100644 --- a/sh/funcs/dirs +++ b/sh/funcs/dirs @@ -15,7 +15,7 @@ # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. -# 4. Neither the name of the University nor the names of its contributors +# 3. Neither the name of the University nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # @@ -32,7 +32,7 @@ # SUCH DAMAGE. # # @(#)dirs 8.2 (Berkeley) 5/4/95 -# $FreeBSD: head/bin/sh/funcs/dirs 139969 2005-01-10 08:39:26Z imp $ +# $FreeBSD: head/bin/sh/funcs/dirs 314436 2017-02-28 23:42:47Z imp $ # pushd, popd, and dirs --- written by Chris Bertin # Pixel Computer Inc. ...!wjh12!pixel!pixutl!chris diff --git a/sh/funcs/login b/sh/funcs/login index 9ca88ec..e3c1154 100644 --- a/sh/funcs/login +++ b/sh/funcs/login @@ -15,7 +15,7 @@ # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. -# 4. Neither the name of the University nor the names of its contributors +# 3. Neither the name of the University nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # @@ -32,7 +32,7 @@ # SUCH DAMAGE. # # @(#)login 8.2 (Berkeley) 5/4/95 -# $FreeBSD: head/bin/sh/funcs/login 139969 2005-01-10 08:39:26Z imp $ +# $FreeBSD: head/bin/sh/funcs/login 314436 2017-02-28 23:42:47Z imp $ # replaces the login builtin in the BSD shell login () exec login "$@" diff --git a/sh/funcs/newgrp b/sh/funcs/newgrp index b99c3fe..5f9f861 100644 --- a/sh/funcs/newgrp +++ b/sh/funcs/newgrp @@ -15,7 +15,7 @@ # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. -# 4. Neither the name of the University nor the names of its contributors +# 3. Neither the name of the University nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # @@ -32,6 +32,6 @@ # SUCH DAMAGE. # # @(#)newgrp 8.2 (Berkeley) 5/4/95 -# $FreeBSD: head/bin/sh/funcs/newgrp 139969 2005-01-10 08:39:26Z imp $ +# $FreeBSD: head/bin/sh/funcs/newgrp 314436 2017-02-28 23:42:47Z imp $ newgrp() exec newgrp "$@" diff --git a/sh/funcs/popd b/sh/funcs/popd index 9787800..7a46b4e 100644 --- a/sh/funcs/popd +++ b/sh/funcs/popd @@ -15,7 +15,7 @@ # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. -# 4. Neither the name of the University nor the names of its contributors +# 3. Neither the name of the University nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # @@ -32,7 +32,7 @@ # SUCH DAMAGE. # # @(#)popd 8.2 (Berkeley) 5/4/95 -# $FreeBSD: head/bin/sh/funcs/popd 139969 2005-01-10 08:39:26Z imp $ +# $FreeBSD: head/bin/sh/funcs/popd 314436 2017-02-28 23:42:47Z imp $ # pushd, popd, and dirs --- written by Chris Bertin # Pixel Computer Inc. ...!wjh12!pixel!pixutl!chris diff --git a/sh/funcs/pushd b/sh/funcs/pushd index 465dd31..8d4f10d 100644 --- a/sh/funcs/pushd +++ b/sh/funcs/pushd @@ -15,7 +15,7 @@ # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. -# 4. Neither the name of the University nor the names of its contributors +# 3. Neither the name of the University nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # @@ -32,7 +32,7 @@ # SUCH DAMAGE. # # @(#)pushd 8.2 (Berkeley) 5/4/95 -# $FreeBSD: head/bin/sh/funcs/pushd 139969 2005-01-10 08:39:26Z imp $ +# $FreeBSD: head/bin/sh/funcs/pushd 314436 2017-02-28 23:42:47Z imp $ # pushd, popd, and dirs --- written by Chris Bertin # Pixel Computer Inc. ...!wjh12!pixel!pixutl!chris diff --git a/sh/funcs/suspend b/sh/funcs/suspend index 2b0b51c..99d3109 100644 --- a/sh/funcs/suspend +++ b/sh/funcs/suspend @@ -13,7 +13,7 @@ # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. -# 4. Neither the name of the University nor the names of its contributors +# 3. Neither the name of the University nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # @@ -30,7 +30,7 @@ # SUCH DAMAGE. # # @(#)suspend 8.2 (Berkeley) 5/4/95 -# $FreeBSD: head/bin/sh/funcs/suspend 215268 2010-11-13 22:20:46Z jilles $ +# $FreeBSD: head/bin/sh/funcs/suspend 314436 2017-02-28 23:42:47Z imp $ suspend() { local - diff --git a/sh/histedit.c b/sh/histedit.c index e2017b0..f01cabd 100644 --- a/sh/histedit.c +++ b/sh/histedit.c @@ -13,7 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -36,7 +36,7 @@ static char sccsid[] = "@(#)histedit.c 8.2 (Berkeley) 5/4/95"; #endif #endif /* not lint */ #include -__FBSDID("$FreeBSD: head/bin/sh/histedit.c 296429 2016-03-06 17:24:02Z jilles $"); +__FBSDID("$FreeBSD: head/bin/sh/histedit.c 319635 2017-06-06 21:08:05Z jilles $"); #include #include @@ -376,10 +376,10 @@ histcmd(int argc, char **argv __unused) char *editcmd; fclose(efp); + INTON; editcmd = stalloc(strlen(editor) + strlen(editfile) + 2); sprintf(editcmd, "%s %s", editor, editfile); evalstring(editcmd, 0); /* XXX - should use no JC command */ - INTON; readcmdfile(editfile); /* XXX - should read back - quick tst */ unlink(editfile); } diff --git a/sh/input.c b/sh/input.c index 15edb67..53376f8 100644 --- a/sh/input.c +++ b/sh/input.c @@ -13,7 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -36,7 +36,7 @@ static char sccsid[] = "@(#)input.c 8.3 (Berkeley) 6/9/95"; #endif #endif /* not lint */ #include -__FBSDID("$FreeBSD: head/bin/sh/input.c 295937 2016-02-23 22:44:01Z jilles $"); +__FBSDID("$FreeBSD: head/bin/sh/input.c 314436 2017-02-28 23:42:47Z imp $"); #include /* defines BUFSIZ */ #include diff --git a/sh/input.h b/sh/input.h index 1c3ece9..5a47e4b 100644 --- a/sh/input.h +++ b/sh/input.h @@ -13,7 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * @(#)input.h 8.2 (Berkeley) 5/4/95 - * $FreeBSD: head/bin/sh/input.h 271593 2014-09-14 16:46:30Z jilles $ + * $FreeBSD: head/bin/sh/input.h 314436 2017-02-28 23:42:47Z imp $ */ /* PEOF (the end of file marker) is defined in syntax.h */ diff --git a/sh/jobs.c b/sh/jobs.c index 28baa0c..358153b 100644 --- a/sh/jobs.c +++ b/sh/jobs.c @@ -13,7 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -36,7 +36,7 @@ static char sccsid[] = "@(#)jobs.c 8.5 (Berkeley) 5/4/95"; #endif #endif /* not lint */ #include -__FBSDID("$FreeBSD: head/bin/sh/jobs.c 296326 2016-03-02 21:24:46Z jilles $"); +__FBSDID("$FreeBSD: head/bin/sh/jobs.c 328818 2018-02-02 22:53:58Z jilles $"); #include #include @@ -75,6 +75,42 @@ __FBSDID("$FreeBSD: head/bin/sh/jobs.c 296326 2016-03-02 21:24:46Z jilles $"); #include "builtins.h" +/* + * A job structure contains information about a job. A job is either a + * single process or a set of processes contained in a pipeline. In the + * latter case, pidlist will be non-NULL, and will point to a -1 terminated + * array of pids. + */ + +struct procstat { + pid_t pid; /* process id */ + int status; /* status flags (defined above) */ + char *cmd; /* text of command being run */ +}; + + +/* states */ +#define JOBSTOPPED 1 /* all procs are stopped */ +#define JOBDONE 2 /* all procs are completed */ + + +struct job { + struct procstat ps0; /* status of process */ + struct procstat *ps; /* status or processes when more than one */ + short nprocs; /* number of processes */ + pid_t pgrp; /* process group of this job */ + char state; /* true if job is finished */ + char used; /* true if this entry is in used */ + char changed; /* true if status has changed */ + char foreground; /* true if running in the foreground */ + char remembered; /* true if $! referenced */ +#if JOBS + char jobctl; /* job running under job control */ + struct job *next; /* job used after this one */ +#endif +}; + + static struct job *jobtab; /* array of jobs */ static int njobs; /* size of array */ static pid_t backgndpid = -1; /* pid of last background process */ @@ -326,7 +362,7 @@ showjob(struct job *jp, int mode) const char *statestr, *coredump; struct procstat *ps; struct job *j; - int col, curr, i, jobno, prev, procno; + int col, curr, i, jobno, prev, procno, status; char c; procno = (mode == SHOWJOBS_PGIDS) ? 1 : jp->nprocs; @@ -340,11 +376,12 @@ showjob(struct job *jp, int mode) } #endif coredump = ""; - ps = jp->ps + jp->nprocs - 1; + status = jp->ps[jp->nprocs - 1].status; if (jp->state == 0) { statestr = "Running"; #if JOBS } else if (jp->state == JOBSTOPPED) { + ps = jp->ps + jp->nprocs - 1; while (!WIFSTOPPED(ps->status) && ps > jp->ps) ps--; if (WIFSTOPPED(ps->status)) @@ -355,20 +392,20 @@ showjob(struct job *jp, int mode) if (statestr == NULL) statestr = "Suspended"; #endif - } else if (WIFEXITED(ps->status)) { - if (WEXITSTATUS(ps->status) == 0) + } else if (WIFEXITED(status)) { + if (WEXITSTATUS(status) == 0) statestr = "Done"; else { fmtstr(statebuf, sizeof(statebuf), "Done(%d)", - WEXITSTATUS(ps->status)); + WEXITSTATUS(status)); statestr = statebuf; } } else { - i = WTERMSIG(ps->status); + i = WTERMSIG(status); statestr = strsignal(i); if (statestr == NULL) statestr = "Unknown signal"; - if (WCOREDUMP(ps->status)) + if (WCOREDUMP(status)) coredump = " (core dumped)"; } @@ -1016,7 +1053,7 @@ vforkexecshell(struct job *jp, char **argv, char **envp, const char *path, int i */ int -waitforjob(struct job *jp, int *origstatus) +waitforjob(struct job *jp, int *signaled) { #if JOBS int propagate_int = jp->jobctl && jp->foreground; @@ -1039,8 +1076,8 @@ waitforjob(struct job *jp, int *origstatus) setcurjob(jp); #endif status = jp->ps[jp->nprocs - 1].status; - if (origstatus != NULL) - *origstatus = status; + if (signaled != NULL) + *signaled = WIFSIGNALED(status); /* convert to 8 bits */ if (WIFEXITED(status)) st = WEXITSTATUS(status); diff --git a/sh/jobs.h b/sh/jobs.h index f9978de..f6d90a8 100644 --- a/sh/jobs.h +++ b/sh/jobs.h @@ -13,7 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * @(#)jobs.h 8.2 (Berkeley) 5/4/95 - * $FreeBSD: head/bin/sh/jobs.h 255157 2013-09-02 21:57:46Z jilles $ + * $FreeBSD: head/bin/sh/jobs.h 327475 2018-01-01 22:31:52Z jilles $ */ /* Mode argument to forkshell. Don't change FORK_FG or FORK_BG. */ @@ -40,40 +40,7 @@ #include /* for sig_atomic_t */ -/* - * A job structure contains information about a job. A job is either a - * single process or a set of processes contained in a pipeline. In the - * latter case, pidlist will be non-NULL, and will point to a -1 terminated - * array of pids. - */ - -struct procstat { - pid_t pid; /* process id */ - int status; /* status flags (defined above) */ - char *cmd; /* text of command being run */ -}; - - -/* states */ -#define JOBSTOPPED 1 /* all procs are stopped */ -#define JOBDONE 2 /* all procs are completed */ - - -struct job { - struct procstat ps0; /* status of process */ - struct procstat *ps; /* status or processes when more than one */ - short nprocs; /* number of processes */ - pid_t pgrp; /* process group of this job */ - char state; /* true if job is finished */ - char used; /* true if this entry is in used */ - char changed; /* true if status has changed */ - char foreground; /* true if running in the foreground */ - char remembered; /* true if $! referenced */ -#if JOBS - char jobctl; /* job running under job control */ - struct job *next; /* job used after this one */ -#endif -}; +struct job; enum { SHOWJOBS_DEFAULT, /* job number, status, command */ diff --git a/sh/mail.c b/sh/mail.c index b6de32b..607b407 100644 --- a/sh/mail.c +++ b/sh/mail.c @@ -13,7 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -36,7 +36,7 @@ static char sccsid[] = "@(#)mail.c 8.2 (Berkeley) 5/4/95"; #endif #endif /* not lint */ #include -__FBSDID("$FreeBSD: head/bin/sh/mail.c 278820 2015-02-15 21:47:43Z jilles $"); +__FBSDID("$FreeBSD: head/bin/sh/mail.c 314436 2017-02-28 23:42:47Z imp $"); /* * Routines to check for mail. (Perhaps make part of main.c?) diff --git a/sh/mail.h b/sh/mail.h index fb5f908..509f11c 100644 --- a/sh/mail.h +++ b/sh/mail.h @@ -1,4 +1,6 @@ /*- + * SPDX-License-Identifier: BSD-3-Clause + * * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * @@ -13,7 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -30,7 +32,7 @@ * SUCH DAMAGE. * * @(#)mail.h 8.2 (Berkeley) 5/4/95 - * $FreeBSD: head/bin/sh/mail.h 127958 2004-04-06 20:06:54Z markm $ + * $FreeBSD: head/bin/sh/mail.h 326025 2017-11-20 19:49:47Z pfg $ */ void chkmail(int); diff --git a/sh/main.c b/sh/main.c index 452ed35..338f97c 100644 --- a/sh/main.c +++ b/sh/main.c @@ -1,4 +1,6 @@ /*- + * SPDX-License-Identifier: BSD-3-Clause + * * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * @@ -13,7 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -42,7 +44,7 @@ static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 5/28/95"; #endif #endif /* not lint */ #include -__FBSDID("$FreeBSD: head/bin/sh/main.c 265772 2014-05-09 13:27:30Z jilles $"); +__FBSDID("$FreeBSD: head/bin/sh/main.c 326025 2017-11-20 19:49:47Z pfg $"); #include #include diff --git a/sh/main.h b/sh/main.h index 1e1b499..ed160cd 100644 --- a/sh/main.h +++ b/sh/main.h @@ -1,4 +1,6 @@ /*- + * SPDX-License-Identifier: BSD-3-Clause + * * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * @@ -13,7 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -30,7 +32,7 @@ * SUCH DAMAGE. * * @(#)main.h 8.2 (Berkeley) 5/4/95 - * $FreeBSD: head/bin/sh/main.h 229220 2012-01-01 22:17:12Z jilles $ + * $FreeBSD: head/bin/sh/main.h 326025 2017-11-20 19:49:47Z pfg $ */ extern int rootpid; /* pid of main shell */ diff --git a/sh/memalloc.c b/sh/memalloc.c index 32e3838..7b5f325 100644 --- a/sh/memalloc.c +++ b/sh/memalloc.c @@ -1,4 +1,6 @@ /*- + * SPDX-License-Identifier: BSD-3-Clause + * * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * @@ -13,7 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -36,7 +38,7 @@ static char sccsid[] = "@(#)memalloc.c 8.3 (Berkeley) 5/4/95"; #endif #endif /* not lint */ #include -__FBSDID("$FreeBSD: head/bin/sh/memalloc.c 278818 2015-02-15 21:41:29Z jilles $"); +__FBSDID("$FreeBSD: head/bin/sh/memalloc.c 326025 2017-11-20 19:49:47Z pfg $"); #include #include "shell.h" diff --git a/sh/memalloc.h b/sh/memalloc.h index ee86a92..180abfd 100644 --- a/sh/memalloc.h +++ b/sh/memalloc.h @@ -1,4 +1,6 @@ /*- + * SPDX-License-Identifier: BSD-3-Clause + * * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * @@ -13,7 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -30,7 +32,7 @@ * SUCH DAMAGE. * * @(#)memalloc.h 8.2 (Berkeley) 5/4/95 - * $FreeBSD: head/bin/sh/memalloc.h 278818 2015-02-15 21:41:29Z jilles $ + * $FreeBSD: head/bin/sh/memalloc.h 326025 2017-11-20 19:49:47Z pfg $ */ #include diff --git a/sh/miscbltin.c b/sh/miscbltin.c index 1950ebc..52a810a 100644 --- a/sh/miscbltin.c +++ b/sh/miscbltin.c @@ -1,4 +1,6 @@ /*- + * SPDX-License-Identifier: BSD-3-Clause + * * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * @@ -13,7 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -36,7 +38,7 @@ static char sccsid[] = "@(#)miscbltin.c 8.4 (Berkeley) 5/4/95"; #endif #endif /* not lint */ #include -__FBSDID("$FreeBSD: head/bin/sh/miscbltin.c 301452 2016-06-05 16:09:31Z jilles $"); +__FBSDID("$FreeBSD: head/bin/sh/miscbltin.c 326025 2017-11-20 19:49:47Z pfg $"); /* * Miscellaneous builtins. @@ -367,7 +369,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/sh/mkbuiltins b/sh/mkbuiltins index dd0adc8..7c2cef1 100755 --- a/sh/mkbuiltins +++ b/sh/mkbuiltins @@ -15,7 +15,7 @@ # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. -# 4. Neither the name of the University nor the names of its contributors +# 3. Neither the name of the University nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # @@ -32,9 +32,9 @@ # SUCH DAMAGE. # # @(#)mkbuiltins 8.2 (Berkeley) 5/4/95 -# $FreeBSD: head/bin/sh/mkbuiltins 293118 2016-01-03 21:30:22Z jilles $ +# $FreeBSD: head/bin/sh/mkbuiltins 328934 2018-02-06 15:41:35Z arichardson $ -temp=`/usr/bin/mktemp -t ka` +temp=`mktemp -t ka` havehist=1 if [ "X$1" = "X-h" ]; then havehist=0 @@ -66,6 +66,9 @@ const unsigned char builtincmd[] = {' awk '{ for (i = 2 ; i <= NF ; i++) { if ($i == "-s") { spc = 1; + } else if ($i == "-n") { + # Handled later for builtins.h + continue } else { printf "\t\"\\%03o\\%03o%s\"\n", length($i), (spc ? 128 : 0) + NR-1, $i spc = 0; @@ -90,4 +93,45 @@ extern int (*const builtinfunc[])(int, char **); extern const unsigned char builtincmd[]; ' awk '{ printf "int %s(int, char **);\n", $1}' $temp + +# Build safe_builtin_always() +cat < -__FBSDID("$FreeBSD: head/bin/sh/mknodes.c 292517 2015-12-20 16:40:36Z jilles $"); +__FBSDID("$FreeBSD: head/bin/sh/mknodes.c 326025 2017-11-20 19:49:47Z pfg $"); /* * This program reads the nodetypes file and nodes.c.pat file. It generates diff --git a/sh/mksyntax.c b/sh/mksyntax.c index 8f9c8fd..52c5631 100644 --- a/sh/mksyntax.c +++ b/sh/mksyntax.c @@ -1,4 +1,6 @@ /*- + * SPDX-License-Identifier: BSD-3-Clause + * * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * @@ -13,7 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -42,7 +44,7 @@ static char sccsid[] = "@(#)mksyntax.c 8.2 (Berkeley) 5/4/95"; #endif /* not lint */ #endif #include -__FBSDID("$FreeBSD: head/bin/sh/mksyntax.c 279569 2015-03-03 21:21:43Z jilles $"); +__FBSDID("$FreeBSD: head/bin/sh/mksyntax.c 326025 2017-11-20 19:49:47Z pfg $"); /* * This program creates syntax.h and syntax.c. diff --git a/sh/mktokens b/sh/mktokens index 7dd8080..98bcc26 100644 --- a/sh/mktokens +++ b/sh/mktokens @@ -15,7 +15,7 @@ # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. -# 4. Neither the name of the University nor the names of its contributors +# 3. Neither the name of the University nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # @@ -32,13 +32,13 @@ # SUCH DAMAGE. # # @(#)mktokens 8.1 (Berkeley) 5/31/93 -# $FreeBSD: head/bin/sh/mktokens 279503 2015-03-01 21:46:55Z jilles $ +# $FreeBSD: head/bin/sh/mktokens 328934 2018-02-06 15:41:35Z arichardson $ # The following is a list of tokens. The second column is nonzero if the # token marks the end of a list. The third column is the name to print in # error messages. -temp=`/usr/bin/mktemp -t ka` +temp=`mktemp -t ka` cat > $temp <<\! TEOF 1 end of file TNL 0 newline diff --git a/sh/myhistedit.h b/sh/myhistedit.h index 1d21f46..3dbad7e 100644 --- a/sh/myhistedit.h +++ b/sh/myhistedit.h @@ -1,4 +1,6 @@ /*- + * SPDX-License-Identifier: BSD-3-Clause + * * Copyright (c) 1993 * The Regents of the University of California. All rights reserved. * @@ -10,7 +12,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -27,7 +29,7 @@ * SUCH DAMAGE. * * @(#)myhistedit.h 8.2 (Berkeley) 5/4/95 - * $FreeBSD: head/bin/sh/myhistedit.h 229220 2012-01-01 22:17:12Z jilles $ + * $FreeBSD: head/bin/sh/myhistedit.h 326025 2017-11-20 19:49:47Z pfg $ */ #include diff --git a/sh/mystring.c b/sh/mystring.c index 60349d7..7e17e23 100644 --- a/sh/mystring.c +++ b/sh/mystring.c @@ -1,4 +1,6 @@ /*- + * SPDX-License-Identifier: BSD-3-Clause + * * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * @@ -13,7 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -36,7 +38,7 @@ static char sccsid[] = "@(#)mystring.c 8.2 (Berkeley) 5/4/95"; #endif #endif /* not lint */ #include -__FBSDID("$FreeBSD: head/bin/sh/mystring.c 270102 2014-08-17 16:40:29Z jilles $"); +__FBSDID("$FreeBSD: head/bin/sh/mystring.c 326025 2017-11-20 19:49:47Z pfg $"); /* * String functions. diff --git a/sh/mystring.h b/sh/mystring.h index 3876bab..31d7891 100644 --- a/sh/mystring.h +++ b/sh/mystring.h @@ -1,4 +1,6 @@ /*- + * SPDX-License-Identifier: BSD-3-Clause + * * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * @@ -13,7 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -30,7 +32,7 @@ * SUCH DAMAGE. * * @(#)mystring.h 8.2 (Berkeley) 5/4/95 - * $FreeBSD: head/bin/sh/mystring.h 268920 2014-07-20 12:06:52Z jilles $ + * $FreeBSD: head/bin/sh/mystring.h 326025 2017-11-20 19:49:47Z pfg $ */ #include diff --git a/sh/nodes.c.pat b/sh/nodes.c.pat index d114d0e..29d1563 100644 --- a/sh/nodes.c.pat +++ b/sh/nodes.c.pat @@ -13,7 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * @(#)nodes.c.pat 8.2 (Berkeley) 5/4/95 - * $FreeBSD: head/bin/sh/nodes.c.pat 291267 2015-11-24 22:47:19Z jilles $ + * $FreeBSD: head/bin/sh/nodes.c.pat 314436 2017-02-28 23:42:47Z imp $ */ #include diff --git a/sh/nodetypes b/sh/nodetypes index 7fb3417..3ad95d6 100644 --- a/sh/nodetypes +++ b/sh/nodetypes @@ -13,7 +13,7 @@ # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. -# 4. Neither the name of the University nor the names of its contributors +# 3. Neither the name of the University nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # @@ -30,7 +30,7 @@ # SUCH DAMAGE. # # @(#)nodetypes 8.2 (Berkeley) 5/4/95 -# $FreeBSD: head/bin/sh/nodetypes 278820 2015-02-15 21:47:43Z jilles $ +# $FreeBSD: head/bin/sh/nodetypes 314436 2017-02-28 23:42:47Z imp $ # This file describes the nodes used in parse trees. Unindented lines # contain a node type followed by a structure tag. Subsequent indented diff --git a/sh/options.c b/sh/options.c index 25056b2..0628e73 100644 --- a/sh/options.c +++ b/sh/options.c @@ -1,4 +1,6 @@ /*- + * SPDX-License-Identifier: BSD-3-Clause + * * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * @@ -13,7 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -36,7 +38,7 @@ static char sccsid[] = "@(#)options.c 8.2 (Berkeley) 5/4/95"; #endif #endif /* not lint */ #include -__FBSDID("$FreeBSD: head/bin/sh/options.c 296577 2016-03-09 21:00:57Z jilles $"); +__FBSDID("$FreeBSD: head/bin/sh/options.c 326025 2017-11-20 19:49:47Z pfg $"); #include #include @@ -131,7 +133,7 @@ procargs(int argc, char **argv) void optschanged(void) { - setinteractive(iflag); + setinteractive(); #ifndef NO_HISTORY histedit(); #endif @@ -141,6 +143,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 @@ -189,16 +193,11 @@ options(int cmdline) while ((c = *p++) != '\0') { if (c == 'c' && cmdline) { char *q; -#ifdef NOHACK /* removing this code allows sh -ce 'foo' for compat */ - if (*p == '\0') -#endif - q = *argptr++; + + q = *argptr++; if (q == NULL || minusc != NULL) error("Bad -c option"); minusc = q; -#ifdef NOHACK - break; -#endif } else if (c == 'o') { minus_o(*argptr, val); if (*argptr) @@ -392,7 +391,7 @@ shiftcmd(int argc, char **argv) /* - * The set command builtin. + * The set builtin command. */ int @@ -558,7 +557,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/sh/options.h b/sh/options.h index 8910df9..233e9c6 100644 --- a/sh/options.h +++ b/sh/options.h @@ -1,4 +1,6 @@ /*- + * SPDX-License-Identifier: BSD-3-Clause + * * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * @@ -13,7 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -30,7 +32,7 @@ * SUCH DAMAGE. * * @(#)options.h 8.2 (Berkeley) 5/4/95 - * $FreeBSD: head/bin/sh/options.h 294348 2016-01-19 22:41:26Z jilles $ + * $FreeBSD: head/bin/sh/options.h 326025 2017-11-20 19:49:47Z pfg $ */ struct shparam { diff --git a/sh/output.c b/sh/output.c index 7718603..737eb91 100644 --- a/sh/output.c +++ b/sh/output.c @@ -1,4 +1,6 @@ /*- + * SPDX-License-Identifier: BSD-3-Clause + * * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * @@ -13,7 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -36,7 +38,7 @@ static char sccsid[] = "@(#)output.c 8.2 (Berkeley) 5/4/95"; #endif #endif /* not lint */ #include -__FBSDID("$FreeBSD: head/bin/sh/output.c 275766 2014-12-14 16:26:19Z jilles $"); +__FBSDID("$FreeBSD: head/bin/sh/output.c 326025 2017-11-20 19:49:47Z pfg $"); /* * Shell output routines. We use our own output routines because: @@ -71,9 +73,9 @@ __FBSDID("$FreeBSD: head/bin/sh/output.c 275766 2014-12-14 16:26:19Z jilles $"); static int doformat_wr(void *, const char *, int); -struct output output = {NULL, 0, NULL, OUTBUFSIZ, 1, 0}; -struct output errout = {NULL, 0, NULL, 256, 2, 0}; -struct output memout = {NULL, 0, NULL, 0, MEM_OUT, 0}; +struct output output = {NULL, NULL, NULL, OUTBUFSIZ, 1, 0}; +struct output errout = {NULL, NULL, NULL, 256, 2, 0}; +struct output memout = {NULL, NULL, NULL, 64, MEM_OUT, 0}; struct output *out1 = &output; struct output *out2 = &errout; @@ -208,26 +210,26 @@ outbin(const void *data, size_t len, struct output *file) void emptyoutbuf(struct output *dest) { - int offset; + int offset, newsize; if (dest->buf == NULL) { INTOFF; dest->buf = ckmalloc(dest->bufsize); dest->nextc = dest->buf; - dest->nleft = dest->bufsize; + dest->bufend = dest->buf + dest->bufsize; INTON; } else if (dest->fd == MEM_OUT) { - offset = dest->bufsize; + offset = dest->nextc - dest->buf; + newsize = dest->bufsize << 1; INTOFF; - dest->bufsize <<= 1; - dest->buf = ckrealloc(dest->buf, dest->bufsize); - dest->nleft = dest->bufsize - offset; + dest->buf = ckrealloc(dest->buf, newsize); + dest->bufsize = newsize; + dest->bufend = dest->buf + newsize; dest->nextc = dest->buf + offset; INTON; } else { flushout(dest); } - dest->nleft--; } @@ -248,20 +250,13 @@ flushout(struct output *dest) if (xwrite(dest->fd, dest->buf, dest->nextc - dest->buf) < 0) dest->flags |= OUTPUT_ERR; dest->nextc = dest->buf; - dest->nleft = dest->bufsize; } void freestdout(void) { - INTOFF; - if (output.buf) { - ckfree(output.buf); - output.buf = NULL; - output.nleft = 0; - } - INTON; + output.nextc = output.buf; } diff --git a/sh/output.h b/sh/output.h index 227db2d..652187a 100644 --- a/sh/output.h +++ b/sh/output.h @@ -1,4 +1,6 @@ /*- + * SPDX-License-Identifier: BSD-3-Clause + * * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * @@ -13,7 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -30,7 +32,7 @@ * SUCH DAMAGE. * * @(#)output.h 8.2 (Berkeley) 5/4/95 - * $FreeBSD: head/bin/sh/output.h 244162 2012-12-12 22:01:10Z jilles $ + * $FreeBSD: head/bin/sh/output.h 326025 2017-11-20 19:49:47Z pfg $ */ #ifndef OUTPUT_INCL @@ -40,7 +42,7 @@ struct output { char *nextc; - int nleft; + char *bufend; char *buf; int bufsize; short fd; @@ -75,7 +77,7 @@ void fmtstr(char *, int, const char *, ...) __printflike(3, 4); void doformat(struct output *, const char *, va_list) __printflike(2, 0); int xwrite(int, const char *, int); -#define outc(c, file) (--(file)->nleft < 0? (emptyoutbuf(file), *(file)->nextc++ = (c)) : (*(file)->nextc++ = (c))) +#define outc(c, file) ((file)->nextc == (file)->bufend ? (emptyoutbuf(file), *(file)->nextc++ = (c)) : (*(file)->nextc++ = (c))) #define out1c(c) outc(c, out1); #define out2c(c) outcslow(c, out2); diff --git a/sh/parser.c b/sh/parser.c index 3dc0d15..799e3b5 100644 --- a/sh/parser.c +++ b/sh/parser.c @@ -1,4 +1,6 @@ /*- + * SPDX-License-Identifier: BSD-3-Clause + * * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * @@ -13,7 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -36,7 +38,7 @@ static char sccsid[] = "@(#)parser.c 8.7 (Berkeley) 5/16/95"; #endif #endif /* not lint */ #include -__FBSDID("$FreeBSD: head/bin/sh/parser.c 301139 2016-06-01 16:56:29Z truckman $"); +__FBSDID("$FreeBSD: head/bin/sh/parser.c 326025 2017-11-20 19:49:47Z pfg $"); #include #include diff --git a/sh/parser.h b/sh/parser.h index 0a42f4e..210726b 100644 --- a/sh/parser.h +++ b/sh/parser.h @@ -1,4 +1,6 @@ /*- + * SPDX-License-Identifier: BSD-3-Clause + * * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * @@ -13,7 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -30,7 +32,7 @@ * SUCH DAMAGE. * * @(#)parser.h 8.3 (Berkeley) 5/4/95 - * $FreeBSD: head/bin/sh/parser.h 288430 2015-09-30 21:32:29Z jilles $ + * $FreeBSD: head/bin/sh/parser.h 326025 2017-11-20 19:49:47Z pfg $ */ /* control characters in argument strings */ diff --git a/sh/redir.c b/sh/redir.c index d0b4535..8f415a6 100644 --- a/sh/redir.c +++ b/sh/redir.c @@ -1,4 +1,6 @@ /*- + * SPDX-License-Identifier: BSD-3-Clause + * * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * @@ -13,7 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -36,7 +38,7 @@ static char sccsid[] = "@(#)redir.c 8.2 (Berkeley) 5/4/95"; #endif #endif /* not lint */ #include -__FBSDID("$FreeBSD: head/bin/sh/redir.c 295085 2016-01-30 21:21:25Z jilles $"); +__FBSDID("$FreeBSD: head/bin/sh/redir.c 326025 2017-11-20 19:49:47Z pfg $"); #include #include diff --git a/sh/redir.h b/sh/redir.h index 7146dd1..74d17b1 100644 --- a/sh/redir.h +++ b/sh/redir.h @@ -1,4 +1,6 @@ /*- + * SPDX-License-Identifier: BSD-3-Clause + * * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * @@ -13,7 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -30,7 +32,7 @@ * SUCH DAMAGE. * * @(#)redir.h 8.2 (Berkeley) 5/4/95 - * $FreeBSD: head/bin/sh/redir.h 254426 2013-08-16 20:24:41Z jilles $ + * $FreeBSD: head/bin/sh/redir.h 326025 2017-11-20 19:49:47Z pfg $ */ /* flags passed to redirect */ diff --git a/sh/sh.1 b/sh/sh.1 index cbfd925..5c2e87d 100644 --- a/sh/sh.1 +++ b/sh/sh.1 @@ -13,7 +13,7 @@ .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. -.\" 4. Neither the name of the University nor the names of its contributors +.\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" @@ -30,7 +30,7 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)sh.1 8.6 (Berkeley) 5/4/95 -.\" $FreeBSD: head/bin/sh/sh.1 306843 2016-10-08 13:40:12Z jilles $ +.\" $FreeBSD: head/bin/sh/sh.1 327121 2017-12-23 22:58:19Z jilles $ .\" .Dd October 8, 2016 .Dt SH 1 @@ -343,7 +343,7 @@ Write each command variable subjected to parameter expansion and arithmetic expansion) to standard error before it is executed. Useful for debugging. -.It nolog +.It Li nolog Another do-nothing option for .Tn POSIX compliance. @@ -1033,7 +1033,7 @@ The syntax of the command is: .Bd -unfilled -offset indent -compact .Ic case Ar word Ic in -.Ar pattern Ns Li ) Ar list Li ;; +.Ar pattern ) Ar list Li ;; .Ar ... .Ic esac .Ed @@ -2018,6 +2018,11 @@ to return exit status 1 if the full pathname of the new directory cannot be determined reliably or at all. Normally this is not considered an error, although a warning is printed. +.Pp +If changing the directory fails, the exit status is greater than 1. +If the directory is changed, the exit status is 0, or also 1 if +.Fl e +was given. .It Ic chdir A synonym for the .Ic cd @@ -2734,7 +2739,7 @@ were a known job that exited with exit status 127. If no operands are given, wait for all jobs to complete and return an exit status of zero. .El -.Ss Commandline Editing +.Ss Command Line Editing When .Nm is being used interactively from a terminal, the current command diff --git a/sh/shell.h b/sh/shell.h index add2bd8..1c7a766 100644 --- a/sh/shell.h +++ b/sh/shell.h @@ -1,4 +1,6 @@ /*- + * SPDX-License-Identifier: BSD-3-Clause + * * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * @@ -13,7 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -30,7 +32,7 @@ * SUCH DAMAGE. * * @(#)shell.h 8.2 (Berkeley) 5/4/95 - * $FreeBSD: head/bin/sh/shell.h 253658 2013-07-25 19:48:15Z jilles $ + * $FreeBSD: head/bin/sh/shell.h 326025 2017-11-20 19:49:47Z pfg $ */ #ifndef SHELL_H_ diff --git a/sh/show.c b/sh/show.c index 0e8cf43..9b55708 100644 --- a/sh/show.c +++ b/sh/show.c @@ -1,4 +1,6 @@ /*- + * SPDX-License-Identifier: BSD-3-Clause + * * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * @@ -13,7 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -36,7 +38,7 @@ static char sccsid[] = "@(#)show.c 8.3 (Berkeley) 5/4/95"; #endif #endif /* not lint */ #include -__FBSDID("$FreeBSD: head/bin/sh/show.c 258776 2013-11-30 21:27:11Z jilles $"); +__FBSDID("$FreeBSD: head/bin/sh/show.c 326025 2017-11-20 19:49:47Z pfg $"); #include #include diff --git a/sh/show.h b/sh/show.h index d9b1666..fc5ef76 100644 --- a/sh/show.h +++ b/sh/show.h @@ -1,4 +1,6 @@ /*- + * SPDX-License-Identifier: BSD-3-Clause + * * Copyright (c) 1995 * The Regents of the University of California. All rights reserved. * @@ -10,7 +12,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -27,7 +29,7 @@ * SUCH DAMAGE. * * @(#)show.h 1.1 (Berkeley) 5/4/95 - * $FreeBSD: head/bin/sh/show.h 200956 2009-12-24 18:41:14Z jilles $ + * $FreeBSD: head/bin/sh/show.h 326025 2017-11-20 19:49:47Z pfg $ */ void showtree(union node *); diff --git a/sh/tests/Makefile b/sh/tests/Makefile index 27932f2..b7d7b7d 100644 --- a/sh/tests/Makefile +++ b/sh/tests/Makefile @@ -1,4 +1,4 @@ -# $FreeBSD: head/bin/sh/tests/Makefile 299094 2016-05-04 23:20:53Z ngie $ +# $FreeBSD: head/bin/sh/tests/Makefile 322438 2017-08-12 19:17:48Z jilles $ .include @@ -6,6 +6,7 @@ TESTS_SUBDIRS+= builtins TESTS_SUBDIRS+= errors TESTS_SUBDIRS+= execution TESTS_SUBDIRS+= expansion +TESTS_SUBDIRS+= invocation TESTS_SUBDIRS+= parameters TESTS_SUBDIRS+= parser TESTS_SUBDIRS+= set-e diff --git a/sh/tests/builtins/Makefile b/sh/tests/builtins/Makefile index 0e6258f..98c3841 100644 --- a/sh/tests/builtins/Makefile +++ b/sh/tests/builtins/Makefile @@ -1,4 +1,4 @@ -# $FreeBSD: head/bin/sh/tests/builtins/Makefile 305305 2016-09-02 21:13:46Z jilles $ +# $FreeBSD: head/bin/sh/tests/builtins/Makefile 320340 2017-06-25 21:53:08Z jilles $ PACKAGE= tests @@ -40,6 +40,8 @@ ${PACKAGE}FILES+= case17.0 ${PACKAGE}FILES+= case18.0 ${PACKAGE}FILES+= case19.0 ${PACKAGE}FILES+= case20.0 +${PACKAGE}FILES+= case21.0 +${PACKAGE}FILES+= case22.0 ${PACKAGE}FILES+= cd1.0 ${PACKAGE}FILES+= cd2.0 ${PACKAGE}FILES+= cd3.0 @@ -49,6 +51,7 @@ ${PACKAGE}FILES+= cd6.0 ${PACKAGE}FILES+= cd7.0 ${PACKAGE}FILES+= cd8.0 ${PACKAGE}FILES+= cd9.0 cd9.0.stdout +${PACKAGE}FILES+= cd10.0 ${PACKAGE}FILES+= command1.0 ${PACKAGE}FILES+= command2.0 ${PACKAGE}FILES+= command3.0 @@ -120,6 +123,7 @@ ${PACKAGE}FILES+= local7.0 .if ${MK_NLS} != "no" ${PACKAGE}FILES+= locale1.0 .endif +${PACKAGE}FILES+= locale2.0 ${PACKAGE}FILES+= printf1.0 ${PACKAGE}FILES+= printf2.0 ${PACKAGE}FILES+= printf3.0 diff --git a/sh/tests/builtins/case21.0 b/sh/tests/builtins/case21.0 new file mode 100644 index 0000000..7d865f0 --- /dev/null +++ b/sh/tests/builtins/case21.0 @@ -0,0 +1,10 @@ +# $FreeBSD: head/bin/sh/tests/builtins/case21.0 318258 2017-05-13 20:28:32Z jilles $ + +case 5 in +[0$((-9))]) ;; +*) echo bad1 ;; +esac + +case - in +[0$((-9))]) echo bad2 ;; +esac diff --git a/sh/tests/builtins/case22.0 b/sh/tests/builtins/case22.0 new file mode 100644 index 0000000..a89c0bd --- /dev/null +++ b/sh/tests/builtins/case22.0 @@ -0,0 +1,10 @@ +# $FreeBSD: head/bin/sh/tests/builtins/case22.0 318269 2017-05-14 13:14:19Z jilles $ + +case 5 in +[0"$((-9))"]) echo bad1 ;; +esac + +case - in +[0"$((-9))"]) ;; +*) echo bad2 ;; +esac diff --git a/sh/tests/builtins/cd10.0 b/sh/tests/builtins/cd10.0 new file mode 100644 index 0000000..79d540f --- /dev/null +++ b/sh/tests/builtins/cd10.0 @@ -0,0 +1,6 @@ +# $FreeBSD: head/bin/sh/tests/builtins/cd10.0 320340 2017-06-25 21:53:08Z jilles $ + +# Precondition +(cd /bin) || exit +# Verify write error is ignored. +$SH +m -ic 'CDPATH=/:; cd bin 1/dev/null 2>&1 done -# For other built-ins and utilites they do not. +# For other built-ins and utilities they do not. set -- ${UTILS} for cmd in "$@" do diff --git a/sh/tests/errors/Makefile b/sh/tests/errors/Makefile index d690409..a234a05 100644 --- a/sh/tests/errors/Makefile +++ b/sh/tests/errors/Makefile @@ -1,4 +1,4 @@ -# $FreeBSD: head/bin/sh/tests/errors/Makefile 299094 2016-05-04 23:20:53Z ngie $ +# $FreeBSD: head/bin/sh/tests/errors/Makefile 319575 2017-06-04 20:52:55Z jilles $ PACKAGE= tests @@ -29,6 +29,7 @@ ${PACKAGE}FILES+= redirection-error4.0 ${PACKAGE}FILES+= redirection-error5.0 ${PACKAGE}FILES+= redirection-error6.0 ${PACKAGE}FILES+= redirection-error7.0 +${PACKAGE}FILES+= redirection-error8.0 ${PACKAGE}FILES+= write-error1.0 .include diff --git a/sh/tests/errors/redirection-error8.0 b/sh/tests/errors/redirection-error8.0 new file mode 100644 index 0000000..97364ac --- /dev/null +++ b/sh/tests/errors/redirection-error8.0 @@ -0,0 +1,5 @@ +# $FreeBSD: head/bin/sh/tests/errors/redirection-error8.0 319575 2017-06-04 20:52:55Z jilles $ + +$SH -c '{ { :; } /dev/null || kill -INT $$; echo continued' +r=$? +[ "$r" -gt 128 ] && [ "$(kill -l "$r")" = INT ] diff --git a/sh/tests/execution/Makefile b/sh/tests/execution/Makefile index b3e99ee..6e80719 100644 --- a/sh/tests/execution/Makefile +++ b/sh/tests/execution/Makefile @@ -1,4 +1,4 @@ -# $FreeBSD: head/bin/sh/tests/execution/Makefile 299094 2016-05-04 23:20:53Z ngie $ +# $FreeBSD: head/bin/sh/tests/execution/Makefile 308229 2016-11-02 22:33:37Z jilles $ PACKAGE= tests @@ -37,6 +37,7 @@ ${PACKAGE}FILES+= redir4.0 ${PACKAGE}FILES+= redir5.0 ${PACKAGE}FILES+= redir6.0 ${PACKAGE}FILES+= redir7.0 +${PACKAGE}FILES+= set-C1.0 ${PACKAGE}FILES+= set-n1.0 ${PACKAGE}FILES+= set-n2.0 ${PACKAGE}FILES+= set-n3.0 diff --git a/sh/tests/execution/set-C1.0 b/sh/tests/execution/set-C1.0 new file mode 100644 index 0000000..b7d5a4c --- /dev/null +++ b/sh/tests/execution/set-C1.0 @@ -0,0 +1,12 @@ +# $FreeBSD: head/bin/sh/tests/execution/set-C1.0 308229 2016-11-02 22:33:37Z jilles $ + +T=$(mktemp -d "${TMPDIR:-/tmp}/sh-test.XXXXXXXX") || exit +trap 'rm -rf "$T"' 0 + +set -C +echo . >"$T/a" && +[ -s "$T/a" ] && +{ ! true >"$T/a"; } 2>/dev/null && +[ -s "$T/a" ] && +ln -s /dev/null "$T/b" && +true >"$T/b" diff --git a/sh/tests/expansion/Makefile b/sh/tests/expansion/Makefile index 734d4f3..1c44a55 100644 --- a/sh/tests/expansion/Makefile +++ b/sh/tests/expansion/Makefile @@ -1,4 +1,4 @@ -# $FreeBSD: head/bin/sh/tests/expansion/Makefile 302937 2016-07-16 13:26:18Z ache $ +# $FreeBSD: head/bin/sh/tests/expansion/Makefile 317514 2017-04-27 18:52:18Z jilles $ PACKAGE= tests @@ -39,6 +39,15 @@ ${PACKAGE}FILES+= cmdsubst14.0 ${PACKAGE}FILES+= cmdsubst15.0 ${PACKAGE}FILES+= cmdsubst16.0 ${PACKAGE}FILES+= cmdsubst17.0 +${PACKAGE}FILES+= cmdsubst18.0 +${PACKAGE}FILES+= cmdsubst19.0 +${PACKAGE}FILES+= cmdsubst20.0 +${PACKAGE}FILES+= cmdsubst21.0 +${PACKAGE}FILES+= cmdsubst22.0 +${PACKAGE}FILES+= cmdsubst23.0 +${PACKAGE}FILES+= cmdsubst24.0 +${PACKAGE}FILES+= cmdsubst25.0 +${PACKAGE}FILES+= cmdsubst26.0 ${PACKAGE}FILES+= export1.0 ${PACKAGE}FILES+= export2.0 ${PACKAGE}FILES+= export3.0 diff --git a/sh/tests/expansion/cmdsubst18.0 b/sh/tests/expansion/cmdsubst18.0 new file mode 100644 index 0000000..2c3a1be --- /dev/null +++ b/sh/tests/expansion/cmdsubst18.0 @@ -0,0 +1,6 @@ +# $FreeBSD: head/bin/sh/tests/expansion/cmdsubst18.0 314637 2017-03-03 22:46:20Z jilles $ + +x=X +unset n +r=${x+$(echo a)}${x-$(echo b)}${n+$(echo c)}${n-$(echo d)}$(echo e) +[ "$r" = aXde ] diff --git a/sh/tests/expansion/cmdsubst19.0 b/sh/tests/expansion/cmdsubst19.0 new file mode 100644 index 0000000..7813c88 --- /dev/null +++ b/sh/tests/expansion/cmdsubst19.0 @@ -0,0 +1,5 @@ +# $FreeBSD: head/bin/sh/tests/expansion/cmdsubst19.0 314637 2017-03-03 22:46:20Z jilles $ + +b=200 c=30 d=5 x=4 +r=$(echo a)$(($(echo b) + ${x+$(echo c)} + ${x-$(echo d)}))$(echo e) +[ "$r" = a234e ] diff --git a/sh/tests/expansion/cmdsubst20.0 b/sh/tests/expansion/cmdsubst20.0 new file mode 100644 index 0000000..a92eaac --- /dev/null +++ b/sh/tests/expansion/cmdsubst20.0 @@ -0,0 +1,6 @@ +# $FreeBSD: head/bin/sh/tests/expansion/cmdsubst20.0 314637 2017-03-03 22:46:20Z jilles $ + +set -T +trapped='' +trap "trapped=x$trapped" USR1 +[ "x$(kill -USR1 $$)y" = xy ] && [ "$trapped" = x ] diff --git a/sh/tests/expansion/cmdsubst21.0 b/sh/tests/expansion/cmdsubst21.0 new file mode 100644 index 0000000..02f938f --- /dev/null +++ b/sh/tests/expansion/cmdsubst21.0 @@ -0,0 +1,6 @@ +# $FreeBSD: head/bin/sh/tests/expansion/cmdsubst21.0 314686 2017-03-04 22:58:34Z jilles $ + +set -T +trapped='' +trap "trapped=x$trapped" TERM +[ "x$($SH -c "kill $$")y" = xy ] && [ "$trapped" = x ] diff --git a/sh/tests/expansion/cmdsubst22.0 b/sh/tests/expansion/cmdsubst22.0 new file mode 100644 index 0000000..b33f6d5 --- /dev/null +++ b/sh/tests/expansion/cmdsubst22.0 @@ -0,0 +1,6 @@ +# $FreeBSD: head/bin/sh/tests/expansion/cmdsubst22.0 314686 2017-03-04 22:58:34Z jilles $ + +set -T +trapped='' +trap "trapped=x$trapped" TERM +[ "x$(:; kill $$)y" = xy ] && [ "$trapped" = x ] diff --git a/sh/tests/expansion/cmdsubst23.0 b/sh/tests/expansion/cmdsubst23.0 new file mode 100644 index 0000000..54b087e --- /dev/null +++ b/sh/tests/expansion/cmdsubst23.0 @@ -0,0 +1,5 @@ +# $FreeBSD: head/bin/sh/tests/expansion/cmdsubst23.0 315005 2017-03-10 16:04:00Z jilles $ + +unset n +x=abcd +[ "X${n#$(echo a)}X${x#$(echo ab)}X$(echo abc)X" = XXcdXabcX ] diff --git a/sh/tests/expansion/cmdsubst24.0 b/sh/tests/expansion/cmdsubst24.0 new file mode 100644 index 0000000..60da04a --- /dev/null +++ b/sh/tests/expansion/cmdsubst24.0 @@ -0,0 +1,24 @@ +# $FreeBSD: head/bin/sh/tests/expansion/cmdsubst24.0 317347 2017-04-23 21:58:17Z jilles $ +# POSIX leaves the effect of NUL bytes in command substitution output +# unspecified but we have always discarded them. + +failures=0 + +check() { + if [ "$2" != "$3" ]; then + printf "Failed at line %s: got \"%s\" expected \"%s\"\n" "$1" "$2" "$3" + : $((failures += 1)) + fi +} + +fmt='\0a\0 \0b\0c d\0' +assign_builtin=$(printf "$fmt") +check "$LINENO" "$assign_builtin" "a bc d" +assign_pipeline=$(printf "$fmt" | cat) +check "$LINENO" "$assign_pipeline" "a bc d" +set -- $(printf "$fmt") $(printf "$fmt" | cat) "$(printf "$fmt")" "$(printf "$fmt" | cat)" +IFS=@ +splits="$*" +check "$LINENO" "$splits" "a@bc@d@a@bc@d@a bc d@a bc d" + +[ "$failures" = 0 ] diff --git a/sh/tests/expansion/cmdsubst25.0 b/sh/tests/expansion/cmdsubst25.0 new file mode 100644 index 0000000..0654847 --- /dev/null +++ b/sh/tests/expansion/cmdsubst25.0 @@ -0,0 +1,7 @@ +# $FreeBSD: head/bin/sh/tests/expansion/cmdsubst25.0 317514 2017-04-27 18:52:18Z jilles $ + +IFS=' ' +set -- `printf '\n '` +IFS=: +[ "$*" = ' +' ] diff --git a/sh/tests/expansion/cmdsubst26.0 b/sh/tests/expansion/cmdsubst26.0 new file mode 100644 index 0000000..c0d600a --- /dev/null +++ b/sh/tests/expansion/cmdsubst26.0 @@ -0,0 +1,6 @@ +# $FreeBSD: head/bin/sh/tests/expansion/cmdsubst26.0 317514 2017-04-27 18:52:18Z jilles $ + +nl=' +' +v=$nl`printf '\n'` +[ "$v" = "$nl" ] diff --git a/sh/tests/invocation/Makefile b/sh/tests/invocation/Makefile new file mode 100644 index 0000000..473990b --- /dev/null +++ b/sh/tests/invocation/Makefile @@ -0,0 +1,16 @@ +# $FreeBSD: head/bin/sh/tests/invocation/Makefile 322455 2017-08-13 14:36:10Z jilles $ + +PACKAGE= tests + +TESTSDIR= ${TESTSBASE}/bin/sh/${.CURDIR:T} + +.PATH: ${.CURDIR:H} +ATF_TESTS_SH= functional_test + +${PACKAGE}FILES+= sh-ac1.0 +${PACKAGE}FILES+= sh-c-missing1.0 +${PACKAGE}FILES+= sh-c1.0 +${PACKAGE}FILES+= sh-ca1.0 +${PACKAGE}FILES+= sh-fca1.0 + +.include diff --git a/sh/tests/invocation/Makefile.depend b/sh/tests/invocation/Makefile.depend new file mode 100644 index 0000000..d01d96a --- /dev/null +++ b/sh/tests/invocation/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD: head/bin/sh/tests/invocation/Makefile.depend 325187 2017-10-31 00:04:07Z bdrewery $ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + + +.include + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/sh/tests/invocation/sh-ac1.0 b/sh/tests/invocation/sh-ac1.0 new file mode 100644 index 0000000..fa7bdac --- /dev/null +++ b/sh/tests/invocation/sh-ac1.0 @@ -0,0 +1,7 @@ +# $FreeBSD: head/bin/sh/tests/invocation/sh-ac1.0 322438 2017-08-12 19:17:48Z jilles $ +# Test that attached options before c are processed + +case `${SH} -ac 'echo $-:$0' moo` in +*a*:moo) true ;; +*) false ;; +esac diff --git a/sh/tests/invocation/sh-c-missing1.0 b/sh/tests/invocation/sh-c-missing1.0 new file mode 100644 index 0000000..8f6a850 --- /dev/null +++ b/sh/tests/invocation/sh-c-missing1.0 @@ -0,0 +1,3 @@ +# $FreeBSD: head/bin/sh/tests/invocation/sh-c-missing1.0 322455 2017-08-13 14:36:10Z jilles $ + +! echo echo bad | ${SH} -c 2>/dev/null diff --git a/sh/tests/invocation/sh-c1.0 b/sh/tests/invocation/sh-c1.0 new file mode 100644 index 0000000..6142225 --- /dev/null +++ b/sh/tests/invocation/sh-c1.0 @@ -0,0 +1,4 @@ +# $FreeBSD: head/bin/sh/tests/invocation/sh-c1.0 322438 2017-08-12 19:17:48Z jilles $ +# Test that -c executes command_string with the given name and arg + +${SH} -c 'echo $0 $@' moo foo | grep -qx -- "moo foo" diff --git a/sh/tests/invocation/sh-ca1.0 b/sh/tests/invocation/sh-ca1.0 new file mode 100644 index 0000000..c743a1e --- /dev/null +++ b/sh/tests/invocation/sh-ca1.0 @@ -0,0 +1,7 @@ +# $FreeBSD: head/bin/sh/tests/invocation/sh-ca1.0 322438 2017-08-12 19:17:48Z jilles $ +# Test that attached options after c are processed + +case `${SH} -ca 'echo $-:$0' moo` in +*a*:moo) true ;; +*) false ;; +esac diff --git a/sh/tests/invocation/sh-fca1.0 b/sh/tests/invocation/sh-fca1.0 new file mode 100644 index 0000000..f28b761 --- /dev/null +++ b/sh/tests/invocation/sh-fca1.0 @@ -0,0 +1,7 @@ +# $FreeBSD: head/bin/sh/tests/invocation/sh-fca1.0 322438 2017-08-12 19:17:48Z jilles $ +# Test that attached options before and after c are processed + +case `${SH} -fca 'echo $-:$-:$0:$@' foo -bar` in +*f*:*a*:foo:-bar) true ;; +*) false ;; +esac diff --git a/sh/tests/parser/Makefile b/sh/tests/parser/Makefile index 4a9c724..cd83a50 100644 --- a/sh/tests/parser/Makefile +++ b/sh/tests/parser/Makefile @@ -1,4 +1,4 @@ -# $FreeBSD: head/bin/sh/tests/parser/Makefile 299094 2016-05-04 23:20:53Z ngie $ +# $FreeBSD: head/bin/sh/tests/parser/Makefile 317039 2017-04-16 22:10:02Z jilles $ PACKAGE= tests @@ -22,6 +22,9 @@ ${PACKAGE}FILES+= alias12.0 ${PACKAGE}FILES+= alias13.0 ${PACKAGE}FILES+= alias14.0 ${PACKAGE}FILES+= alias15.0 alias15.0.stdout +${PACKAGE}FILES+= alias16.0 +${PACKAGE}FILES+= alias17.0 +${PACKAGE}FILES+= alias18.0 ${PACKAGE}FILES+= and-pipe-not.0 ${PACKAGE}FILES+= case1.0 ${PACKAGE}FILES+= case2.0 diff --git a/sh/tests/parser/alias16.0 b/sh/tests/parser/alias16.0 new file mode 100644 index 0000000..b551216 --- /dev/null +++ b/sh/tests/parser/alias16.0 @@ -0,0 +1,7 @@ +# $FreeBSD: head/bin/sh/tests/parser/alias16.0 316646 2017-04-08 21:57:59Z jilles $ + +v=1 +alias a='unalias a +v=2' +eval a +[ "$v" = 2 ] diff --git a/sh/tests/parser/alias17.0 b/sh/tests/parser/alias17.0 new file mode 100644 index 0000000..fd233ef --- /dev/null +++ b/sh/tests/parser/alias17.0 @@ -0,0 +1,7 @@ +# $FreeBSD: head/bin/sh/tests/parser/alias17.0 317037 2017-04-16 21:42:43Z jilles $ + +v=1 +alias a='unalias -a +v=2' +eval a +[ "$v" = 2 ] diff --git a/sh/tests/parser/alias18.0 b/sh/tests/parser/alias18.0 new file mode 100644 index 0000000..4b072e8 --- /dev/null +++ b/sh/tests/parser/alias18.0 @@ -0,0 +1,8 @@ +# $FreeBSD: head/bin/sh/tests/parser/alias18.0 317039 2017-04-16 22:10:02Z jilles $ + +v=1 +alias a='alias a=v=2 +v=3 +a' +eval a +[ "$v" = 2 ] diff --git a/sh/trap.c b/sh/trap.c index 7a969ed..0f84892 100644 --- a/sh/trap.c +++ b/sh/trap.c @@ -1,4 +1,6 @@ /*- + * SPDX-License-Identifier: BSD-3-Clause + * * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * @@ -13,7 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -36,7 +38,7 @@ static char sccsid[] = "@(#)trap.c 8.5 (Berkeley) 6/5/95"; #endif #endif /* not lint */ #include -__FBSDID("$FreeBSD: head/bin/sh/trap.c 297360 2016-03-28 18:58:40Z jilles $"); +__FBSDID("$FreeBSD: head/bin/sh/trap.c 326025 2017-11-20 19:49:47Z pfg $"); #include #include @@ -481,19 +483,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; } @@ -534,11 +531,13 @@ exitshell_savedstatus(void) */ evalskip = 0; trap[0] = NULL; + FORCEINTON; evalstring(p, 0); } } if (!setjmp(loc2.loc)) { handler = &loc2; /* probably unnecessary */ + FORCEINTON; flushall(); #if JOBS setjobctl(0); diff --git a/sh/trap.h b/sh/trap.h index a000647..90ba054 100644 --- a/sh/trap.h +++ b/sh/trap.h @@ -1,4 +1,6 @@ /*- + * SPDX-License-Identifier: BSD-3-Clause + * * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * @@ -13,7 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -30,7 +32,7 @@ * SUCH DAMAGE. * * @(#)trap.h 8.3 (Berkeley) 6/5/95 - * $FreeBSD: head/bin/sh/trap.h 276038 2014-12-21 23:09:59Z jilles $ + * $FreeBSD: head/bin/sh/trap.h 326025 2017-11-20 19:49:47Z pfg $ */ extern volatile sig_atomic_t pendingsig; @@ -43,6 +45,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/sh/var.c b/sh/var.c index 5ff6d20..feeea03 100644 --- a/sh/var.c +++ b/sh/var.c @@ -1,4 +1,6 @@ /*- + * SPDX-License-Identifier: BSD-3-Clause + * * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * @@ -13,7 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -36,7 +38,7 @@ static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 5/4/95"; #endif #endif /* not lint */ #include -__FBSDID("$FreeBSD: head/bin/sh/var.c 306843 2016-10-08 13:40:12Z jilles $"); +__FBSDID("$FreeBSD: head/bin/sh/var.c 329221 2018-02-13 16:48:57Z bdrewery $"); #include #include @@ -69,7 +71,9 @@ __FBSDID("$FreeBSD: head/bin/sh/var.c 306843 2016-10-08 13:40:12Z jilles $"); #endif +#ifndef VTABSIZE #define VTABSIZE 39 +#endif struct varinit { @@ -513,7 +517,7 @@ bltinunsetlocale(void) if (localevar(cmdenviron->args[i])) { setlocale(LC_ALL, ""); updatecharset(); - return; + break; } } INTON; diff --git a/sh/var.h b/sh/var.h index 7955c04..c9b5a99 100644 --- a/sh/var.h +++ b/sh/var.h @@ -1,4 +1,6 @@ /*- + * SPDX-License-Identifier: BSD-3-Clause + * * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * @@ -13,7 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -30,7 +32,7 @@ * SUCH DAMAGE. * * @(#)var.h 8.2 (Berkeley) 5/4/95 - * $FreeBSD: head/bin/sh/var.h 289159 2015-10-11 21:33:00Z jilles $ + * $FreeBSD: head/bin/sh/var.h 326025 2017-11-20 19:49:47Z pfg $ */ /* diff --git a/shell_cmds.xcodeproj/project.pbxproj b/shell_cmds.xcodeproj/project.pbxproj index ec1e231..df03dc7 100644 --- a/shell_cmds.xcodeproj/project.pbxproj +++ b/shell_cmds.xcodeproj/project.pbxproj @@ -3815,7 +3815,7 @@ FC80BF5714A05A2F00C6F7F5 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0430; + LastUpgradeCheck = 1100; ORGANIZATIONNAME = "Apple Inc."; TargetAttributes = { FD6060B11B7C0388004BCA6A = { @@ -3825,10 +3825,11 @@ }; buildConfigurationList = FC80BF5A14A05A2F00C6F7F5 /* Build configuration list for PBXProject "shell_cmds" */; compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; + developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( en, + Base, ); mainGroup = FC80BF5514A05A2F00C6F7F5; productRefGroup = FC80BF6114A05A2F00C6F7F5 /* Products */; @@ -4948,6 +4949,7 @@ C686857D154725700025D623 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; INSTALL_PATH = /usr/local/bin; PRODUCT_NAME = "$(TARGET_NAME)"; }; @@ -4956,6 +4958,7 @@ FC5D638A14B9819E00123E48 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -4963,6 +4966,7 @@ FC5D639614B9822D00123E48 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -4972,18 +4976,41 @@ buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; APPLY_RULES_IN_COPY_FILES = YES; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "-"; COPY_PHASE_STRIP = YES; CURRENT_PROJECT_VERSION = "$(RC_ProjectSourceVersion)"; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_ENABLE_OBJC_EXCEPTIONS = YES; + GCC_NO_COMMON_BLOCKS = YES; GCC_PREPROCESSOR_DEFINITIONS = "__FBSDID=__RCSID"; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; INSTALL_PATH = /usr/bin; + SDKROOT = macosx.internal; VERSIONING_SYSTEM = "apple-generic"; }; name = Release; @@ -4991,6 +5018,7 @@ FCBA149D14A141FF00AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -4998,6 +5026,7 @@ FCBA14B314A1422D00AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -5005,6 +5034,7 @@ FCBA14BC14A1423E00AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; INSTALL_PATH = /usr/sbin; PRODUCT_NAME = "$(TARGET_NAME)"; }; @@ -5013,6 +5043,7 @@ FCBA14C414A1426800AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = NO; INSTALL_PATH = /bin; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -5022,6 +5053,7 @@ FCBA14CC14A1428000AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -5029,6 +5061,7 @@ FCBA14D414A1433F00AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; INSTALL_PATH = /bin; PRODUCT_NAME = "$(TARGET_NAME)"; }; @@ -5037,6 +5070,7 @@ FCBA14DC14A1434A00AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -5044,6 +5078,7 @@ FCBA14FF14A144EC00AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -5051,6 +5086,7 @@ FCBA151314A1453A00AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; INSTALL_PATH = /bin; PRODUCT_NAME = "$(TARGET_NAME)"; }; @@ -5059,6 +5095,7 @@ FCBA151B14A1454D00AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -5066,6 +5103,7 @@ FCBA152314A1455600AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; GCC_PREPROCESSOR_DEFINITIONS = ( "__FBSDID=__RCSID", _DARWIN_USE_64_BIT_INODE, @@ -5078,6 +5116,7 @@ FCBA152B14A1455900AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -5085,6 +5124,7 @@ FCBA153314A1455C00AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; INSTALL_PATH = /bin; PRODUCT_NAME = "$(TARGET_NAME)"; }; @@ -5093,6 +5133,7 @@ FCBA153B14A1455F00AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; GCC_PREPROCESSOR_DEFINITIONS = ( "__FBSDID=__RCSID", USE_BSM_AUDIT, @@ -5105,6 +5146,7 @@ FCBA154314A1456100AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = NO; PRODUCT_NAME = "$(TARGET_NAME)"; }; @@ -5113,6 +5155,7 @@ FCBA154B14A1456400AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; INSTALL_PATH = /bin; PRODUCT_NAME = "$(TARGET_NAME)"; }; @@ -5121,6 +5164,7 @@ FCBA155314A1456700AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -5128,6 +5172,7 @@ FCBA155B14A1456A00AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -5135,6 +5180,7 @@ FCBA156314A1456E00AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -5142,6 +5188,7 @@ FCBA156B14A1457100AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -5149,6 +5196,7 @@ FCBA157B14A1457B00AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -5156,6 +5204,7 @@ FCBA158314A1457F00AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -5163,6 +5212,7 @@ FCBA158B14A1458500AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -5170,6 +5220,7 @@ FCBA159314A1458800AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; INSTALL_PATH = /usr/libexec; PRODUCT_NAME = "$(TARGET_NAME)"; }; @@ -5178,6 +5229,7 @@ FCBA159B14A1458C00AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -5185,6 +5237,7 @@ FCBA15A314A1459000AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -5192,6 +5245,7 @@ FCBA15AB14A1459500AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; INSTALL_PATH = /bin; PRODUCT_NAME = "$(TARGET_NAME)"; }; @@ -5200,6 +5254,7 @@ FCBA15B314A1459700AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -5207,6 +5262,7 @@ FCBA15BB14A1459900AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -5214,6 +5270,7 @@ FCBA15C314A1459E00AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -5221,6 +5278,7 @@ FCBA15CB14A145A200AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -5228,6 +5286,7 @@ FCBA15D314A145A500AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; INSTALL_PATH = /bin; PRODUCT_NAME = "$(TARGET_NAME)"; }; @@ -5236,6 +5295,7 @@ FCBA15DB14A145A700AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; INSTALL_MODE_FLAG = "u+s,u+w,go-w,a+rX"; PRODUCT_NAME = "$(TARGET_NAME)"; }; @@ -5244,6 +5304,7 @@ FCBA15E314A145A900AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -5251,6 +5312,7 @@ FCBA15EB14A145AE00AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; INSTALL_PATH = /bin; PRODUCT_NAME = "$(TARGET_NAME)"; }; @@ -5259,6 +5321,7 @@ FCBA15F314A145B000AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -5266,6 +5329,7 @@ FCBA15FB14A145B200AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -5273,6 +5337,7 @@ FCBA160314A145B500AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -5280,6 +5345,7 @@ FCBA160B14A145B800AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -5287,6 +5353,7 @@ FCBA161314A145BA00AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; GCC_PREPROCESSOR_DEFINITIONS = ( "__FBSDID=__RCSID", "HAVE_KVM=0", @@ -5300,6 +5367,7 @@ FCBA161B14A145BC00AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -5307,6 +5375,7 @@ FCBA162314A145C000AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -5314,6 +5383,7 @@ FCBA162B14A145C500AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; GCC_PREPROCESSOR_DEFINITIONS = ( "__FBSDID=__RCSID", _UTMPX_COMPAT, @@ -5326,6 +5396,7 @@ FCBA163314A145C700AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -5333,6 +5404,7 @@ FCBA163B14A145CA00AA698B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -5340,6 +5412,7 @@ FCE30ED114B5368A00CC0294 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; INSTALL_PATH = /usr/libexec; PRODUCT_NAME = "$(TARGET_NAME)"; }; @@ -5348,6 +5421,7 @@ FCE30EDD14B536C900CC0294 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; INSTALL_PATH = /usr/libexec; PRODUCT_NAME = "$(TARGET_NAME)"; }; @@ -5356,6 +5430,7 @@ FCE30F4C14B619B000CC0294 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -5364,6 +5439,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = FD6061311B7D2DDE004BCA6A /* sh.xcconfig */; buildSettings = { + CLANG_ENABLE_OBJC_WEAK = YES; }; name = Release; }; diff --git a/time/time.c b/time/time.c index cd8f573..0a3cb47 100644 --- a/time/time.c +++ b/time/time.c @@ -55,6 +55,8 @@ __RCSID("$NetBSD: time.c,v 1.9 1997/10/20 03:28:21 lukem Exp $"); #include #include #include +#include +#include int lflag; int portableflag; @@ -70,6 +72,7 @@ main(argc, argv) int ch, status; struct timeval before, after; struct rusage ru; + char * radix = NULL; #ifdef __GNUC__ /* XXX: borken gcc */ (void)&argv; @@ -116,14 +119,20 @@ main(argc, argv) timersub(&after, &before, &after); if (portableflag) { - fprintf (stderr, "real %9ld.%02ld\n", - (long)after.tv_sec, (long)after.tv_usec/10000); - fprintf (stderr, "user %9ld.%02ld\n", - (long)ru.ru_utime.tv_sec, (long)ru.ru_utime.tv_usec/10000); - fprintf (stderr, "sys %9ld.%02ld\n", - (long)ru.ru_stime.tv_sec, (long)ru.ru_stime.tv_usec/10000); - } else { + setlocale(LC_ALL, ""); + radix = nl_langinfo(RADIXCHAR); + if (!radix || radix[0] == '\0') { + radix = "."; + } + + fprintf (stderr, "real %9ld%s%02ld\n", + (long)after.tv_sec, radix, (long)after.tv_usec/10000); + fprintf (stderr, "user %9ld%s%02ld\n", + (long)ru.ru_utime.tv_sec, radix, (long)ru.ru_utime.tv_usec/10000); + fprintf (stderr, "sys %9ld%s%02ld\n", + (long)ru.ru_stime.tv_sec, radix, (long)ru.ru_stime.tv_usec/10000); + } else { fprintf(stderr, "%9ld.%02ld real ", (long)after.tv_sec, (long)after.tv_usec/10000); fprintf(stderr, "%9ld.%02ld user ", diff --git a/w/w.c b/w/w.c index c52c5ad..e493734 100644 --- a/w/w.c +++ b/w/w.c @@ -263,7 +263,7 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; -#if !TARGET_OS_EMBEDDED +#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) if (!(_res.options & RES_INIT)) res_init(); _res.retrans = 2; /* resolver timeout to 2 seconds per try */ -- 2.45.2