diff options
author | Ron Yorston <rmy@pobox.com> | 2024-04-09 12:43:48 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2024-04-09 12:43:48 +0100 |
commit | 7e09f7ce4e0d99b0e54684e5cc506e1532db392f (patch) | |
tree | 547d16627fbfd152abaed2c9d48da6ef68101ecf | |
parent | e1f73b64dcf047c9794f3546e3dc1b041a3660a6 (diff) | |
download | busybox-w32-7e09f7ce4e0d99b0e54684e5cc506e1532db392f.tar.gz busybox-w32-7e09f7ce4e0d99b0e54684e5cc506e1532db392f.tar.bz2 busybox-w32-7e09f7ce4e0d99b0e54684e5cc506e1532db392f.zip |
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)
-rw-r--r-- | shell/ash.c | 12 |
1 files 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) | |||
16235 | #endif | 16235 | #endif |
16236 | 16236 | ||
16237 | #if ENABLE_PLATFORM_MINGW32 | 16237 | #if ENABLE_PLATFORM_MINGW32 |
16238 | if (dirarg) { | 16238 | if (!dirarg && !login_sh && iflag) { |
16239 | chdir(dirarg); | ||
16240 | setpwd(NULL, 0); | ||
16241 | } | ||
16242 | else if (!login_sh && iflag) { | ||
16243 | char *cwd = getcwd(NULL, 0); | 16239 | char *cwd = getcwd(NULL, 0); |
16244 | if (cwd) { | 16240 | if (cwd) { |
16245 | chdir(cwd); | 16241 | chdir(cwd); |
@@ -16281,6 +16277,12 @@ int ash_main(int argc UNUSED_PARAM, char **argv) | |||
16281 | } | 16277 | } |
16282 | state2: | 16278 | state2: |
16283 | state = 3; | 16279 | state = 3; |
16280 | #if ENABLE_PLATFORM_MINGW32 | ||
16281 | if (dirarg) { | ||
16282 | chdir(dirarg); | ||
16283 | setpwd(NULL, 0); | ||
16284 | } | ||
16285 | #endif | ||
16284 | if (iflag | 16286 | if (iflag |
16285 | #if ENABLE_PLATFORM_POSIX | 16287 | #if ENABLE_PLATFORM_POSIX |
16286 | #ifndef linux | 16288 | #ifndef linux |