aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2012-04-26 14:57:13 +0100
committerRon Yorston <rmy@pobox.com>2012-04-26 14:57:13 +0100
commitfd571d9c7525247c0cdcf154f547d4658df0837e (patch)
treef769b962ac4a6652961e04075b54e81c362afe34 /shell
parent591378ff82a3dcbd0bdccf7a6f7ffb70090a4b35 (diff)
downloadbusybox-w32-fd571d9c7525247c0cdcf154f547d4658df0837e.tar.gz
busybox-w32-fd571d9c7525247c0cdcf154f547d4658df0837e.tar.bz2
busybox-w32-fd571d9c7525247c0cdcf154f547d4658df0837e.zip
ash: set working directory and environment on first startup
Diffstat (limited to 'shell')
-rw-r--r--shell/ash.c45
1 files changed, 21 insertions, 24 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 8c39a504a..f7c12f8e1 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -13508,27 +13508,43 @@ init(void)
13508 * 13508 *
13509 * We may end up having both Path and PATH. Then Path will be chosen 13509 * We may end up having both Path and PATH. Then Path will be chosen
13510 * because it appears first. 13510 * because it appears first.
13511 *
13512 * Also, replace backslashes with forward slashes.
13513 */ 13511 */
13514 for (envp = environ; envp && *envp; envp++) 13512 for (envp = environ; envp && *envp; envp++) {
13515 if (!strncasecmp(*envp, "PATH=", 5) && 13513 if (strncasecmp(*envp, "PATH=", 5) == 0 &&
13516 strncmp(*envp, "PATH=", 5)) 13514 strncmp(*envp, "PATH=", 5) != 0) {
13517 break; 13515 break;
13516 }
13517 }
13518
13518 if (envp && *envp) { 13519 if (envp && *envp) {
13520 /*
13521 * If we get here it's because the environment contains a path
13522 * variable called something other than PATH. This suggests we
13523 * haven't been invoked from an earlier instance of BusyBox.
13524 */
13519 char *start, *end; 13525 char *start, *end;
13526 struct passwd *pw;
13527
13520 for (envp = environ; envp && *envp; envp++) { 13528 for (envp = environ; envp && *envp; envp++) {
13521 end = strchr(*envp, '='); 13529 end = strchr(*envp, '=');
13522 if (!end) 13530 if (!end)
13523 continue; 13531 continue;
13532
13533 /* make all variable names uppercase */
13524 for (start = *envp;start < end;start++) 13534 for (start = *envp;start < end;start++)
13525 *start = toupper(*start); 13535 *start = toupper(*start);
13536
13537 /* convert backslashes to forward slashes */
13526 for ( ++end; *end; ++end ) { 13538 for ( ++end; *end; ++end ) {
13527 if ( *end == '\\' ) { 13539 if ( *end == '\\' ) {
13528 *end = '/'; 13540 *end = '/';
13529 } 13541 }
13530 } 13542 }
13531 } 13543 }
13544
13545 /* some initialisation normally performed at login */
13546 pw = xgetpwuid(getuid());
13547 setup_environment(pw->pw_shell, SETUP_ENV_CHANGEENV, pw);
13532 } 13548 }
13533#endif 13549#endif
13534 for (envp = environ; envp && *envp; envp++) { 13550 for (envp = environ; envp && *envp; envp++) {
@@ -13537,25 +13553,6 @@ init(void)
13537 } 13553 }
13538 } 13554 }
13539 13555
13540#if ENABLE_PLATFORM_MINGW32
13541 p = lookupvar("HOME");
13542 if (!p) {
13543 const char *hd, *hp;
13544
13545 hd = lookupvar("HOMEDRIVE");
13546 hp = lookupvar("HOMEPATH");
13547 if (hd && hp) {
13548 char *s;
13549
13550 if ((s=malloc(strlen(hd) + strlen(hp) + 1)) != NULL) {
13551 strcat(strcpy(s, hd), hp);
13552 setvar("HOME", s, VEXPORT);
13553 free(s);
13554 }
13555 }
13556 }
13557#endif
13558
13559 if (!ENABLE_PLATFORM_MINGW32) 13556 if (!ENABLE_PLATFORM_MINGW32)
13560 setvar("PPID", utoa(getppid()), 0); 13557 setvar("PPID", utoa(getppid()), 0);
13561 13558