From 6bb25c4493268d24a3b82d3268b2adf624de88bd Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sat, 9 Dec 2023 09:43:06 +0000 Subject: win32: allow hardcoded list of applets to override The environment variable BB_OVERRIDE_APPLETS provides control over which applets are preferred in standalone shell mode. Allow a similar list to be hardcoded in the binary with the OVERRIDE_APPLETS configuration string. The environment variable is checked first. If it doesn't override the applet the hardcoded string is then checked too. The default for OVERRIDE_APPLETS is an empty string. In this case the size and behaviour of the binary is unchanged. --- Config.in | 10 ++++++++++ configs/mingw32_defconfig | 3 ++- configs/mingw64_defconfig | 3 ++- configs/mingw64u_defconfig | 3 ++- libbb/appletlib.c | 13 ++++++++++--- 5 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Config.in b/Config.in index 0da09c1cd..0a6d57327 100644 --- a/Config.in +++ b/Config.in @@ -556,6 +556,16 @@ config FEATURE_EXTRA_FILE_DATA determine the ownership of files so that, for example, 'ls' can distinguish files belonging to the current user. +config OVERRIDE_APPLETS + string "Override applets" + default "" + depends on PLATFORM_MINGW32 && (FEATURE_PREFER_APPLETS || FEATURE_SH_STANDALONE) + help + A list of applets to be ignored in standalone shell mode. The + format is the same as that used by the BB_OVERRIDE_APPLETS + environment variable. BB_OVERRIDE_APPLETS is checked first, if it + allows the applet and this list is non-empty it is checked too. + comment 'Build Options' config STATIC diff --git a/configs/mingw32_defconfig b/configs/mingw32_defconfig index 3a21dfae6..ee01330d1 100644 --- a/configs/mingw32_defconfig +++ b/configs/mingw32_defconfig @@ -1,7 +1,7 @@ # # Automatically generated make config: don't edit # Busybox version: 1.37.0.git -# Wed Sep 20 08:30:38 2023 +# Sat Dec 9 09:38:58 2023 # CONFIG_HAVE_DOT_CONFIG=y # CONFIG_PLATFORM_POSIX is not set @@ -61,6 +61,7 @@ CONFIG_FEATURE_EURO=y CONFIG_TERMINAL_MODE=5 CONFIG_FEATURE_IMPROVED_COLOUR_MAPPING=y CONFIG_FEATURE_EXTRA_FILE_DATA=y +CONFIG_OVERRIDE_APPLETS="" # # Build Options diff --git a/configs/mingw64_defconfig b/configs/mingw64_defconfig index 8b993460f..3fed1c99b 100644 --- a/configs/mingw64_defconfig +++ b/configs/mingw64_defconfig @@ -1,7 +1,7 @@ # # Automatically generated make config: don't edit # Busybox version: 1.37.0.git -# Wed Sep 20 08:30:38 2023 +# Sat Dec 9 09:38:58 2023 # CONFIG_HAVE_DOT_CONFIG=y # CONFIG_PLATFORM_POSIX is not set @@ -61,6 +61,7 @@ CONFIG_FEATURE_EURO=y CONFIG_TERMINAL_MODE=5 CONFIG_FEATURE_IMPROVED_COLOUR_MAPPING=y CONFIG_FEATURE_EXTRA_FILE_DATA=y +CONFIG_OVERRIDE_APPLETS="" # # Build Options diff --git a/configs/mingw64u_defconfig b/configs/mingw64u_defconfig index a7428d1d2..f3391a206 100644 --- a/configs/mingw64u_defconfig +++ b/configs/mingw64u_defconfig @@ -1,7 +1,7 @@ # # Automatically generated make config: don't edit # Busybox version: 1.37.0.git -# Wed Sep 20 08:30:38 2023 +# Sat Dec 9 09:38:58 2023 # CONFIG_HAVE_DOT_CONFIG=y # CONFIG_PLATFORM_POSIX is not set @@ -61,6 +61,7 @@ CONFIG_FEATURE_UTF8_OUTPUT=y CONFIG_TERMINAL_MODE=5 CONFIG_FEATURE_IMPROVED_COLOUR_MAPPING=y CONFIG_FEATURE_EXTRA_FILE_DATA=y +CONFIG_OVERRIDE_APPLETS="" # # Build Options diff --git a/libbb/appletlib.c b/libbb/appletlib.c index 6b610743a..3c9cebf1e 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c @@ -282,12 +282,11 @@ static int external_exists(const char *name) return ret != NULL; } -int FAST_FUNC is_applet_preferred(const char *name) +static int is_applet_preferred_by_var(const char *name, const char *var) { - const char *var, *s, *sep; + const char *s, *sep; size_t len; - var = getenv(BB_OVERRIDE_APPLETS); if (var && *var) { /* '-' disables all applets */ if (var[0] == '-' && var[1] == '\0') @@ -319,6 +318,14 @@ int FAST_FUNC is_applet_preferred(const char *name) } return TRUE; } + +int FAST_FUNC is_applet_preferred(const char *name) +{ + int ret = is_applet_preferred_by_var(name, getenv(BB_OVERRIDE_APPLETS)); + if (sizeof(CONFIG_OVERRIDE_APPLETS) > 1 && ret) + ret = is_applet_preferred_by_var(name, CONFIG_OVERRIDE_APPLETS); + return ret; +} #endif -- cgit v1.2.3-55-g6feb