From b6afcc78194aa0801544bc606b9562339c846eb4 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 12 Dec 2016 16:30:20 +0100 Subject: shell: suppress "unused var/func" warnings on some configs Signed-off-by: Denys Vlasenko --- shell/ash.c | 12 ++++++------ shell/hush.c | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index 2bdb4aad7..91bcccb9d 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -11373,13 +11373,13 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs) smallint quotef; smallint dblquote; smallint oldstyle; - smallint prevsyntax; /* syntax before arithmetic */ + IF_SH_MATH_SUPPORT(smallint prevsyntax;) /* syntax before arithmetic */ #if ENABLE_ASH_EXPAND_PRMT smallint pssyntax; /* we are expanding a prompt string */ #endif int varnest; /* levels of variables expansion */ - int arinest; /* levels of arithmetic expansion */ - int parenlevel; /* levels of parens in arithmetic */ + IF_SH_MATH_SUPPORT(int arinest;) /* levels of arithmetic expansion */ + IF_SH_MATH_SUPPORT(int parenlevel;) /* levels of parens in arithmetic */ int dqvarnest; /* levels of variables expansion within double quotes */ IF_ASH_BASH_COMPAT(smallint bash_dollar_squote = 0;) @@ -11387,7 +11387,7 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs) startlinno = g_parsefile->linno; bqlist = NULL; quotef = 0; - prevsyntax = 0; + IF_SH_MATH_SUPPORT(prevsyntax = 0;) #if ENABLE_ASH_EXPAND_PRMT pssyntax = (syntax == PSSYNTAX); if (pssyntax) @@ -11395,8 +11395,8 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs) #endif dblquote = (syntax == DQSYNTAX); varnest = 0; - arinest = 0; - parenlevel = 0; + IF_SH_MATH_SUPPORT(arinest = 0;) + IF_SH_MATH_SUPPORT(parenlevel = 0;) dqvarnest = 0; STARTSTACKSTR(out); diff --git a/shell/hush.c b/shell/hush.c index bcd4dffee..888be6e6e 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -1574,9 +1574,8 @@ static sighandler_t install_sighandler(int sig, sighandler_t handler) } static void hush_exit(int exitcode) NORETURN; -static void fflush_and__exit(void) NORETURN; -static void restore_ttypgrp_and__exit(void) NORETURN; +static void restore_ttypgrp_and__exit(void) NORETURN; static void restore_ttypgrp_and__exit(void) { /* xfunc has failed! die die die */ @@ -1585,6 +1584,8 @@ static void restore_ttypgrp_and__exit(void) hush_exit(xfunc_error_retval); } +#if ENABLE_HUSH_JOB + /* Needed only on some libc: * It was observed that on exit(), fgetc'ed buffered data * gets "unwound" via lseek(fd, -NUM, SEEK_CUR). @@ -1598,14 +1599,13 @@ static void restore_ttypgrp_and__exit(void) * and in `cmd` handling. * If set as die_func(), this makes xfunc_die() exit via _exit(), not exit(): */ +static void fflush_and__exit(void) NORETURN; static void fflush_and__exit(void) { fflush_all(); _exit(xfunc_error_retval); } -#if ENABLE_HUSH_JOB - /* After [v]fork, in child: do not restore tty pgrp on xfunc death */ # define disable_restore_tty_pgrp_on_exit() (die_func = fflush_and__exit) /* After [v]fork, in parent: restore tty pgrp on xfunc death */ -- cgit v1.2.3-55-g6feb From 2fe66b1d2dc50f9d5ed98d5c537745f3066fb4d8 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 12 Dec 2016 17:39:12 +0100 Subject: ash: fix signed char expansion bug Signed-off-by: Denys Vlasenko --- shell/ash.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index 91bcccb9d..8d8cc466b 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -3113,7 +3113,18 @@ static const uint8_t syntax_index_table[] ALIGN1 = { # endif }; +#if 1 # define SIT(c, syntax) ((S_I_T[syntax_index_table[c]] >> ((syntax)*4)) & 0xf) +#else /* debug version, caught one signed char bug */ +# define SIT(c, syntax) \ + ({ \ + if ((c) < 0 || (c) > (PEOF + ENABLE_ASH_ALIAS)) \ + bb_error_msg_and_die("line:%d c:%d", __LINE__, (c)); \ + if ((syntax) < 0 || (syntax) > (2 + ENABLE_SH_MATH_SUPPORT)) \ + bb_error_msg_and_die("line:%d c:%d", __LINE__, (c)); \ + ((S_I_T[syntax_index_table[c]] >> ((syntax)*4)) & 0xf); \ + }) +#endif #endif /* !USE_SIT_FUNCTION */ @@ -5869,14 +5880,15 @@ memtodest(const char *p, size_t len, int syntax, int quotes) do { unsigned char c = *p++; if (c) { - int n = SIT(c, syntax); - if ((quotes & QUOTES_ESC) - && ((n == CCTL) - || (((quotes & EXP_FULL) || syntax != BASESYNTAX) - && n == CBACK) - ) - ) { - USTPUTC(CTLESC, q); + if (quotes & QUOTES_ESC) { + int n = SIT(c, syntax); + if (n == CCTL + || (((quotes & EXP_FULL) || syntax != BASESYNTAX) + && n == CBACK + ) + ) { + USTPUTC(CTLESC, q); + } } } else if (!(quotes & QUOTES_KEEPNUL)) continue; @@ -10051,7 +10063,7 @@ pgetc(void) return g_parsefile->lastc[--g_parsefile->unget]; if (--g_parsefile->left_in_line >= 0) - c = (signed char)*g_parsefile->next_to_pgetc++; + c = (unsigned char)*g_parsefile->next_to_pgetc++; else c = preadbuffer(); -- cgit v1.2.3-55-g6feb From 3a4cdf45f928de0af09088bbbb96f60d9ac44e87 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 21 Dec 2016 04:13:23 +0100 Subject: ash: error out if ASH_INTERNAL_GLOB is not selected on uClibc Signed-off-by: Denys Vlasenko --- shell/ash.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index 8d8cc466b..7d45b2cd2 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -51,6 +51,14 @@ # define ENABLE_ASH_INTERNAL_GLOB 1 #endif +#if !ENABLE_ASH_INTERNAL_GLOB && defined(__UCLIBC__) +# error uClibc glob() is buggy, use ASH_INTERNAL_GLOB. +# error The bug is: for "$PWD"/ ash will escape e.g. dashes in "$PWD" +# error with backslash, even ones which do not need to be: "/a-b" -> "/a\-b" +# error glob() should unbackslash them and match. uClibc does not unbackslash, +# error fails to match dirname, subsequently not expanding in it. +#endif + #if !ENABLE_ASH_INTERNAL_GLOB # include #endif -- cgit v1.2.3-55-g6feb From 2166952ec393b9a8f890a12951c812c47fdfd457 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 21 Dec 2016 21:04:16 +0100 Subject: ash: clarify uclibc glob() bug in comment Signed-off-by: Denys Vlasenko --- shell/ash.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index 7d45b2cd2..802626d4e 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -57,6 +57,9 @@ # error with backslash, even ones which do not need to be: "/a-b" -> "/a\-b" # error glob() should unbackslash them and match. uClibc does not unbackslash, # error fails to match dirname, subsequently not expanding in it. +// Testcase: +// if (glob("/etc/polkit\\-1", 0, NULL, &pglob)) - this returns 0 on uclibc, no bug +// if (glob("/etc/polkit\\-1/*", 0, NULL, &pglob)) printf("uclibc bug!\n"); #endif #if !ENABLE_ASH_INTERNAL_GLOB -- cgit v1.2.3-55-g6feb From 326edc3e375d6d5be205d4b1592211bf15e33bcd Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 22 Dec 2016 14:36:49 +0100 Subject: Tweak some config defaults; fix MODPROBE_SMALL ordering in "make config" Signed-off-by: Denys Vlasenko --- include/applets.h.sh | 8 ++++---- init/init.c | 2 +- modutils/Config.src | 31 +++++++++++++++++++++++++++++++ modutils/modprobe-small.c | 34 +++------------------------------- shell/ash.c | 5 ++--- 5 files changed, 41 insertions(+), 39 deletions(-) (limited to 'shell') diff --git a/include/applets.h.sh b/include/applets.h.sh index bab4e0d72..be8b92404 100755 --- a/include/applets.h.sh +++ b/include/applets.h.sh @@ -6,9 +6,6 @@ # CONFIG_applet names grep ^IF_ applets.h | grep -v IF_FEATURE_ | sed 's/IF_\([A-Z0-9._-]*\)(.*/\1/' \ | grep -v MODPROBE_SMALL \ -| sed 's/BB_SYSCTL/SYSCTL/' \ -| sed 's/TEST1/[/' \ -| sed 's/TEST2/[[/' \ | sort | uniq \ >applets_APP1 @@ -17,8 +14,11 @@ grep ^IF_ applets.h | sed -e's/ //g' -e's/.*(\([a-z[][^,]*\),.*/\1/' \ | grep -v '^bash$' \ | grep -v '^sh$' \ | tr a-z A-Z \ +| sed 's/^SYSCTL$/BB_SYSCTL/' \ +| sed 's/^\[\[$/TEST1/' \ +| sed 's/^\[$/TEST2/' \ | sort | uniq \ >applets_APP2 diff -u applets_APP1 applets_APP2 >applets_APP.diff -rm applets_APP1 applets_APP2 +#rm applets_APP1 applets_APP2 diff --git a/init/init.c b/init/init.c index 0813d1b5f..08cfa2f8c 100644 --- a/init/init.c +++ b/init/init.c @@ -83,7 +83,7 @@ //config: //config:config FEATURE_INIT_COREDUMPS //config: bool "Support dumping core for child processes (debugging only)" -//config: default y +//config: default n # not Y because this is a debug option //config: depends on INIT || LINUXRC //config: help //config: If this option is enabled and the file /.init_enable_core diff --git a/modutils/Config.src b/modutils/Config.src index 4227f356a..84ff34a08 100644 --- a/modutils/Config.src +++ b/modutils/Config.src @@ -5,6 +5,37 @@ menu "Linux Module Utilities" +config MODPROBE_SMALL + bool "Simplified modutils" + default y + select PLATFORM_LINUX + help + Simplified modutils. + + With this option modprobe does not require modules.dep file + and does not use /etc/modules.conf file. + It scans module files in /lib/modules/`uname -r` and + determines dependencies and module alias names on the fly. + This may make module loading slower, most notably + when one needs to load module by alias (this requires + scanning through module _bodies_). + + At the first attempt to load a module by alias modprobe + will try to generate modules.dep.bb file in order to speed up + future loads by alias. Failure to do so (read-only /lib/modules, + etc) is not reported, and future modprobes will be slow too. + + NB: modules.dep.bb file format is not compatible + with modules.dep file as created/used by standard module tools. + + Additional module parameters can be stored in + /etc/modules/$module_name files. + + Apart from modprobe, other utilities are also provided: + - insmod is an alias to modprobe + - rmmod is an alias to modprobe -r + - depmod generates modules.dep.bb + INSERT comment "Options common to multiple modutils" diff --git a/modutils/modprobe-small.c b/modutils/modprobe-small.c index 51ba42f7a..e3a349b4e 100644 --- a/modutils/modprobe-small.c +++ b/modutils/modprobe-small.c @@ -7,37 +7,9 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ -//config:config MODPROBE_SMALL -//config: bool "Simplified modutils" -//config: default y -//config: select PLATFORM_LINUX -//config: help -//config: Simplified modutils. -//config: -//config: With this option modprobe does not require modules.dep file -//config: and does not use /etc/modules.conf file. -//config: It scans module files in /lib/modules/`uname -r` and -//config: determines dependencies and module alias names on the fly. -//config: This may make module loading slower, most notably -//config: when one needs to load module by alias (this requires -//config: scanning through module _bodies_). -//config: -//config: At the first attempt to load a module by alias modprobe -//config: will try to generate modules.dep.bb file in order to speed up -//config: future loads by alias. Failure to do so (read-only /lib/modules, -//config: etc) is not reported, and future modprobes will be slow too. -//config: -//config: NB: modules.dep.bb file format is not compatible -//config: with modules.dep file as created/used by standard module tools. -//config: -//config: Additional module parameters can be stored in -//config: /etc/modules/$module_name files. -//config: -//config: Apart from modprobe, other utilities are also provided: -//config: - insmod is an alias to modprobe -//config: - rmmod is an alias to modprobe -r -//config: - depmod generates modules.dep.bb -//config: + +/* config MODPROBE_SMALL is defined in Config.src to ensure better "make config" order */ + //config:config FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE //config: bool "Accept module options on modprobe command line" //config: default y diff --git a/shell/ash.c b/shell/ash.c index 802626d4e..89339182e 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -117,7 +117,7 @@ //config: //config:config ASH_INTERNAL_GLOB //config: bool "Use internal glob() implementation" -//config: default n +//config: default y # Y is bigger, but because of uclibc glob() bug, let Y be default for now //config: depends on ASH //config: help //config: Do not use glob() function from libc, use internal implementation. @@ -218,11 +218,10 @@ //config: //config:config ASH_MAIL //config: bool "Check for new mail on interactive shells" -//config: default n +//config: default y //config: depends on ASH //config: help //config: Enable "check for new mail" function in the ash shell. -//config: //applet:IF_ASH(APPLET(ash, BB_DIR_BIN, BB_SUID_DROP)) //applet:IF_FEATURE_SH_IS_ASH(APPLET_ODDNAME(sh, ash, BB_DIR_BIN, BB_SUID_DROP, sh)) -- cgit v1.2.3-55-g6feb From 6704746c697ace0cc0de5b231fc8be4db06c40f4 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 22 Dec 2016 15:21:58 +0100 Subject: shell: move "config" blocks above their use in coditional includes Signed-off-by: Denys Vlasenko --- shell/ash.c | 163 +++++++++++++++++++++++++++++------------------------------ shell/hush.c | 58 ++++++++++----------- 2 files changed, 110 insertions(+), 111 deletions(-) (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index 89339182e..b11f36589 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -15,88 +15,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - -/* - * The following should be set to reflect the type of system you have: - * JOBS -> 1 if you have Berkeley job control, 0 otherwise. - * define SYSV if you are running under System V. - * define DEBUG=1 to compile in debugging ('set -o debug' to turn on) - * define DEBUG=2 to compile in and turn on debugging. - * - * When debugging is on (DEBUG is 1 and "set -o debug" was executed), - * debugging info will be written to ./trace and a quit signal - * will generate a core dump. - */ -#define DEBUG 0 -/* Tweak debug output verbosity here */ -#define DEBUG_TIME 0 -#define DEBUG_PID 1 -#define DEBUG_SIG 1 -#define DEBUG_INTONOFF 0 - -#define PROFILE 0 - -#define JOBS ENABLE_ASH_JOB_CONTROL - -#include -#include -#include -#include /* for setting $HOSTNAME */ - -#include "busybox.h" /* for applet_names */ - -#if defined(__ANDROID_API__) && __ANDROID_API__ <= 24 -/* Bionic at least up to version 24 has no glob() */ -# undef ENABLE_ASH_INTERNAL_GLOB -# define ENABLE_ASH_INTERNAL_GLOB 1 -#endif - -#if !ENABLE_ASH_INTERNAL_GLOB && defined(__UCLIBC__) -# error uClibc glob() is buggy, use ASH_INTERNAL_GLOB. -# error The bug is: for "$PWD"/ ash will escape e.g. dashes in "$PWD" -# error with backslash, even ones which do not need to be: "/a-b" -> "/a\-b" -# error glob() should unbackslash them and match. uClibc does not unbackslash, -# error fails to match dirname, subsequently not expanding in it. -// Testcase: -// if (glob("/etc/polkit\\-1", 0, NULL, &pglob)) - this returns 0 on uclibc, no bug -// if (glob("/etc/polkit\\-1/*", 0, NULL, &pglob)) printf("uclibc bug!\n"); -#endif - -#if !ENABLE_ASH_INTERNAL_GLOB -# include -#endif - -#include "unicode.h" -#include "shell_common.h" -#if ENABLE_SH_MATH_SUPPORT -# include "math.h" -#endif -#if ENABLE_ASH_RANDOM_SUPPORT -# include "random.h" -#else -# define CLEAR_RANDOM_T(rnd) ((void)0) -#endif - -#include "NUM_APPLETS.h" -#if NUM_APPLETS == 1 -/* STANDALONE does not make sense, and won't compile */ -# undef CONFIG_FEATURE_SH_STANDALONE -# undef ENABLE_FEATURE_SH_STANDALONE -# undef IF_FEATURE_SH_STANDALONE -# undef IF_NOT_FEATURE_SH_STANDALONE -# define ENABLE_FEATURE_SH_STANDALONE 0 -# define IF_FEATURE_SH_STANDALONE(...) -# define IF_NOT_FEATURE_SH_STANDALONE(...) __VA_ARGS__ -#endif - -#ifndef PIPE_BUF -# define PIPE_BUF 4096 /* amount of buffering in a pipe */ -#endif - -#if !BB_MMU -# error "Do not even bother, ash will not run on NOMMU machine" -#endif - //config:config ASH //config: bool "ash" //config: default y @@ -230,6 +148,87 @@ //kbuild:lib-$(CONFIG_ASH) += ash.o ash_ptr_hack.o shell_common.o //kbuild:lib-$(CONFIG_ASH_RANDOM_SUPPORT) += random.o +/* + * The following should be set to reflect the type of system you have: + * JOBS -> 1 if you have Berkeley job control, 0 otherwise. + * define SYSV if you are running under System V. + * define DEBUG=1 to compile in debugging ('set -o debug' to turn on) + * define DEBUG=2 to compile in and turn on debugging. + * + * When debugging is on (DEBUG is 1 and "set -o debug" was executed), + * debugging info will be written to ./trace and a quit signal + * will generate a core dump. + */ +#define DEBUG 0 +/* Tweak debug output verbosity here */ +#define DEBUG_TIME 0 +#define DEBUG_PID 1 +#define DEBUG_SIG 1 +#define DEBUG_INTONOFF 0 + +#define PROFILE 0 + +#define JOBS ENABLE_ASH_JOB_CONTROL + +#include +#include +#include +#include /* for setting $HOSTNAME */ + +#include "busybox.h" /* for applet_names */ + +#if defined(__ANDROID_API__) && __ANDROID_API__ <= 24 +/* Bionic at least up to version 24 has no glob() */ +# undef ENABLE_ASH_INTERNAL_GLOB +# define ENABLE_ASH_INTERNAL_GLOB 1 +#endif + +#if !ENABLE_ASH_INTERNAL_GLOB && defined(__UCLIBC__) +# error uClibc glob() is buggy, use ASH_INTERNAL_GLOB. +# error The bug is: for "$PWD"/ ash will escape e.g. dashes in "$PWD" +# error with backslash, even ones which do not need to be: "/a-b" -> "/a\-b" +# error glob() should unbackslash them and match. uClibc does not unbackslash, +# error fails to match dirname, subsequently not expanding in it. +// Testcase: +// if (glob("/etc/polkit\\-1", 0, NULL, &pglob)) - this returns 0 on uclibc, no bug +// if (glob("/etc/polkit\\-1/*", 0, NULL, &pglob)) printf("uclibc bug!\n"); +#endif + +#if !ENABLE_ASH_INTERNAL_GLOB +# include +#endif + +#include "unicode.h" +#include "shell_common.h" +#if ENABLE_SH_MATH_SUPPORT +# include "math.h" +#endif +#if ENABLE_ASH_RANDOM_SUPPORT +# include "random.h" +#else +# define CLEAR_RANDOM_T(rnd) ((void)0) +#endif + +#include "NUM_APPLETS.h" +#if NUM_APPLETS == 1 +/* STANDALONE does not make sense, and won't compile */ +# undef CONFIG_FEATURE_SH_STANDALONE +# undef ENABLE_FEATURE_SH_STANDALONE +# undef IF_FEATURE_SH_STANDALONE +# undef IF_NOT_FEATURE_SH_STANDALONE +# define ENABLE_FEATURE_SH_STANDALONE 0 +# define IF_FEATURE_SH_STANDALONE(...) +# define IF_NOT_FEATURE_SH_STANDALONE(...) __VA_ARGS__ +#endif + +#ifndef PIPE_BUF +# define PIPE_BUF 4096 /* amount of buffering in a pipe */ +#endif + +#if !BB_MMU +# error "Do not even bother, ash will not run on NOMMU machine" +#endif + /* ============ Hash table sizes. Configurable. */ diff --git a/shell/hush.c b/shell/hush.c index 888be6e6e..c5821259a 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -82,35 +82,6 @@ * $ "export" i=`echo 'aaa bbb'`; echo "$i" * aaa */ -#if !(defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) \ - || defined(__APPLE__) \ - ) -# include /* for malloc_trim */ -#endif -#include -/* #include */ -#if ENABLE_HUSH_CASE -# include -#endif -#include /* for setting $HOSTNAME */ - -#include "busybox.h" /* for APPLET_IS_NOFORK/NOEXEC */ -#include "unicode.h" -#include "shell_common.h" -#include "math.h" -#include "match.h" -#if ENABLE_HUSH_RANDOM_SUPPORT -# include "random.h" -#else -# define CLEAR_RANDOM_T(rnd) ((void)0) -#endif -#ifndef F_DUPFD_CLOEXEC -# define F_DUPFD_CLOEXEC F_DUPFD -#endif -#ifndef PIPE_BUF -# define PIPE_BUF 4096 /* amount of buffering in a pipe */ -#endif - //config:config HUSH //config: bool "hush" //config: default y @@ -277,6 +248,35 @@ //usage:# define bash_full_usage hush_full_usage //usage:#endif +#if !(defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) \ + || defined(__APPLE__) \ + ) +# include /* for malloc_trim */ +#endif +#include +/* #include */ +#if ENABLE_HUSH_CASE +# include +#endif +#include /* for setting $HOSTNAME */ + +#include "busybox.h" /* for APPLET_IS_NOFORK/NOEXEC */ +#include "unicode.h" +#include "shell_common.h" +#include "math.h" +#include "match.h" +#if ENABLE_HUSH_RANDOM_SUPPORT +# include "random.h" +#else +# define CLEAR_RANDOM_T(rnd) ((void)0) +#endif +#ifndef F_DUPFD_CLOEXEC +# define F_DUPFD_CLOEXEC F_DUPFD +#endif +#ifndef PIPE_BUF +# define PIPE_BUF 4096 /* amount of buffering in a pipe */ +#endif + /* Build knobs */ #define LEAK_HUNTING 0 -- cgit v1.2.3-55-g6feb From 0b8835861b2e43cb45becdb560877bcc89aea827 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 23 Dec 2016 16:49:07 +0100 Subject: Make it possible to select "sh" and "bash" aliases without selecting ash or hush The same can be done for msh, but we are probably better off just deleting it in a next versio or two. Signed-off-by: Denys Vlasenko --- coreutils/Kbuild.src | 20 ++++++----- coreutils/test.c | 2 ++ make_single_applets.sh | 11 ++++++ procps/Kbuild.src | 2 ++ shell/Config.src | 45 +++++++++++------------- shell/Kbuild.src | 2 +- shell/ash.c | 95 ++++++++++++++++++++++++-------------------------- shell/hush.c | 59 +++++++++++++------------------ shell/math.h | 2 +- 9 files changed, 120 insertions(+), 118 deletions(-) (limited to 'shell') diff --git a/coreutils/Kbuild.src b/coreutils/Kbuild.src index 8e2c097a3..d9a448781 100644 --- a/coreutils/Kbuild.src +++ b/coreutils/Kbuild.src @@ -10,12 +10,16 @@ lib-y:= INSERT -lib-$(CONFIG_MORE) += cat.o # more uses it if stdout isn't a tty -lib-$(CONFIG_LESS) += cat.o # less too -lib-$(CONFIG_CRONTAB) += cat.o # crontab -l -lib-$(CONFIG_ADDUSER) += chown.o # used by adduser -lib-$(CONFIG_ADDGROUP) += chown.o # used by adduser -lib-$(CONFIG_ASH) += echo.o # used by ash -lib-$(CONFIG_HUSH) += echo.o # used by hush -lib-$(CONFIG_FTPD) += ls.o # used by ftpd +lib-$(CONFIG_MORE) += cat.o # more uses it if stdout isn't a tty +lib-$(CONFIG_LESS) += cat.o # less too +lib-$(CONFIG_CRONTAB) += cat.o # crontab -l +lib-$(CONFIG_ADDUSER) += chown.o # used by adduser +lib-$(CONFIG_ADDGROUP) += chown.o # used by adduser +lib-$(CONFIG_ASH) += echo.o # used by ash +lib-$(CONFIG_SH_IS_ASH) += echo.o # used by ash +lib-$(CONFIG_BASH_IS_ASH) += echo.o # used by ash +lib-$(CONFIG_HUSH) += echo.o # used by hush +lib-$(CONFIG_SH_IS_HUSH) += echo.o # used by hush +lib-$(CONFIG_BASH_IS_HUSH) += echo.o # used by hush +lib-$(CONFIG_FTPD) += ls.o # used by ftpd lib-$(CONFIG_ASH_BUILTIN_PRINTF) += printf.o diff --git a/coreutils/test.c b/coreutils/test.c index 9e18ee986..288f66508 100644 --- a/coreutils/test.c +++ b/coreutils/test.c @@ -55,6 +55,8 @@ //kbuild:lib-$(CONFIG_TEST2) += test.o test_ptr_hack.o //kbuild:lib-$(CONFIG_ASH_BUILTIN_TEST) += test.o test_ptr_hack.o //kbuild:lib-$(CONFIG_HUSH) += test.o test_ptr_hack.o +//kbuild:lib-$(CONFIG_SH_IS_HUSH) += test.o test_ptr_hack.o +//kbuild:lib-$(CONFIG_BASH_IS_HUSH) += test.o test_ptr_hack.o /* "test --help" is special-cased to ignore --help */ //usage:#define test_trivial_usage NOUSAGE_STR diff --git a/make_single_applets.sh b/make_single_applets.sh index 6473e4ddd..705f9821c 100755 --- a/make_single_applets.sh +++ b/make_single_applets.sh @@ -26,6 +26,7 @@ allno="$cfg" for app in $apps; do allno="`echo "$allno" | sed "s/^CONFIG_${app}=y\$/# CONFIG_${app} is not set/"`" done +#echo "$allno" >.config_allno # Turn on each applet individually and build single-applet executable fail=0 @@ -37,6 +38,16 @@ for app in $apps; do mv .config .config.SV echo "CONFIG_${app}=y" >.config echo "$allno" | sed "/^# CONFIG_${app} is not set\$/d" >>.config + + if test x"${app}" != x"SH_IS_ASH"; then + # $allno has all choices for "sh" aliasing at off. + # "sh" aliasing defaults to "ash", not none. + # without this fix, "make oldconfig" sets it wrong, + # resulting in NUM_APPLETS = 2 + sed '/CONFIG_SH_IS_NONE/d' -i .config + echo "CONFIG_SH_IS_NONE=y" >>.config + fi + if ! yes '' | make oldconfig >busybox_make_${app}.log 2>&1; then : $((fail++)) echo "Config error for ${app}" diff --git a/procps/Kbuild.src b/procps/Kbuild.src index 83af05a05..e7adc7340 100644 --- a/procps/Kbuild.src +++ b/procps/Kbuild.src @@ -9,3 +9,5 @@ lib-y:= INSERT lib-$(CONFIG_ASH) += kill.o # used for built-in kill by ash +lib-$(CONFIG_SH_IS_ASH) += kill.o # used for built-in kill by ash +lib-$(CONFIG_BASH_IS_ASH) += kill.o # used for built-in kill by ash diff --git a/shell/Config.src b/shell/Config.src index e4df35973..7f5f67050 100644 --- a/shell/Config.src +++ b/shell/Config.src @@ -5,34 +5,30 @@ menu "Shells" -INSERT - choice prompt "Choose which shell is aliased to 'sh' name" - default FEATURE_SH_IS_ASH + default SH_IS_ASH help Choose which shell you want to be executed by 'sh' alias. The ash shell is the most bash compatible and full featured one. # note: cannot use "select ASH" here, it breaks "make allnoconfig" -config FEATURE_SH_IS_ASH - depends on ASH - bool "ash" +config SH_IS_ASH depends on !NOMMU + bool "ash" -config FEATURE_SH_IS_HUSH - depends on HUSH +config SH_IS_HUSH bool "hush" -config FEATURE_SH_IS_NONE +config SH_IS_NONE bool "none" endchoice choice prompt "Choose which shell is aliased to 'bash' name" - default FEATURE_BASH_IS_NONE + default BASH_IS_NONE help Choose which shell you want to be executed by 'bash' alias. The ash shell is the most bash compatible and full featured one. @@ -47,32 +43,33 @@ choice can't be used for running them because it won't recongnize "bash" as a supported applet name. -config FEATURE_BASH_IS_ASH - depends on ASH - bool "ash" +config BASH_IS_ASH depends on !NOMMU + bool "ash" -config FEATURE_BASH_IS_HUSH - depends on HUSH +config BASH_IS_HUSH bool "hush" -config FEATURE_BASH_IS_NONE +config BASH_IS_NONE bool "none" endchoice -config SH_MATH_SUPPORT +INSERT + + +config FEATURE_SH_MATH bool "POSIX math support" default y - depends on ASH || HUSH + depends on ASH || HUSH || SH_IS_ASH || BASH_IS_ASH || SH_IS_HUSH || BASH_IS_HUSH help Enable math support in the shell via $((...)) syntax. -config SH_MATH_SUPPORT_64 +config FEATURE_SH_MATH_64 bool "Extend POSIX math support to 64 bit" default y - depends on SH_MATH_SUPPORT + depends on FEATURE_SH_MATH help Enable 64-bit math support in the shell. This will make the shell slightly larger, but will allow computation with very large numbers. @@ -81,14 +78,14 @@ config SH_MATH_SUPPORT_64 config FEATURE_SH_EXTRA_QUIET bool "Hide message on interactive shell startup" default y - depends on HUSH || ASH + depends on ASH || HUSH || SH_IS_ASH || BASH_IS_ASH || SH_IS_HUSH || BASH_IS_HUSH help Remove the busybox introduction when starting a shell. config FEATURE_SH_STANDALONE bool "Standalone shell" default n - depends on (HUSH || ASH) + depends on ASH || HUSH || SH_IS_ASH || BASH_IS_ASH || SH_IS_HUSH || BASH_IS_HUSH help This option causes busybox shells to use busybox applets in preference to executables in the PATH whenever possible. For @@ -121,7 +118,7 @@ config FEATURE_SH_STANDALONE config FEATURE_SH_NOFORK bool "Run 'nofork' applets directly" default n - depends on (HUSH || ASH) + depends on ASH || HUSH || SH_IS_ASH || BASH_IS_ASH || SH_IS_HUSH || BASH_IS_HUSH help This option causes busybox shells to not execute typical fork/exec/wait sequence, but call _main directly, @@ -139,7 +136,7 @@ config FEATURE_SH_NOFORK config FEATURE_SH_HISTFILESIZE bool "Use $HISTFILESIZE" default y - depends on HUSH || ASH + depends on ASH || HUSH || SH_IS_ASH || BASH_IS_ASH || SH_IS_HUSH || BASH_IS_HUSH help This option makes busybox shells to use $HISTFILESIZE variable to set shell history size. Note that its max value is capped diff --git a/shell/Kbuild.src b/shell/Kbuild.src index c00aec92a..6bba4989f 100644 --- a/shell/Kbuild.src +++ b/shell/Kbuild.src @@ -8,4 +8,4 @@ lib-y:= INSERT -lib-$(CONFIG_SH_MATH_SUPPORT) += math.o +lib-$(CONFIG_FEATURE_SH_MATH) += math.o diff --git a/shell/ash.c b/shell/ash.c index b11f36589..430e42a7b 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -29,14 +29,14 @@ //config:config ASH_OPTIMIZE_FOR_SIZE //config: bool "Optimize for size instead of speed" //config: default y -//config: depends on ASH +//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH //config: help //config: Compile ash for reduced size at the price of speed. //config: //config:config ASH_INTERNAL_GLOB //config: bool "Use internal glob() implementation" //config: default y # Y is bigger, but because of uclibc glob() bug, let Y be default for now -//config: depends on ASH +//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH //config: help //config: Do not use glob() function from libc, use internal implementation. //config: Use this if you are getting "glob.h: No such file or directory" @@ -45,7 +45,7 @@ //config:config ASH_RANDOM_SUPPORT //config: bool "Pseudorandom generator and $RANDOM variable" //config: default y -//config: depends on ASH +//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH //config: help //config: Enable pseudorandom generator and dynamic variable "$RANDOM". //config: Each read of "$RANDOM" will generate a new pseudorandom value. @@ -56,7 +56,7 @@ //config:config ASH_EXPAND_PRMT //config: bool "Expand prompt string" //config: default y -//config: depends on ASH +//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH //config: help //config: "PS#" may contain volatile content, such as backquote commands. //config: This option recreates the prompt string from the environment @@ -65,70 +65,70 @@ //config:config ASH_BASH_COMPAT //config: bool "bash-compatible extensions" //config: default y -//config: depends on ASH +//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH //config: help //config: Enable bash-compatible extensions. //config: //config:config ASH_IDLE_TIMEOUT //config: bool "Idle timeout variable" //config: default n -//config: depends on ASH +//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH //config: help //config: Enables bash-like auto-logout after $TMOUT seconds of idle time. //config: //config:config ASH_JOB_CONTROL //config: bool "Job control" //config: default y -//config: depends on ASH +//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH //config: help //config: Enable job control in the ash shell. //config: //config:config ASH_ALIAS //config: bool "Alias support" //config: default y -//config: depends on ASH +//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH //config: help //config: Enable alias support in the ash shell. //config: //config:config ASH_GETOPTS //config: bool "Builtin getopt to parse positional parameters" //config: default y -//config: depends on ASH +//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH //config: help //config: Enable support for getopts builtin in ash. //config: //config:config ASH_BUILTIN_ECHO //config: bool "Builtin version of 'echo'" //config: default y -//config: depends on ASH +//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH //config: help //config: Enable support for echo builtin in ash. //config: //config:config ASH_BUILTIN_PRINTF //config: bool "Builtin version of 'printf'" //config: default y -//config: depends on ASH +//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH //config: help //config: Enable support for printf builtin in ash. //config: //config:config ASH_BUILTIN_TEST //config: bool "Builtin version of 'test'" //config: default y -//config: depends on ASH +//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH //config: help //config: Enable support for test builtin in ash. //config: //config:config ASH_HELP //config: bool "help builtin" //config: default y -//config: depends on ASH +//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH //config: help //config: Enable help builtin in ash. //config: //config:config ASH_CMDCMD //config: bool "'command' command to override shell builtins" //config: default y -//config: depends on ASH +//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH //config: help //config: Enable support for the ash 'command' builtin, which allows //config: you to run the specified command with the specified arguments, @@ -137,15 +137,17 @@ //config:config ASH_MAIL //config: bool "Check for new mail on interactive shells" //config: default y -//config: depends on ASH +//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH //config: help //config: Enable "check for new mail" function in the ash shell. //applet:IF_ASH(APPLET(ash, BB_DIR_BIN, BB_SUID_DROP)) -//applet:IF_FEATURE_SH_IS_ASH(APPLET_ODDNAME(sh, ash, BB_DIR_BIN, BB_SUID_DROP, sh)) -//applet:IF_FEATURE_BASH_IS_ASH(APPLET_ODDNAME(bash, ash, BB_DIR_BIN, BB_SUID_DROP, bash)) +//applet:IF_SH_IS_ASH(APPLET_ODDNAME(sh, ash, BB_DIR_BIN, BB_SUID_DROP, ash)) +//applet:IF_BASH_IS_ASH(APPLET_ODDNAME(bash, ash, BB_DIR_BIN, BB_SUID_DROP, ash)) //kbuild:lib-$(CONFIG_ASH) += ash.o ash_ptr_hack.o shell_common.o +//kbuild:lib-$(CONFIG_SH_IS_ASH) += ash.o ash_ptr_hack.o shell_common.o +//kbuild:lib-$(CONFIG_BASH_IS_ASH) += ash.o ash_ptr_hack.o shell_common.o //kbuild:lib-$(CONFIG_ASH_RANDOM_SUPPORT) += random.o /* @@ -200,7 +202,7 @@ #include "unicode.h" #include "shell_common.h" -#if ENABLE_SH_MATH_SUPPORT +#if ENABLE_FEATURE_SH_MATH # include "math.h" #endif #if ENABLE_ASH_RANDOM_SUPPORT @@ -2144,6 +2146,7 @@ lookupvar(const char *name) return NULL; } +#if ENABLE_UNICODE_SUPPORT static void reinit_unicode_for_ash(void) { @@ -2160,6 +2163,9 @@ reinit_unicode_for_ash(void) reinit_unicode(s); } } +#else +# define reinit_unicode_for_ash() ((void)0) +#endif /* * Search the environment of a builtin command. @@ -2741,7 +2747,7 @@ pwdcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) #define USE_SIT_FUNCTION ENABLE_ASH_OPTIMIZE_FOR_SIZE -#if ENABLE_SH_MATH_SUPPORT +#if ENABLE_FEATURE_SH_MATH # define SIT_ITEM(a,b,c,d) (a | (b << 4) | (c << 8) | (d << 12)) #else # define SIT_ITEM(a,b,c,d) (a | (b << 4) | (c << 8)) @@ -3129,7 +3135,7 @@ static const uint8_t syntax_index_table[] ALIGN1 = { ({ \ if ((c) < 0 || (c) > (PEOF + ENABLE_ASH_ALIAS)) \ bb_error_msg_and_die("line:%d c:%d", __LINE__, (c)); \ - if ((syntax) < 0 || (syntax) > (2 + ENABLE_SH_MATH_SUPPORT)) \ + if ((syntax) < 0 || (syntax) > (2 + ENABLE_FEATURE_SH_MATH)) \ bb_error_msg_and_die("line:%d c:%d", __LINE__, (c)); \ ((S_I_T[syntax_index_table[c]] >> ((syntax)*4)) & 0xf); \ }) @@ -4487,7 +4493,7 @@ cmdputs(const char *s) case CTLBACKQ: str = "$(...)"; goto dostr; -#if ENABLE_SH_MATH_SUPPORT +#if ENABLE_FEATURE_SH_MATH case CTLARI: str = "$(("; goto dostr; @@ -5547,7 +5553,7 @@ redirectsafe(union node *redir, int flags) * We have to deal with backquotes, shell variables, and file metacharacters. */ -#if ENABLE_SH_MATH_SUPPORT +#if ENABLE_FEATURE_SH_MATH static arith_t ash_arith(const char *s) { @@ -5635,7 +5641,7 @@ static struct arglist exparg; /* * Our own itoa(). */ -#if !ENABLE_SH_MATH_SUPPORT +#if !ENABLE_FEATURE_SH_MATH /* cvtnum() is used even if math support is off (to prepare $? values and such) */ typedef long arith_t; # define ARITH_FMT "%ld" @@ -6148,7 +6154,7 @@ expbackq(union node *cmd, int flag) stackblock() + startloc)); } -#if ENABLE_SH_MATH_SUPPORT +#if ENABLE_FEATURE_SH_MATH /* * Expand arithmetic expression. Backup to start of expression, * evaluate, place result in (backed up) result, adjust string position. @@ -6230,7 +6236,7 @@ argstr(char *p, int flags, struct strlist *var_str_list) CTLESC, CTLVAR, CTLBACKQ, -#if ENABLE_SH_MATH_SUPPORT +#if ENABLE_FEATURE_SH_MATH CTLENDARI, #endif '\0' @@ -6266,7 +6272,7 @@ argstr(char *p, int flags, struct strlist *var_str_list) c = p[length]; if (c) { if (!(c & 0x80) - IF_SH_MATH_SUPPORT(|| c == CTLENDARI) + IF_FEATURE_SH_MATH(|| c == CTLENDARI) ) { /* c == '=' || c == ':' || c == CTLENDARI */ length++; @@ -6346,7 +6352,7 @@ argstr(char *p, int flags, struct strlist *var_str_list) expbackq(argbackq->n, flags | inquotes); argbackq = argbackq->next; goto start; -#if ENABLE_SH_MATH_SUPPORT +#if ENABLE_FEATURE_SH_MATH case CTLENDARI: p--; expari(flags | inquotes); @@ -9265,7 +9271,7 @@ static int helpcmd(int, char **) FAST_FUNC; #if MAX_HISTORY static int historycmd(int, char **) FAST_FUNC; #endif -#if ENABLE_SH_MATH_SUPPORT +#if ENABLE_FEATURE_SH_MATH static int letcmd(int, char **) FAST_FUNC; #endif static int readcmd(int, char **) FAST_FUNC; @@ -9345,7 +9351,7 @@ static const struct builtincmd builtintab[] = { { BUILTIN_REGULAR "jobs" , jobscmd }, { BUILTIN_REGULAR "kill" , killcmd }, #endif -#if ENABLE_SH_MATH_SUPPORT +#if ENABLE_FEATURE_SH_MATH { BUILTIN_NOSPEC "let" , letcmd }, #endif { BUILTIN_ASSIGN "local" , localcmd }, @@ -11394,13 +11400,13 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs) smallint quotef; smallint dblquote; smallint oldstyle; - IF_SH_MATH_SUPPORT(smallint prevsyntax;) /* syntax before arithmetic */ + IF_FEATURE_SH_MATH(smallint prevsyntax;) /* syntax before arithmetic */ #if ENABLE_ASH_EXPAND_PRMT smallint pssyntax; /* we are expanding a prompt string */ #endif int varnest; /* levels of variables expansion */ - IF_SH_MATH_SUPPORT(int arinest;) /* levels of arithmetic expansion */ - IF_SH_MATH_SUPPORT(int parenlevel;) /* levels of parens in arithmetic */ + IF_FEATURE_SH_MATH(int arinest;) /* levels of arithmetic expansion */ + IF_FEATURE_SH_MATH(int parenlevel;) /* levels of parens in arithmetic */ int dqvarnest; /* levels of variables expansion within double quotes */ IF_ASH_BASH_COMPAT(smallint bash_dollar_squote = 0;) @@ -11408,7 +11414,7 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs) startlinno = g_parsefile->linno; bqlist = NULL; quotef = 0; - IF_SH_MATH_SUPPORT(prevsyntax = 0;) + IF_FEATURE_SH_MATH(prevsyntax = 0;) #if ENABLE_ASH_EXPAND_PRMT pssyntax = (syntax == PSSYNTAX); if (pssyntax) @@ -11416,8 +11422,8 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs) #endif dblquote = (syntax == DQSYNTAX); varnest = 0; - IF_SH_MATH_SUPPORT(arinest = 0;) - IF_SH_MATH_SUPPORT(parenlevel = 0;) + IF_FEATURE_SH_MATH(arinest = 0;) + IF_FEATURE_SH_MATH(parenlevel = 0;) dqvarnest = 0; STARTSTACKSTR(out); @@ -11524,7 +11530,7 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs) } USTPUTC(c, out); break; -#if ENABLE_SH_MATH_SUPPORT +#if ENABLE_FEATURE_SH_MATH case CLP: /* '(' in arithmetic */ parenlevel++; USTPUTC(c, out); @@ -11575,7 +11581,7 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs) } /* for (;;) */ endword: -#if ENABLE_SH_MATH_SUPPORT +#if ENABLE_FEATURE_SH_MATH if (syntax == ARISYNTAX) raise_error_syntax("missing '))'"); #endif @@ -11754,7 +11760,7 @@ parsesub: { } else if (c == '(') { /* $(command) or $((arith)) */ if (pgetc_eatbnl() == '(') { -#if ENABLE_SH_MATH_SUPPORT +#if ENABLE_FEATURE_SH_MATH PARSEARITH(); #else raise_error_syntax("you disabled math support for $((arith)) syntax"); @@ -12009,7 +12015,7 @@ parsebackq: { goto parsebackq_newreturn; } -#if ENABLE_SH_MATH_SUPPORT +#if ENABLE_FEATURE_SH_MATH /* * Parse an arithmetic expansion (indicate start of one and set state) */ @@ -13046,7 +13052,7 @@ timescmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) return 0; } -#if ENABLE_SH_MATH_SUPPORT +#if ENABLE_FEATURE_SH_MATH /* * The let builtin. Partially stolen from GNU Bash, the Bourne Again SHell. * Copyright (C) 1987, 1989, 1991 Free Software Foundation, Inc. @@ -13301,15 +13307,6 @@ init(void) //usage:#define ash_full_usage "\n\n" //usage: "Unix shell interpreter" -//usage:#if ENABLE_FEATURE_SH_IS_ASH -//usage:# define sh_trivial_usage ash_trivial_usage -//usage:# define sh_full_usage ash_full_usage -//usage:#endif -//usage:#if ENABLE_FEATURE_BASH_IS_ASH -//usage:# define bash_trivial_usage ash_trivial_usage -//usage:# define bash_full_usage ash_full_usage -//usage:#endif - /* * Process the shell command line arguments. */ diff --git a/shell/hush.c b/shell/hush.c index c5821259a..fecc89294 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -99,7 +99,7 @@ //config:config HUSH_BASH_COMPAT //config: bool "bash-compatible extensions" //config: default y -//config: depends on HUSH +//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH //config: help //config: Enable bash-compatible extensions. //config: @@ -113,14 +113,14 @@ //config:config HUSH_HELP //config: bool "help builtin" //config: default y -//config: depends on HUSH +//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH //config: help //config: Enable help builtin in hush. Code size + ~1 kbyte. //config: //config:config HUSH_INTERACTIVE //config: bool "Interactive mode" //config: default y -//config: depends on HUSH +//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH //config: help //config: Enable interactive mode (prompt and command editing). //config: Without this, hush simply reads and executes commands @@ -148,35 +148,35 @@ //config:config HUSH_TICK //config: bool "Process substitution" //config: default y -//config: depends on HUSH +//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH //config: help //config: Enable process substitution `command` and $(command) in hush. //config: //config:config HUSH_IF //config: bool "Support if/then/elif/else/fi" //config: default y -//config: depends on HUSH +//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH //config: help //config: Enable if/then/elif/else/fi in hush. //config: //config:config HUSH_LOOPS //config: bool "Support for, while and until loops" //config: default y -//config: depends on HUSH +//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH //config: help //config: Enable for, while and until loops in hush. //config: //config:config HUSH_CASE //config: bool "Support case ... esac statement" //config: default y -//config: depends on HUSH +//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH //config: help //config: Enable case ... esac statement in hush. +400 bytes. //config: //config:config HUSH_FUNCTIONS //config: bool "Support funcname() { commands; } syntax" //config: default y -//config: depends on HUSH +//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH //config: help //config: Enable support for shell functions in hush. +800 bytes. //config: @@ -190,7 +190,7 @@ //config:config HUSH_RANDOM_SUPPORT //config: bool "Pseudorandom generator and $RANDOM variable" //config: default y -//config: depends on HUSH +//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH //config: help //config: Enable pseudorandom generator and dynamic variable "$RANDOM". //config: Each read of "$RANDOM" will generate a new pseudorandom value. @@ -198,14 +198,14 @@ //config:config HUSH_EXPORT_N //config: bool "Support 'export -n' option" //config: default y -//config: depends on HUSH +//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH //config: help //config: export -n unexports variables. It is a bash extension. //config: //config:config HUSH_MODE_X //config: bool "Support 'hush -x' option and 'set -x' command" //config: default y -//config: depends on HUSH +//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH //config: help //config: This instructs hush to print commands before execution. //config: Adds ~300 bytes. @@ -216,14 +216,15 @@ //config: select HUSH //config: help //config: msh is deprecated and will be removed, please migrate to hush. -//config: //applet:IF_HUSH(APPLET(hush, BB_DIR_BIN, BB_SUID_DROP)) -//applet:IF_MSH(APPLET(msh, BB_DIR_BIN, BB_SUID_DROP)) -//applet:IF_FEATURE_SH_IS_HUSH(APPLET_ODDNAME(sh, hush, BB_DIR_BIN, BB_SUID_DROP, sh)) -//applet:IF_FEATURE_BASH_IS_HUSH(APPLET_ODDNAME(bash, hush, BB_DIR_BIN, BB_SUID_DROP, bash)) +//applet:IF_MSH(APPLET_ODDNAME(msh, hush, BB_DIR_BIN, BB_SUID_DROP, hush)) +//applet:IF_SH_IS_HUSH(APPLET_ODDNAME(sh, hush, BB_DIR_BIN, BB_SUID_DROP, hush)) +//applet:IF_BASH_IS_HUSH(APPLET_ODDNAME(bash, hush, BB_DIR_BIN, BB_SUID_DROP, hush)) //kbuild:lib-$(CONFIG_HUSH) += hush.o match.o shell_common.o +//kbuild:lib-$(CONFIG_SH_IS_HUSH) += hush.o match.o shell_common.o +//kbuild:lib-$(CONFIG_BASH_IS_HUSH) += hush.o match.o shell_common.o //kbuild:lib-$(CONFIG_HUSH_RANDOM_SUPPORT) += random.o /* -i (interactive) and -s (read stdin) are also accepted, @@ -236,18 +237,6 @@ //usage:#define hush_full_usage "\n\n" //usage: "Unix shell interpreter" -//usage:#define msh_trivial_usage hush_trivial_usage -//usage:#define msh_full_usage hush_full_usage - -//usage:#if ENABLE_FEATURE_SH_IS_HUSH -//usage:# define sh_trivial_usage hush_trivial_usage -//usage:# define sh_full_usage hush_full_usage -//usage:#endif -//usage:#if ENABLE_FEATURE_BASH_IS_HUSH -//usage:# define bash_trivial_usage hush_trivial_usage -//usage:# define bash_full_usage hush_full_usage -//usage:#endif - #if !(defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) \ || defined(__APPLE__) \ ) @@ -4011,7 +4000,7 @@ static int i_peek_and_eat_bkslash_nl(struct in_str *input) } } -#if ENABLE_HUSH_TICK || ENABLE_SH_MATH_SUPPORT || ENABLE_HUSH_DOLLAR_OPS +#if ENABLE_HUSH_TICK || ENABLE_FEATURE_SH_MATH || ENABLE_HUSH_DOLLAR_OPS /* Subroutines for copying $(...) and `...` things */ static int add_till_backquote(o_string *dest, struct in_str *input, int in_dquote); /* '...' */ @@ -4179,7 +4168,7 @@ static int add_till_closing_bracket(o_string *dest, struct in_str *input, unsign } return ch; } -#endif /* ENABLE_HUSH_TICK || ENABLE_SH_MATH_SUPPORT || ENABLE_HUSH_DOLLAR_OPS */ +#endif /* ENABLE_HUSH_TICK || ENABLE_FEATURE_SH_MATH || ENABLE_HUSH_DOLLAR_OPS */ /* Return code: 0 for OK, 1 for syntax error */ #if BB_MMU @@ -4333,13 +4322,13 @@ static int parse_dollar(o_string *as_string, o_addchr(dest, SPECIAL_VAR_SYMBOL); break; } -#if ENABLE_SH_MATH_SUPPORT || ENABLE_HUSH_TICK +#if ENABLE_FEATURE_SH_MATH || ENABLE_HUSH_TICK case '(': { unsigned pos; ch = i_getch(input); nommu_addchr(as_string, ch); -# if ENABLE_SH_MATH_SUPPORT +# if ENABLE_FEATURE_SH_MATH if (i_peek_and_eat_bkslash_nl(input) == '(') { ch = i_getch(input); nommu_addchr(as_string, ch); @@ -5217,7 +5206,7 @@ static char *encode_then_expand_string(const char *str, int process_bkslash, int return exp_str; } -#if ENABLE_SH_MATH_SUPPORT +#if ENABLE_FEATURE_SH_MATH static arith_t expand_and_evaluate_arith(const char *arg, const char **errmsg_p) { arith_state_t math_state; @@ -5469,7 +5458,7 @@ static NOINLINE const char *expand_one_var(char **to_be_freed_pp, char *arg, cha } #endif else if (exp_op == ':') { -#if ENABLE_HUSH_BASH_COMPAT && ENABLE_SH_MATH_SUPPORT +#if ENABLE_HUSH_BASH_COMPAT && ENABLE_FEATURE_SH_MATH /* It's ${var:N[:M]} bashism. * Note that in encoded form it has TWO parts: * var:NM @@ -5604,7 +5593,7 @@ static NOINLINE int expand_vars_to_list(o_string *output, int n, char *arg) #if ENABLE_HUSH_TICK o_string subst_result = NULL_O_STRING; #endif -#if ENABLE_SH_MATH_SUPPORT +#if ENABLE_FEATURE_SH_MATH char arith_buf[sizeof(arith_t)*3 + 2]; #endif @@ -5698,7 +5687,7 @@ static NOINLINE int expand_vars_to_list(o_string *output, int n, char *arg) val = subst_result.data; goto store_val; #endif -#if ENABLE_SH_MATH_SUPPORT +#if ENABLE_FEATURE_SH_MATH case '+': { /* +cmd */ arith_t res; diff --git a/shell/math.h b/shell/math.h index 864bee691..32e1ffe35 100644 --- a/shell/math.h +++ b/shell/math.h @@ -63,7 +63,7 @@ PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN -#if ENABLE_SH_MATH_SUPPORT_64 +#if ENABLE_FEATURE_SH_MATH_64 typedef long long arith_t; #define ARITH_FMT "%lld" #define strto_arith_t strtoull -- cgit v1.2.3-55-g6feb From ea7d2f6ec0596789fc5b2e3fca3b7a602bfa2c26 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Tue, 3 Jan 2017 11:18:23 +0100 Subject: ash: fix error code regression The commit 'ash,hush: set exit code 127 in "sh /does/not/exist" case' only partly implemented the dash commit '[ERROR] Allow the originator of EXERROR to set the exit status'. This resulted in incorrect error codes for a syntax error: $ ) $ echo $? 0 or a redirection error for a special builtin: $ rm -f xxx $ eval cat Reported-by: Martijn Dekker Signed-off-by: Denys Vlasenko --- shell/ash.c | 8 ++++++-- shell/ash_test/ash-misc/exitcode2.right | 4 ++++ shell/ash_test/ash-misc/exitcode2.tests | 12 ++++++++++++ shell/hush_test/hush-misc/exitcode2.right | 4 ++++ shell/hush_test/hush-misc/exitcode2.tests | 12 ++++++++++++ 5 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 shell/ash_test/ash-misc/exitcode2.right create mode 100755 shell/ash_test/ash-misc/exitcode2.tests create mode 100644 shell/hush_test/hush-misc/exitcode2.right create mode 100755 shell/hush_test/hush-misc/exitcode2.tests (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index 430e42a7b..7c53946ce 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -1284,6 +1284,8 @@ ash_msg_and_raise_error(const char *msg, ...) { va_list ap; + exitstatus = 2; + va_start(ap, msg); ash_vmsg_and_raise(EXERROR, msg, ap); /* NOTREACHED */ @@ -9588,11 +9590,13 @@ evalcommand(union node *cmd, int flags) } if (status) { + bail: + exitstatus = status; + /* We have a redirection error. */ if (spclbltin > 0) raise_exception(EXERROR); - bail: - exitstatus = status; + goto out; } diff --git a/shell/ash_test/ash-misc/exitcode2.right b/shell/ash_test/ash-misc/exitcode2.right new file mode 100644 index 000000000..f7cb983c6 --- /dev/null +++ b/shell/ash_test/ash-misc/exitcode2.right @@ -0,0 +1,4 @@ +./test.sh: line 1: syntax error: unexpected ")" +Done:2 +./exitcode2.tests: line 11: can't open does_not_exist: no such file +Done:1 diff --git a/shell/ash_test/ash-misc/exitcode2.tests b/shell/ash_test/ash-misc/exitcode2.tests new file mode 100755 index 000000000..79a6ebd50 --- /dev/null +++ b/shell/ash_test/ash-misc/exitcode2.tests @@ -0,0 +1,12 @@ +# syntax error should return status 2 +cat >test.sh <test.sh < Date: Tue, 3 Jan 2017 11:47:50 +0100 Subject: hush: correct exitcode for unterminated ')' - exitcode2.tests testcase function old new delta parse_stream 2595 2609 +14 Signed-off-by: Denys Vlasenko --- shell/hush.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'shell') diff --git a/shell/hush.c b/shell/hush.c index fecc89294..a56d3b280 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -1137,6 +1137,9 @@ static void syntax_error_unexpected_ch(unsigned lineno UNUSED_PARAM, int ch) char msg[2]; msg[0] = ch; msg[1] = '\0'; +#if HUSH_DEBUG >= 2 + bb_error_msg("hush.c:%u", lineno); +#endif bb_error_msg("syntax error: unexpected %s", ch == EOF ? "EOF" : msg); } @@ -4997,7 +5000,8 @@ static struct pipe *parse_stream(char **pstring, * if we see {, we call parse_group(..., end_trigger='}') * and it will match } earlier (not here). */ syntax_error_unexpected_ch(ch); - goto parse_error; + G.last_exitcode = 2; + goto parse_error1; default: if (HUSH_DEBUG) bb_error_msg_and_die("BUG: unexpected %c\n", ch); @@ -5005,6 +5009,8 @@ static struct pipe *parse_stream(char **pstring, } /* while (1) */ parse_error: + G.last_exitcode = 1; + parse_error1: { struct parse_context *pctx; IF_HAS_KEYWORDS(struct parse_context *p2;) @@ -5038,7 +5044,6 @@ static struct pipe *parse_stream(char **pstring, } while (HAS_KEYWORDS && pctx); o_free(&dest); - G.last_exitcode = 1; #if !BB_MMU if (pstring) *pstring = NULL; -- cgit v1.2.3-55-g6feb