Skip to content

Commit 290d07a

Browse files
committed
env.cpp: Better fallback for missing PATH
Ask the system where utilities are available with confstr (POSIX). This is the same string printed by `getconf PATH`, which likely includes more directories.
1 parent 4567d3a commit 290d07a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/env.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,8 +649,15 @@ static void setup_path() {
649649
auto &vars = env_stack_t::globals();
650650
const auto path = vars.get(L"PATH");
651651
if (path.missing_or_empty()) {
652-
wcstring_list_t value({L"/usr/bin", L"/bin"});
653-
vars.set(L"PATH", ENV_GLOBAL | ENV_EXPORT, value);
652+
#if defined(_CS_PATH)
653+
// _CS_PATH: colon-separated paths to find POSIX utilities
654+
std::string cspath;
655+
cspath.resize(confstr(_CS_PATH, nullptr, 0));
656+
confstr(_CS_PATH, &cspath[0], cspath.length());
657+
#else
658+
std::string cspath = "/bin:/usr/bin"; // shouldn't really happen
659+
#endif
660+
vars.set_one(L"PATH", ENV_GLOBAL | ENV_EXPORT, str2wcstring(cspath));
654661
}
655662
}
656663

0 commit comments

Comments
 (0)