Shell: Set up the PWD environment variable early

This ensures that PWD is set when running "sh -c something"
This commit is contained in:
Andreas Kling 2020-03-07 00:25:30 +01:00
parent d7cfe61fe4
commit 4a271430f8
Notes: sideshowbarker 2024-07-19 08:51:37 +09:00

View File

@ -981,6 +981,13 @@ int main(int argc, char** argv)
if (rc < 0)
perror("ttyname_r");
{
auto* cwd = getcwd(nullptr, 0);
g.cwd = cwd;
setenv("PWD", cwd, 1);
free(cwd);
}
{
auto* pw = getpwuid(getuid());
if (pw) {
@ -1012,13 +1019,6 @@ int main(int argc, char** argv)
return 0;
}
{
auto* cwd = getcwd(nullptr, 0);
g.cwd = cwd;
setenv("PWD", cwd, 1);
free(cwd);
}
g.directory_stack.append(g.cwd);
load_history();