diff options
author | Ron Yorston <rmy@pobox.com> | 2023-06-02 16:44:17 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2023-06-02 16:44:17 +0100 |
commit | 0a5ca0348b05f827032a57fac5d7732e464a0e46 (patch) | |
tree | fedd1e50274a148ccee8acbb494769489698a136 /libbb/appletlib.c | |
parent | bec2426878edb9b8553b4daa27cd34a8e230d465 (diff) | |
download | busybox-w32-0a5ca0348b05f827032a57fac5d7732e464a0e46.tar.gz busybox-w32-0a5ca0348b05f827032a57fac5d7732e464a0e46.tar.bz2 busybox-w32-0a5ca0348b05f827032a57fac5d7732e464a0e46.zip |
win32: change interpretation of BB_OVERRIDE_APPLETS
Make the following changes to BB_OVERRIDE_APPLETS:
- Applet names in the list can be separated by spaces, commas or
semicolons.
- Applets before the first semicolon are disabled unconditionally.
- Applets after the first semicolon are overridden if a matching
external command exists.
- '-' alone disables all applets.
- '+' alone overrides every applet for which a matching external
command exists.
This doesn't change the existing documented behaviour. It adds
the ability to have applets overridden if an external command
exists but to remain available if not.
Adds 80-88 bytes.
(GitHub issue #329)
Diffstat (limited to 'libbb/appletlib.c')
-rw-r--r-- | libbb/appletlib.c | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c index 379d6af2f..b5ea90ffd 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c | |||
@@ -263,18 +263,33 @@ int FAST_FUNC find_applet_by_name(const char *name) | |||
263 | 263 | ||
264 | #if ENABLE_PLATFORM_MINGW32 && NUM_APPLETS > 1 && \ | 264 | #if ENABLE_PLATFORM_MINGW32 && NUM_APPLETS > 1 && \ |
265 | (ENABLE_FEATURE_PREFER_APPLETS || ENABLE_FEATURE_SH_STANDALONE) | 265 | (ENABLE_FEATURE_PREFER_APPLETS || ENABLE_FEATURE_SH_STANDALONE) |
266 | static int external_exists(const char *name) | ||
267 | { | ||
268 | char *ret = find_first_executable(name); | ||
269 | free(ret); | ||
270 | return ret != NULL; | ||
271 | } | ||
272 | |||
266 | int FAST_FUNC is_applet_preferred(const char *name) | 273 | int FAST_FUNC is_applet_preferred(const char *name) |
267 | { | 274 | { |
268 | const char *var, *s; | 275 | const char *var, *s, *sep; |
269 | size_t len; | 276 | size_t len; |
270 | 277 | ||
271 | var = getenv(BB_OVERRIDE_APPLETS); | 278 | var = getenv(BB_OVERRIDE_APPLETS); |
272 | if (var && *var) { | 279 | if (var && *var) { |
273 | /* '-' overrides all applets */ | 280 | /* '-' disables all applets */ |
274 | if (var[0] == '-' && var[1] == '\0') | 281 | if (var[0] == '-' && var[1] == '\0') |
275 | return FALSE; | 282 | return FALSE; |
276 | 283 | ||
277 | /* Override applets from a space-separated list */ | 284 | /* '+' each applet is overridden if an external command exists */ |
285 | if (var[0] == '+' && var[1] == '\0') | ||
286 | return !external_exists(name); | ||
287 | |||
288 | /* Handle applets from a list separated by spaces, commas or | ||
289 | * semicolons. Applets before the first semicolon are disabled. | ||
290 | * Applets after the first semicolon are overridden if a | ||
291 | * corresponding external command exists. */ | ||
292 | sep = strchr(var, ';'); | ||
278 | len = strlen(name); | 293 | len = strlen(name); |
279 | s = var - 1; | 294 | s = var - 1; |
280 | while (1) { | 295 | while (1) { |
@@ -282,12 +297,12 @@ int FAST_FUNC is_applet_preferred(const char *name) | |||
282 | if (!s) | 297 | if (!s) |
283 | break; | 298 | break; |
284 | /* neither "name.." nor "xxx,name.."? */ | 299 | /* neither "name.." nor "xxx,name.."? */ |
285 | if (s != var && s[-1] != ' ') | 300 | if (s != var && !strchr(" ,;", s[-1])) |
286 | continue; | 301 | continue; |
287 | /* neither "..name" nor "..name,xxx"? */ | 302 | /* neither "..name" nor "..name,xxx"? */ |
288 | if (s[len] != '\0' && s[len] != ' ') | 303 | if (s[len] != '\0' && !strchr(" ,;", s[len])) |
289 | continue; | 304 | continue; |
290 | return FALSE; | 305 | return (sep == NULL || s < sep) ? FALSE : !external_exists(name); |
291 | } | 306 | } |
292 | } | 307 | } |
293 | return TRUE; | 308 | return TRUE; |