summaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDenys Vlasenko2018-01-12 13:21:33 +0100
committerDenys Vlasenko2018-01-12 13:21:33 +0100
commitcca7c611f26d98415c0f986e5a5e731ab5e379ff (patch)
treea080a096774447299f7772bc5c5e6a47d2a9ef0f /libbb
parent3bb3e1d0a1eed01306e22e59db8de6c2d945165a (diff)
downloadbusybox-cca7c611f26d98415c0f986e5a5e731ab5e379ff.zip
busybox-cca7c611f26d98415c0f986e5a5e731ab5e379ff.tar.gz
which: fix TODO with NOFORK+malloc_failure misbehaving
function old new delta find_executable 86 104 +18 which_main 202 194 -8 executable_exists 66 51 -15 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/2 up/down: 18/-23) Total: -5 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r--libbb/executable.c18
-rw-r--r--libbb/messages.c8
2 files changed, 11 insertions, 15 deletions
diff --git a/libbb/executable.c b/libbb/executable.c
index 325dd01..29d2a2c 100644
--- a/libbb/executable.c
+++ b/libbb/executable.c
@@ -25,7 +25,8 @@ int FAST_FUNC file_is_executable(const char *name)
* you may call find_executable again with this PATHp to continue
* (if it's not NULL).
* return NULL otherwise; (PATHp is undefined)
- * in all cases (*PATHp) contents will be trashed (s/:/NUL/).
+ * in all cases (*PATHp) contents are temporarily modified
+ * but are restored on return (s/:/NUL/ and back).
*/
char* FAST_FUNC find_executable(const char *filename, char **PATHp)
{
@@ -41,14 +42,17 @@ char* FAST_FUNC find_executable(const char *filename, char **PATHp)
p = *PATHp;
while (p) {
+ int ex;
+
n = strchr(p, ':');
- if (n)
- *n++ = '\0';
+ if (n) *n = '\0';
p = concat_path_file(
p[0] ? p : ".", /* handle "::" case */
filename
);
- if (file_is_executable(p)) {
+ ex = file_is_executable(p);
+ if (n) *n++ = ':';
+ if (ex) {
*PATHp = n;
return p;
}
@@ -64,10 +68,8 @@ char* FAST_FUNC find_executable(const char *filename, char **PATHp)
*/
int FAST_FUNC executable_exists(const char *filename)
{
- char *path = xstrdup(getenv("PATH"));
- char *tmp = path;
- char *ret = find_executable(filename, &tmp);
- free(path);
+ char *path = getenv("PATH");
+ char *ret = find_executable(filename, &path);
free(ret);
return ret != NULL;
}
diff --git a/libbb/messages.c b/libbb/messages.c
index 0a6cf3b..6914d57 100644
--- a/libbb/messages.c
+++ b/libbb/messages.c
@@ -6,11 +6,6 @@
*/
#include "libbb.h"
-/* allow default system PATH to be extended via CFLAGS */
-#ifndef BB_ADDITIONAL_PATH
-#define BB_ADDITIONAL_PATH ""
-#endif
-
/* allow version to be extended, via CFLAGS */
#ifndef BB_EXTRA_VERSION
#define BB_EXTRA_VERSION " ("AUTOCONF_TIMESTAMP")"
@@ -36,8 +31,7 @@ const char bb_busybox_exec_path[] ALIGN1 = CONFIG_BUSYBOX_EXEC_PATH;
const char bb_default_login_shell[] ALIGN1 = LIBBB_DEFAULT_LOGIN_SHELL;
/* util-linux manpage says /sbin:/bin:/usr/sbin:/usr/bin,
* but I want to save a few bytes here. Check libbb.h before changing! */
-const char bb_PATH_root_path[] ALIGN1 =
- "PATH=/sbin:/usr/sbin:/bin:/usr/bin" BB_ADDITIONAL_PATH;
+const char bb_PATH_root_path[] ALIGN1 = BB_PATH_ROOT_PATH;
//const int const_int_1 = 1;