From fff1c91e642f4d62e5dc542594e79b0972a3db78 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Mon, 8 Jul 2024 14:10:31 +0100 Subject: ash: read profile script relative to binary As well as trying to read '/etc/profile' also look for the script 'etc/profile' relative to the location of the running binary. Adds 64-96 bytes. --- include/mingw.h | 1 + miscutils/man.c | 5 ++--- shell/ash.c | 4 ++++ win32/mingw.c | 8 ++++++++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/include/mingw.h b/include/mingw.h index b0342337d..c4c2e199a 100644 --- a/include/mingw.h +++ b/include/mingw.h @@ -639,3 +639,4 @@ char *find_first_executable(const char *name); char *xappendword(const char *str, const char *word); int windows_env(void); void change_critical_error_dialogs(const char *newval) FAST_FUNC; +char *exe_relative_path(const char *tail); diff --git a/miscutils/man.c b/miscutils/man.c index c3efe4484..3954455b4 100644 --- a/miscutils/man.c +++ b/miscutils/man.c @@ -261,7 +261,7 @@ int man_main(int argc UNUSED_PARAM, char **argv) char *token[2]; #if ENABLE_PLATFORM_MINGW32 char **ptr; - char *exepath, *relpath; + char *relpath; const char *mpl[] = { "/usr/man", "/usr/share/man", NULL, NULL }; #endif @@ -316,8 +316,7 @@ int man_main(int argc UNUSED_PARAM, char **argv) #if ENABLE_PLATFORM_MINGW32 /* allow man pages to be stored relative to the executable */ - exepath = xstrdup(bb_busybox_exec_path); - relpath = concat_path_file(dirname(exepath), "man"); + relpath = exe_relative_path("man"); if (!man_path_list) { mpl[2] = relpath; diff --git a/shell/ash.c b/shell/ash.c index 881bc12ab..d9ab3feb5 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -16295,6 +16295,10 @@ int ash_main(int argc UNUSED_PARAM, char **argv) hp = concat_path_file(get_system_drive(), "/etc/profile"); read_profile(hp); free((void *)hp); + + hp = exe_relative_path("/etc/profile"); + read_profile(hp); + free((void *)hp); #else read_profile("/etc/profile"); #endif diff --git a/win32/mingw.c b/win32/mingw.c index 273b8d840..f2b025e43 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -2507,3 +2507,11 @@ change_critical_error_dialogs(const char *newval) SetErrorMode(newval && newval[0] == '1' && newval[1] == '\0' ? 0 : SEM_FAILCRITICALERRORS); } + +char *exe_relative_path(const char *tail) +{ + char *exepath = xstrdup(bb_busybox_exec_path); + char *relpath = concat_path_file(dirname(exepath), tail); + free(exepath); + return relpath; +} -- cgit v1.2.3-55-g6feb