aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/libbb.h9
-rw-r--r--libbb/appletlib.c22
-rw-r--r--shell/ash.c19
3 files changed, 19 insertions, 31 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 1200e636a..5c4a01e8d 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1326,16 +1326,13 @@ void run_noexec_applet_and_exit(int a, const char *name, char **argv) NORETURN F
1326#ifndef BUILD_INDIVIDUAL 1326#ifndef BUILD_INDIVIDUAL
1327int find_applet_by_name(const char *name) FAST_FUNC; 1327int find_applet_by_name(const char *name) FAST_FUNC;
1328void run_applet_no_and_exit(int a, const char *name, char **argv) NORETURN FAST_FUNC; 1328void run_applet_no_and_exit(int a, const char *name, char **argv) NORETURN FAST_FUNC;
1329int find_preferred_applet_by_name(const char *name) FAST_FUNC;
1330int is_applet_preferred(const char *name) FAST_FUNC;
1331# if ENABLE_PLATFORM_MINGW32 && \ 1329# if ENABLE_PLATFORM_MINGW32 && \
1332 (ENABLE_FEATURE_PREFER_APPLETS || ENABLE_FEATURE_SH_STANDALONE) 1330 (ENABLE_FEATURE_PREFER_APPLETS || ENABLE_FEATURE_SH_STANDALONE)
1333# if ENABLE_ASH 1331int is_applet_preferred(const char *name) FAST_FUNC;
1334extern const char *ash_path; 1332const char *get_ash_path(void);
1335# endif
1336# define find_applet_by_name(n) find_preferred_applet_by_name(n)
1337# else 1333# else
1338# define is_applet_preferred(n) (1) 1334# define is_applet_preferred(n) (1)
1335# define get_ash_path() (NULL)
1339# endif 1336# endif
1340#endif 1337#endif
1341void show_usage_if_dash_dash_help(int applet_no, char **argv) FAST_FUNC; 1338void show_usage_if_dash_dash_help(int applet_no, char **argv) FAST_FUNC;
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index 10268b982..a378846b9 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -76,13 +76,6 @@ static inline int *get_perrno(void) { return &errno; }
76static const char packed_scripts[] ALIGN1 = { PACKED_SCRIPTS }; 76static 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
86/* "Do not compress usage text if uncompressed text is small 79/* "Do not compress usage text if uncompressed text is small
87 * and we don't include bunzip2 code for other reasons" 80 * and we don't include bunzip2 code for other reasons"
88 * 81 *
@@ -245,7 +238,7 @@ int FAST_FUNC find_applet_by_name(const char *name)
245 for (j = 0; *p == name[j]; ++j) { 238 for (j = 0; *p == name[j]; ++j) {
246 if (*p++ == '\0') { 239 if (*p++ == '\0') {
247 //bb_error_msg("found:'%s' i:%u", name, i); 240 //bb_error_msg("found:'%s' i:%u", name, i);
248 return i; /* yes */ 241 return is_applet_preferred(name) ? i : -1; /* yes */
249 } 242 }
250 } 243 }
251 /* No. Have we gone too far, alphabetically? */ 244 /* No. Have we gone too far, alphabetically? */
@@ -263,14 +256,9 @@ int FAST_FUNC find_applet_by_name(const char *name)
263 256
264#if ENABLE_PLATFORM_MINGW32 && NUM_APPLETS > 1 && \ 257#if ENABLE_PLATFORM_MINGW32 && NUM_APPLETS > 1 && \
265 (ENABLE_FEATURE_PREFER_APPLETS || ENABLE_FEATURE_SH_STANDALONE) 258 (ENABLE_FEATURE_PREFER_APPLETS || ENABLE_FEATURE_SH_STANDALONE)
266# if ENABLE_ASH
267const char *ash_path = NULL;
268# else
269# define ash_path NULL
270# endif
271
272static int external_exists(const char *name) 259static int external_exists(const char *name)
273{ 260{
261 const char *ash_path = get_ash_path();
274 char *path = ash_path ? auto_string(xstrdup(ash_path)) : getenv("PATH"); 262 char *path = ash_path ? auto_string(xstrdup(ash_path)) : getenv("PATH");
275 char *ret = find_executable(name, &path); 263 char *ret = find_executable(name, &path);
276 free(ret); 264 free(ret);
@@ -314,12 +302,6 @@ int FAST_FUNC is_applet_preferred(const char *name)
314 } 302 }
315 return TRUE; 303 return TRUE;
316} 304}
317
318int FAST_FUNC find_preferred_applet_by_name(const char *name)
319{
320 int applet_no = find_applet_by_name(name);
321 return applet_no >= 0 && is_applet_preferred(name) ? applet_no : -1;
322}
323#endif 305#endif
324 306
325 307
diff --git a/shell/ash.c b/shell/ash.c
index b29927a83..721204c61 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -428,13 +428,21 @@ static void forkshell_print(FILE *fp0, struct forkshell *fs, const char **notes)
428 428
429#if ENABLE_PLATFORM_MINGW32 && NUM_APPLETS > 1 && \ 429#if ENABLE_PLATFORM_MINGW32 && NUM_APPLETS > 1 && \
430 (ENABLE_FEATURE_PREFER_APPLETS || ENABLE_FEATURE_SH_STANDALONE) 430 (ENABLE_FEATURE_PREFER_APPLETS || ENABLE_FEATURE_SH_STANDALONE)
431static int 431static const char *ash_path;
432ash_preferred_applet_by_name(const char *name, const char *path) 432
433const char *
434get_ash_path(void)
435{
436 return ash_path;
437}
438
439static int NOINLINE
440ash_applet_by_name(const char *name, const char *path)
433{ 441{
434 int ret; 442 int ret;
435 443
436 ash_path = path; 444 ash_path = path;
437 ret = find_preferred_applet_by_name(name); 445 ret = find_applet_by_name(name);
438 ash_path = NULL; 446 ash_path = NULL;
439 447
440 return ret; 448 return ret;
@@ -451,11 +459,12 @@ ash_applet_preferred(const char *name, const char *path)
451 459
452 return ret; 460 return ret;
453} 461}
454# undef find_applet_by_name 462# define find_applet_by_name(n, p) ash_applet_by_name(n, p)
455# define find_applet_by_name(n, p) ash_preferred_applet_by_name(n, p)
456# define is_applet_preferred(n, p) ash_applet_preferred(n, p) 463# define is_applet_preferred(n, p) ash_applet_preferred(n, p)
457#else 464#else
458# define find_applet_by_name(n, p) find_applet_by_name(n) 465# define find_applet_by_name(n, p) find_applet_by_name(n)
466# undef is_applet_preferred
467# define is_applet_preferred(n, p) (1)
459#endif 468#endif
460 469
461/* ============ Hash table sizes. Configurable. */ 470/* ============ Hash table sizes. Configurable. */