diff options
-rw-r--r-- | libbb/appletlib.c | 27 | ||||
-rw-r--r-- | win32/process.c | 12 |
2 files changed, 23 insertions, 16 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; |
diff --git a/win32/process.c b/win32/process.c index a7074ec75..2f8b6ce31 100644 --- a/win32/process.c +++ b/win32/process.c | |||
@@ -153,16 +153,8 @@ quote_arg(const char *arg) | |||
153 | char * | 153 | char * |
154 | find_first_executable(const char *name) | 154 | find_first_executable(const char *name) |
155 | { | 155 | { |
156 | char *tmp, *path = getenv("PATH"); | 156 | char *path = getenv("PATH"); |
157 | char *exe_path = NULL; | 157 | return find_executable(name, &path); |
158 | |||
159 | if (path) { | ||
160 | tmp = path = xstrdup(path); | ||
161 | exe_path = find_executable(name, &tmp); | ||
162 | free(path); | ||
163 | } | ||
164 | |||
165 | return exe_path; | ||
166 | } | 158 | } |
167 | 159 | ||
168 | static intptr_t | 160 | static intptr_t |