diff options
-rw-r--r-- | loginutils/suw32.c | 7 | ||||
-rw-r--r-- | shell/ash.c | 33 |
2 files changed, 35 insertions, 5 deletions
diff --git a/loginutils/suw32.c b/loginutils/suw32.c index 3aa478f33..be1a5211e 100644 --- a/loginutils/suw32.c +++ b/loginutils/suw32.c | |||
@@ -28,6 +28,7 @@ int suw32_main(int argc UNUSED_PARAM, char **argv) | |||
28 | { | 28 | { |
29 | char *opt_command = NULL; | 29 | char *opt_command = NULL; |
30 | SHELLEXECUTEINFO info; | 30 | SHELLEXECUTEINFO info; |
31 | char *cwd; | ||
31 | 32 | ||
32 | getopt32(argv, "c:", &opt_command); | 33 | getopt32(argv, "c:", &opt_command); |
33 | if (argv[optind]) | 34 | if (argv[optind]) |
@@ -39,10 +40,12 @@ int suw32_main(int argc UNUSED_PARAM, char **argv) | |||
39 | /* info.hwnd = NULL; */ | 40 | /* info.hwnd = NULL; */ |
40 | info.lpVerb = "runas"; | 41 | info.lpVerb = "runas"; |
41 | info.lpFile = bb_busybox_exec_path; | 42 | info.lpFile = bb_busybox_exec_path; |
43 | cwd = getcwd(NULL, 0); | ||
42 | if (opt_command) | 44 | if (opt_command) |
43 | info.lpParameters = xasprintf("ash -s -c \"%s\"", opt_command); | 45 | info.lpParameters = |
46 | xasprintf("ash -d \"%s\" -s -c \"%s\"", cwd, opt_command); | ||
44 | else | 47 | else |
45 | info.lpParameters = "ash"; | 48 | info.lpParameters = xasprintf("ash -d \"%s\"", cwd); |
46 | /* info.lpDirectory = NULL; */ | 49 | /* info.lpDirectory = NULL; */ |
47 | info.nShow = SW_SHOWNORMAL; | 50 | info.nShow = SW_SHOWNORMAL; |
48 | 51 | ||
diff --git a/shell/ash.c b/shell/ash.c index b276544a6..b7fb29452 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -480,6 +480,9 @@ struct globals_misc { | |||
480 | int errlinno; | 480 | int errlinno; |
481 | 481 | ||
482 | char *minusc; /* argument to -c option */ | 482 | char *minusc; /* argument to -c option */ |
483 | #if ENABLE_PLATFORM_MINGW32 | ||
484 | char *dirarg; /* argument to -d option */ | ||
485 | #endif | ||
483 | 486 | ||
484 | char *curdir; // = nullstr; /* current working directory */ | 487 | char *curdir; // = nullstr; /* current working directory */ |
485 | char *physdir; // = nullstr; /* physical working directory */ | 488 | char *physdir; // = nullstr; /* physical working directory */ |
@@ -573,6 +576,9 @@ extern struct globals_misc *BB_GLOBAL_CONST ash_ptr_to_globals_misc; | |||
573 | #define loopnest (G_misc.loopnest ) | 576 | #define loopnest (G_misc.loopnest ) |
574 | #endif | 577 | #endif |
575 | #define minusc (G_misc.minusc ) | 578 | #define minusc (G_misc.minusc ) |
579 | #if ENABLE_PLATFORM_MINGW32 | ||
580 | #define dirarg (G_misc.dirarg ) | ||
581 | #endif | ||
576 | #define curdir (G_misc.curdir ) | 582 | #define curdir (G_misc.curdir ) |
577 | #define physdir (G_misc.physdir ) | 583 | #define physdir (G_misc.physdir ) |
578 | #define arg0 (G_misc.arg0 ) | 584 | #define arg0 (G_misc.arg0 ) |
@@ -11672,8 +11678,12 @@ options(int cmdline, int *login_sh) | |||
11672 | int val; | 11678 | int val; |
11673 | int c; | 11679 | int c; |
11674 | 11680 | ||
11675 | if (cmdline) | 11681 | if (cmdline) { |
11676 | minusc = NULL; | 11682 | minusc = NULL; |
11683 | #if ENABLE_PLATFORM_MINGW32 | ||
11684 | dirarg = NULL; | ||
11685 | #endif | ||
11686 | } | ||
11677 | while ((p = *argptr) != NULL) { | 11687 | while ((p = *argptr) != NULL) { |
11678 | c = *p++; | 11688 | c = *p++; |
11679 | if (c != '-' && c != '+') | 11689 | if (c != '-' && c != '+') |
@@ -11699,6 +11709,14 @@ options(int cmdline, int *login_sh) | |||
11699 | /* bash 3.2 indeed handles -c CMD and +c CMD the same */ | 11709 | /* bash 3.2 indeed handles -c CMD and +c CMD the same */ |
11700 | if (c == 'c' && cmdline) { | 11710 | if (c == 'c' && cmdline) { |
11701 | minusc = p; /* command is after shell args */ | 11711 | minusc = p; /* command is after shell args */ |
11712 | #if ENABLE_PLATFORM_MINGW32 | ||
11713 | /* Undocumented -d option to force current directory. | ||
11714 | * Must appear before -s or -c. */ | ||
11715 | } else if (c == 'd' && cmdline && val == 1) { | ||
11716 | if (*argptr == NULL) | ||
11717 | ash_msg_and_raise_error(bb_msg_requires_arg, "-d"); | ||
11718 | dirarg = *argptr++; | ||
11719 | #endif | ||
11702 | } else if (c == 'o') { | 11720 | } else if (c == 'o') { |
11703 | if (plus_minus_o(*argptr, val)) { | 11721 | if (plus_minus_o(*argptr, val)) { |
11704 | /* it already printed err message */ | 11722 | /* it already printed err message */ |
@@ -14956,12 +14974,21 @@ int ash_main(int argc UNUSED_PARAM, char **argv) | |||
14956 | hide_console(); | 14974 | hide_console(); |
14957 | #endif | 14975 | #endif |
14958 | 14976 | ||
14977 | #if ENABLE_PLATFORM_MINGW32 | ||
14978 | if (dirarg) { | ||
14979 | chdir(dirarg); | ||
14980 | setpwd(NULL, 0); | ||
14981 | } | ||
14982 | #endif | ||
14983 | |||
14959 | if (login_sh) { | 14984 | if (login_sh) { |
14960 | const char *hp; | 14985 | const char *hp; |
14961 | 14986 | ||
14962 | #if ENABLE_PLATFORM_MINGW32 | 14987 | #if ENABLE_PLATFORM_MINGW32 |
14963 | chdir(xgetpwuid(getuid())->pw_dir); | 14988 | if (!dirarg) { |
14964 | setpwd(NULL, 0); | 14989 | chdir(xgetpwuid(getuid())->pw_dir); |
14990 | setpwd(NULL, 0); | ||
14991 | } | ||
14965 | #endif | 14992 | #endif |
14966 | 14993 | ||
14967 | state = 1; | 14994 | state = 1; |