diff options
author | Ron Yorston <rmy@pobox.com> | 2022-05-06 12:31:21 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2022-05-06 12:31:21 +0100 |
commit | ecdc5b3ffabb58e3a9fc3a55a2a44323644995fc (patch) | |
tree | 7a394f48dea0e8e5f47c4ab0eba84d2fb04a00b0 /libbb | |
parent | 26ba73098e714459e3294679228a1d54eed14799 (diff) | |
download | busybox-w32-ecdc5b3ffabb58e3a9fc3a55a2a44323644995fc.tar.gz busybox-w32-ecdc5b3ffabb58e3a9fc3a55a2a44323644995fc.tar.bz2 busybox-w32-ecdc5b3ffabb58e3a9fc3a55a2a44323644995fc.zip |
win32: allow preference for applets to be disabled at runtime
The default busybox-w32 configuration enables the PREFER_APPLETS
and SH_STANDALONE features. Sometimes it may be desirable to
override the default preference for applets, for example, if an
applet needs to be replaced by an external program with additional
features.
Add support for the environment variable BB_OVERRIDE_APPLETS.
Its value may be:
- a single dash ('-'): all applets are overridden;
- a space-separated list of names: only the specified applets
are overridden.
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/appletlib.c | 46 | ||||
-rw-r--r-- | libbb/lineedit.c | 2 |
2 files changed, 47 insertions, 1 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c index aa442144a..8d58ce2ea 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c | |||
@@ -76,6 +76,13 @@ static inline int *get_perrno(void) { return &errno; } | |||
76 | static const char packed_scripts[] ALIGN1 = { PACKED_SCRIPTS }; | 76 | static const char packed_scripts[] ALIGN1 = { PACKED_SCRIPTS }; |
77 | #endif | 77 | #endif |
78 | 78 | ||
79 | #if defined(find_applet_by_name) | ||
80 | # undef find_applet_by_name | ||
81 | #endif | ||
82 | #if defined(is_applet_preferred) | ||
83 | # undef is_applet_preferred | ||
84 | #endif | ||
85 | |||
79 | /* "Do not compress usage text if uncompressed text is small | 86 | /* "Do not compress usage text if uncompressed text is small |
80 | * and we don't include bunzip2 code for other reasons" | 87 | * and we don't include bunzip2 code for other reasons" |
81 | * | 88 | * |
@@ -254,6 +261,45 @@ int FAST_FUNC find_applet_by_name(const char *name) | |||
254 | return -1; | 261 | return -1; |
255 | } | 262 | } |
256 | 263 | ||
264 | #if ENABLE_PLATFORM_MINGW32 && NUM_APPLETS > 1 && \ | ||
265 | (ENABLE_FEATURE_PREFER_APPLETS || ENABLE_FEATURE_SH_STANDALONE) | ||
266 | int FAST_FUNC is_applet_preferred(const char *name) | ||
267 | { | ||
268 | const char *var, *s; | ||
269 | size_t len; | ||
270 | |||
271 | var = getenv("BB_OVERRIDE_APPLETS"); | ||
272 | if (var && *var) { | ||
273 | /* '-' overrides all applets */ | ||
274 | if (var[0] == '-' && var[1] == '\0') | ||
275 | return FALSE; | ||
276 | |||
277 | /* Override applets from a space-separated list */ | ||
278 | len = strlen(name); | ||
279 | s = var - 1; | ||
280 | while (1) { | ||
281 | s = strstr(s + 1, name); | ||
282 | if (!s) | ||
283 | break; | ||
284 | /* neither "name.." nor "xxx,name.."? */ | ||
285 | if (s != var && s[-1] != ' ') | ||
286 | continue; | ||
287 | /* neither "..name" nor "..name,xxx"? */ | ||
288 | if (s[len] != '\0' && s[len] != ' ') | ||
289 | continue; | ||
290 | return FALSE; | ||
291 | } | ||
292 | } | ||
293 | return TRUE; | ||
294 | } | ||
295 | |||
296 | int FAST_FUNC find_preferred_applet_by_name(const char *name) | ||
297 | { | ||
298 | int applet_no = find_applet_by_name(name); | ||
299 | return applet_no >= 0 && is_applet_preferred(name) ? applet_no : -1; | ||
300 | } | ||
301 | #endif | ||
302 | |||
257 | 303 | ||
258 | void lbb_prepare(const char *applet | 304 | void lbb_prepare(const char *applet |
259 | IF_FEATURE_INDIVIDUAL(, char **argv)) | 305 | IF_FEATURE_INDIVIDUAL(, char **argv)) |
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 778511d16..4f68547eb 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
@@ -926,7 +926,7 @@ static NOINLINE unsigned complete_cmd_dir_file(const char *command, int type) | |||
926 | # if ENABLE_FEATURE_SH_STANDALONE && NUM_APPLETS != 1 | 926 | # if ENABLE_FEATURE_SH_STANDALONE && NUM_APPLETS != 1 |
927 | const char *p = applet_names; | 927 | const char *p = applet_names; |
928 | while (*p) { | 928 | while (*p) { |
929 | if (strncmp(basecmd, p, baselen) == 0) | 929 | if (strncmp(basecmd, p, baselen) == 0 && is_applet_preferred(p)) |
930 | add_match(xstrdup(p)); | 930 | add_match(xstrdup(p)); |
931 | while (*p++ != '\0') | 931 | while (*p++ != '\0') |
932 | continue; | 932 | continue; |