Shell: do path resolution only if command doesn't contain '/'
This commit is contained in:
parent
2e858fddb5
commit
24243268a6
|
@ -469,11 +469,12 @@ pid_t execute_command_no_wait(BAN::Vector<BAN::String>& args, int fd_in, int fd_
|
|||
|
||||
// do PATH resolution
|
||||
BAN::String executable_file;
|
||||
if (!args.front().empty() && args.front().front() != '.' && args.front().front() != '/')
|
||||
{
|
||||
char* path_env_cstr = getenv("PATH");
|
||||
if (path_env_cstr)
|
||||
if (!args.front().sv().contains('/'))
|
||||
{
|
||||
const char* path_env_cstr = getenv("PATH");
|
||||
if (path_env_cstr == nullptr)
|
||||
path_env_cstr = "";
|
||||
|
||||
auto path_env_list = MUST(BAN::StringView(path_env_cstr).split(':'));
|
||||
for (auto path_env : path_env_list)
|
||||
{
|
||||
|
@ -488,13 +489,6 @@ pid_t execute_command_no_wait(BAN::Vector<BAN::String>& args, int fd_in, int fd_
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (executable_file.empty())
|
||||
{
|
||||
fprintf(stderr, "command not found: %s\n", args.front().data());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -504,7 +498,7 @@ pid_t execute_command_no_wait(BAN::Vector<BAN::String>& args, int fd_in, int fd_
|
|||
// Verify that the file exists is executable
|
||||
{
|
||||
struct stat st;
|
||||
if (stat(executable_file.data(), &st) == -1)
|
||||
if (executable_file.empty() || stat(executable_file.data(), &st) == -1)
|
||||
{
|
||||
fprintf(stderr, "command not found: %s\n", args.front().data());
|
||||
return -1;
|
||||
|
|
Loading…
Reference in New Issue