Date: Sun, 4 Jun 2017 21:02:48 +0000 (UTC) From: Bryan Drewery <bdrewery@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r319576 - head/bin/sh Message-ID: <201706042102.v54L2m28013733@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: bdrewery Date: Sun Jun 4 21:02:48 2017 New Revision: 319576 URL: https://svnweb.freebsd.org/changeset/base/319576 Log: Allow defining nofork builtins from builtins.def and move always-safe ones there. The generated code remains the same. Reviewed by: jilles Differential Revision: https://reviews.freebsd.org/D11042 Modified: head/bin/sh/builtins.def head/bin/sh/eval.c head/bin/sh/mkbuiltins Modified: head/bin/sh/builtins.def ============================================================================== --- head/bin/sh/builtins.def Sun Jun 4 20:52:55 2017 (r319575) +++ head/bin/sh/builtins.def Sun Jun 4 21:02:48 2017 (r319576) @@ -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 Modified: head/bin/sh/eval.c ============================================================================== --- head/bin/sh/eval.c Sun Jun 4 20:52:55 2017 (r319575) +++ head/bin/sh/eval.c Sun Jun 4 21:02:48 2017 (r319576) @@ -800,11 +800,8 @@ xtracecommand(struct arglist *varlist, int argc, char 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) Modified: head/bin/sh/mkbuiltins ============================================================================== --- head/bin/sh/mkbuiltins Sun Jun 4 20:52:55 2017 (r319575) +++ head/bin/sh/mkbuiltins Sun Jun 4 21:02:48 2017 (r319576) @@ -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 <<EOF + +static inline int +safe_builtin_always(int idx) +{ +EOF +awk ' +BEGIN { printed = 0 } +{ + for (i = 2 ; i <= NF ; i++) { + if ($i == "-s") { + continue + } else if ($i == "-n") { + nofork = 1; + } else { + if (nofork == 0) { + continue + } + if (printed == 1) { + printf " || \n\t " + } else { + printf "\tif (" + } + printf "idx == " toupper($1) + printed = 1 + nofork = 0; + # Only need to check each once + break + } + } +}' $temp + +cat << EOF +) + return (1); + return(0); +} +EOF + rm -f $temp
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201706042102.v54L2m28013733>