diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2020-06-24 13:39:13 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2020-06-24 15:05:22 +0200 |
commit | 67e1529b921416d6c3f33fb43691bc9919e3eacc (patch) | |
tree | 874946bf7b52062d7496ea612b62f1cfe95f864f | |
parent | d5314e71294d228cff5d86e00d15661461f68fc9 (diff) |
nologin: make it possible to build it as single applet
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | libbb/appletlib.c | 38 | ||||
-rw-r--r-- | shell/Config.src | 20 | ||||
-rw-r--r-- | shell/ash.c | 41 | ||||
-rw-r--r-- | shell/hush.c | 73 | ||||
-rw-r--r-- | util-linux/nologin.c | 2 |
5 files changed, 110 insertions, 64 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c index f842e73cc..a515c3fe3 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c @@ -754,7 +754,9 @@ static void install_links(const char *busybox UNUSED_PARAM, } # endif +# if ENABLE_BUSYBOX || NUM_APPLETS > 0 static void run_applet_and_exit(const char *name, char **argv) NORETURN; +#endif # if NUM_SCRIPTS > 0 static int find_script_by_name(const char *name) @@ -775,13 +777,13 @@ int scripted_main(int argc UNUSED_PARAM, char **argv) { int script = find_script_by_name(applet_name); if (script >= 0) -#if ENABLE_ASH || ENABLE_SH_IS_ASH || ENABLE_BASH_IS_ASH +# if ENABLE_SHELL_ASH exit(ash_main(-script - 1, argv)); -#elif ENABLE_HUSH || ENABLE_SH_IS_HUSH || ENABLE_BASH_IS_HUSH +# elif ENABLE_SHELL_HUSH exit(hush_main(-script - 1, argv)); -#else +# else return 1; -#endif +# endif return 0; } @@ -1024,7 +1026,33 @@ static NORETURN void run_applet_and_exit(const char *name, char **argv) } # endif -#endif /* !defined(SINGLE_APPLET_MAIN) */ +#else /* defined(SINGLE_APPLET_MAIN) */ + +# if NUM_SCRIPTS > 0 +/* if SINGLE_APPLET_MAIN, these two functions are simpler: */ +int scripted_main(int argc UNUSED_PARAM, char **argv) MAIN_EXTERNALLY_VISIBLE; +int scripted_main(int argc UNUSED_PARAM, char **argv) +{ +# if ENABLE_SHELL_ASH + int script = 0; + exit(ash_main(-script - 1, argv)); +# elif ENABLE_SHELL_HUSH + int script = 0; + exit(hush_main(-script - 1, argv)); +# else + return 1; +# endif +} +char* FAST_FUNC +get_script_content(unsigned n UNUSED_PARAM) +{ + char *t = unpack_bz2_data(packed_scripts, sizeof(packed_scripts), + UNPACKED_SCRIPTS_LENGTH); + return t; +} +# endif /* NUM_SCRIPTS > 0 */ + +#endif /* defined(SINGLE_APPLET_MAIN) */ #if ENABLE_BUILD_LIBBUSYBOX diff --git a/shell/Config.src b/shell/Config.src index d7623f774..5efbf9995 100644 --- a/shell/Config.src +++ b/shell/Config.src @@ -17,6 +17,7 @@ choice config SH_IS_ASH depends on !NOMMU bool "ash" + select SHELL_ASH help Choose ash to be the shell executed by 'sh' name. The ash code will be built into busybox. If you don't select @@ -25,6 +26,7 @@ config SH_IS_ASH config SH_IS_HUSH bool "hush" + select SHELL_HUSH help Choose hush to be the shell executed by 'sh' name. The hush code will be built into busybox. If you don't select @@ -57,6 +59,7 @@ choice config BASH_IS_ASH depends on !NOMMU bool "ash" + select SHELL_ASH help Choose ash to be the shell executed by 'bash' name. The ash code will be built into busybox. If you don't select @@ -65,6 +68,7 @@ config BASH_IS_ASH config BASH_IS_HUSH bool "hush" + select SHELL_HUSH help Choose hush to be the shell executed by 'bash' name. The hush code will be built into busybox. If you don't select @@ -81,12 +85,12 @@ INSERT comment "Options common to all shells" -if ASH || HUSH || SH_IS_ASH || BASH_IS_ASH || SH_IS_HUSH || BASH_IS_HUSH +if SHELL_ASH || SHELL_HUSH config FEATURE_SH_MATH bool "POSIX math support" default y - depends on ASH || HUSH || SH_IS_ASH || BASH_IS_ASH || SH_IS_HUSH || BASH_IS_HUSH + depends on SHELL_ASH || SHELL_HUSH help Enable math support in the shell via $((...)) syntax. @@ -107,14 +111,14 @@ config FEATURE_SH_MATH_BASE config FEATURE_SH_EXTRA_QUIET bool "Hide message on interactive shell startup" default y - depends on ASH || HUSH || SH_IS_ASH || BASH_IS_ASH || SH_IS_HUSH || BASH_IS_HUSH + depends on SHELL_ASH || SHELL_HUSH help Remove the busybox introduction when starting a shell. config FEATURE_SH_STANDALONE bool "Standalone shell" default n - depends on ASH || HUSH || SH_IS_ASH || BASH_IS_ASH || SH_IS_HUSH || BASH_IS_HUSH + depends on SHELL_ASH || SHELL_HUSH help This option causes busybox shells to use busybox applets in preference to executables in the PATH whenever possible. For @@ -135,7 +139,7 @@ config FEATURE_SH_STANDALONE config FEATURE_SH_NOFORK bool "Run 'nofork' applets directly" default n - depends on ASH || HUSH || SH_IS_ASH || BASH_IS_ASH || SH_IS_HUSH || BASH_IS_HUSH + depends on SHELL_ASH || SHELL_HUSH help This option causes busybox shells to not execute typical fork/exec/wait sequence, but call <applet>_main directly, @@ -153,14 +157,14 @@ config FEATURE_SH_NOFORK config FEATURE_SH_READ_FRAC bool "read -t N.NNN support (+110 bytes)" default y - depends on ASH || HUSH || SH_IS_ASH || BASH_IS_ASH || SH_IS_HUSH || BASH_IS_HUSH + depends on SHELL_ASH || SHELL_HUSH help Enable support for fractional second timeout in read builtin. config FEATURE_SH_HISTFILESIZE bool "Use $HISTFILESIZE" default y - depends on ASH || HUSH || SH_IS_ASH || BASH_IS_ASH || SH_IS_HUSH || BASH_IS_HUSH + depends on SHELL_ASH || SHELL_HUSH help This option makes busybox shells to use $HISTFILESIZE variable to set shell history size. Note that its max value is capped @@ -169,7 +173,7 @@ config FEATURE_SH_HISTFILESIZE config FEATURE_SH_EMBEDDED_SCRIPTS bool "Embed scripts in the binary" default y - depends on ASH || HUSH || SH_IS_ASH || BASH_IS_ASH || SH_IS_HUSH || BASH_IS_HUSH + depends on SHELL_ASH || SHELL_HUSH help Allow scripts to be compressed and embedded in the busybox binary. The scripts should be placed in the 'embed' directory diff --git a/shell/ash.c b/shell/ash.c index 2a4c839a7..ecb9b132b 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -15,10 +15,15 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +//config:config SHELL_ASH +//config: bool #hidden option +//config: depends on !NOMMU +//config: //config:config ASH //config: bool "ash (78 kb)" //config: default y //config: depends on !NOMMU +//config: select SHELL_ASH //config: help //config: The most complete and most pedantically correct shell included with //config: busybox. This shell is actually a derivative of the Debian 'dash' @@ -28,17 +33,17 @@ //config:# ash options //config:# note: Don't remove !NOMMU part in the next line; it would break //config:# menuconfig's indenting. -//config:if !NOMMU && (ASH || SH_IS_ASH || BASH_IS_ASH) +//config:if !NOMMU && (SHELL_ASH || ASH || SH_IS_ASH || BASH_IS_ASH) //config: //config:config ASH_OPTIMIZE_FOR_SIZE //config: bool "Optimize for size instead of speed" //config: default y -//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH +//config: depends on SHELL_ASH //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 || SH_IS_ASH || BASH_IS_ASH +//config: depends on SHELL_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" @@ -49,7 +54,7 @@ //config:config ASH_BASH_COMPAT //config: bool "bash-compatible extensions" //config: default y -//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH +//config: depends on SHELL_ASH //config: //config:config ASH_BASH_SOURCE_CURDIR //config: bool "'source' and '.' builtins search current directory after $PATH" @@ -70,17 +75,17 @@ //config:config ASH_JOB_CONTROL //config: bool "Job control" //config: default y -//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH +//config: depends on SHELL_ASH //config: //config:config ASH_ALIAS //config: bool "Alias support" //config: default y -//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH +//config: depends on SHELL_ASH //config: //config:config ASH_RANDOM_SUPPORT //config: bool "Pseudorandom generator and $RANDOM variable" //config: default y -//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH +//config: depends on SHELL_ASH //config: help //config: Enable pseudorandom generator and dynamic variable "$RANDOM". //config: Each read of "$RANDOM" will generate a new pseudorandom value. @@ -91,7 +96,7 @@ //config:config ASH_EXPAND_PRMT //config: bool "Expand prompt string" //config: default y -//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH +//config: depends on SHELL_ASH //config: help //config: $PS# may contain volatile content, such as backquote commands. //config: This option recreates the prompt string from the environment @@ -100,14 +105,14 @@ //config:config ASH_IDLE_TIMEOUT //config: bool "Idle timeout variable $TMOUT" //config: default y -//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH +//config: depends on SHELL_ASH //config: help //config: Enable bash-like auto-logout after $TMOUT seconds of idle time. //config: //config:config ASH_MAIL //config: bool "Check for new mail in interactive shell" //config: default y -//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH +//config: depends on SHELL_ASH //config: help //config: Enable "check for new mail" function: //config: if set, $MAIL file and $MAILPATH list of files @@ -117,32 +122,32 @@ //config:config ASH_ECHO //config: bool "echo builtin" //config: default y -//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH +//config: depends on SHELL_ASH //config: //config:config ASH_PRINTF //config: bool "printf builtin" //config: default y -//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH +//config: depends on SHELL_ASH //config: //config:config ASH_TEST //config: bool "test builtin" //config: default y -//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH +//config: depends on SHELL_ASH //config: //config:config ASH_HELP //config: bool "help builtin" //config: default y -//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH +//config: depends on SHELL_ASH //config: //config:config ASH_GETOPTS //config: bool "getopts builtin" //config: default y -//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH +//config: depends on SHELL_ASH //config: //config:config ASH_CMDCMD //config: bool "command builtin" //config: default y -//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH +//config: depends on SHELL_ASH //config: help //config: Enable support for the 'command' builtin, which allows //config: you to run the specified command or builtin, @@ -155,9 +160,7 @@ //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_SHELL_ASH) += ash.o ash_ptr_hack.o shell_common.o //kbuild:lib-$(CONFIG_ASH_RANDOM_SUPPORT) += random.o /* diff --git a/shell/hush.c b/shell/hush.c index 2cf2170ca..e9cec1cc9 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -95,6 +95,7 @@ //config:config HUSH //config: bool "hush (68 kb)" //config: default y +//config: select SHELL_HUSH //config: help //config: hush is a small shell. It handles the normal flow control //config: constructs such as if/then/elif/else/fi, for/in/do/done, while loops, @@ -106,10 +107,20 @@ //config: It does not handle select, aliases, tilde expansion, //config: &>file and >&file redirection of stdout+stderr. //config: +// This option is visible (has a description) to make it possible to select +// a "scripted" applet (such as NOLOGIN) but avoid selecting any shells: +//config:config SHELL_HUSH +//config: bool "Internal shell for embedded script support" +//config: default n +//config: +//config:# hush options +//config:# It's only needed to get "nice" menuconfig indenting. +//config:if SHELL_HUSH || HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: //config:config HUSH_BASH_COMPAT //config: bool "bash-compatible extensions" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_BRACE_EXPANSION //config: bool "Brace expansion" @@ -133,7 +144,7 @@ //config:config HUSH_INTERACTIVE //config: bool "Interactive mode" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: help //config: Enable interactive mode (prompt and command editing). //config: Without this, hush simply reads and executes commands @@ -159,31 +170,31 @@ //config:config HUSH_TICK //config: bool "Support command substitution" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: help //config: Enable `command` and $(command). //config: //config:config HUSH_IF //config: bool "Support if/then/elif/else/fi" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_LOOPS //config: bool "Support for, while and until loops" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_CASE //config: bool "Support case ... esac statement" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: help //config: Enable case ... esac statement. +400 bytes. //config: //config:config HUSH_FUNCTIONS //config: bool "Support funcname() { commands; } syntax" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: help //config: Enable support for shell functions. +800 bytes. //config: @@ -197,7 +208,7 @@ //config:config HUSH_RANDOM_SUPPORT //config: bool "Pseudorandom generator and $RANDOM variable" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: help //config: Enable pseudorandom generator and dynamic variable "$RANDOM". //config: Each read of "$RANDOM" will generate a new pseudorandom value. @@ -205,7 +216,7 @@ //config:config HUSH_MODE_X //config: bool "Support 'hush -x' option and 'set -x' command" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: help //config: This instructs hush to print commands before execution. //config: Adds ~300 bytes. @@ -213,27 +224,27 @@ //config:config HUSH_ECHO //config: bool "echo builtin" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_PRINTF //config: bool "printf builtin" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_TEST //config: bool "test builtin" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_HELP //config: bool "help builtin" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_EXPORT //config: bool "export builtin" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_EXPORT_N //config: bool "Support 'export -n' option" @@ -245,83 +256,83 @@ //config:config HUSH_READONLY //config: bool "readonly builtin" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: help //config: Enable support for read-only variables. //config: //config:config HUSH_KILL //config: bool "kill builtin (supports kill %jobspec)" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_WAIT //config: bool "wait builtin" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_COMMAND //config: bool "command builtin" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_TRAP //config: bool "trap builtin" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_TYPE //config: bool "type builtin" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_TIMES //config: bool "times builtin" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_READ //config: bool "read builtin" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_SET //config: bool "set builtin" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_UNSET //config: bool "unset builtin" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_ULIMIT //config: bool "ulimit builtin" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_UMASK //config: bool "umask builtin" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_GETOPTS //config: bool "getopts builtin" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_MEMLEAK //config: bool "memleak builtin (debugging)" //config: default n -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH +//config: +//config:endif # hush options //applet:IF_HUSH(APPLET(hush, BB_DIR_BIN, BB_SUID_DROP)) // APPLET_ODDNAME:name main location suid_type help //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_SHELL_HUSH) += hush.o match.o shell_common.o //kbuild:lib-$(CONFIG_HUSH_RANDOM_SUPPORT) += random.o /* -i (interactive) is also accepted, diff --git a/util-linux/nologin.c b/util-linux/nologin.c index 5e5e42305..5a8b047a5 100644 --- a/util-linux/nologin.c +++ b/util-linux/nologin.c @@ -7,7 +7,7 @@ //config: //config:config NOLOGIN_DEPENDENCIES //config: bool "Enable dependencies for nologin" -//config: default y +//config: default n # Y default makes it harder to select single-applet test //config: depends on NOLOGIN //config: select CAT //config: select ECHO |