From 7e09f7ce4e0d99b0e54684e5cc506e1532db392f Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Tue, 9 Apr 2024 12:43:48 +0100 Subject: ash: move setting of current directory The undocumented '-d' shell option is used to set the current directory in shells started by the 'su' applet of busybox-w32. In this case, the shell isn't a login shell. If a login shell sets the current working directory in /etc/profile it's possible the user may wish to override this with '-d'. This didn't work, though, because the directory is changed before /etc/profile is processed. Move the changing of the directory to that specified by '-d' so it happens after the processing of /etc/profile and ~/.profile. This won't affect the intended use of '-d'. (GitHub issue #403) --- shell/ash.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/shell/ash.c b/shell/ash.c index df27e9c8d..dc2115414 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -16235,11 +16235,7 @@ int ash_main(int argc UNUSED_PARAM, char **argv) #endif #if ENABLE_PLATFORM_MINGW32 - if (dirarg) { - chdir(dirarg); - setpwd(NULL, 0); - } - else if (!login_sh && iflag) { + if (!dirarg && !login_sh && iflag) { char *cwd = getcwd(NULL, 0); if (cwd) { chdir(cwd); @@ -16281,6 +16277,12 @@ int ash_main(int argc UNUSED_PARAM, char **argv) } state2: state = 3; +#if ENABLE_PLATFORM_MINGW32 + if (dirarg) { + chdir(dirarg); + setpwd(NULL, 0); + } +#endif if (iflag #if ENABLE_PLATFORM_POSIX #ifndef linux -- cgit v1.2.3-55-g6feb