Shell: Don't return early if command is in PATH and a directory

This commit is contained in:
Linus Groh 2020-04-19 15:10:13 +01:00 committed by Andreas Kling
parent 11054fc9f9
commit 2623bd711b
Notes: sideshowbarker 2024-07-19 07:28:10 +09:00

View file

@ -885,12 +885,6 @@ static int run_command(const String& cmd)
if (handle_builtin(argv.size() - 1, argv.data(), retval))
return retval;
struct stat st;
if (stat(argv[0], &st) == 0 && S_ISDIR(st.st_mode)) {
fprintf(stderr, "Shell: %s: Is a directory\n", argv[0]);
return 126;
}
pid_t child = fork();
if (!child) {
setpgid(0, 0);
@ -911,10 +905,16 @@ static int run_command(const String& cmd)
int rc = execvp(argv[0], const_cast<char* const*>(argv.data()));
if (rc < 0) {
if (errno == ENOENT)
if (errno == ENOENT) {
fprintf(stderr, "%s: Command not found.\n", argv[0]);
else
} else {
struct stat st;
if (stat(argv[0], &st) == 0 && S_ISDIR(st.st_mode)) {
fprintf(stderr, "Shell: %s: Is a directory\n", argv[0]);
_exit(126);
}
fprintf(stderr, "execvp(%s): %s\n", argv[0], strerror(errno));
}
_exit(1);
}
ASSERT_NOT_REACHED();