mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 19:35:09 +00:00
Shell: Don't return early if command is in PATH and a directory
This commit is contained in:
parent
11054fc9f9
commit
2623bd711b
1 changed files with 8 additions and 8 deletions
|
@ -885,12 +885,6 @@ static int run_command(const String& cmd)
|
||||||
if (handle_builtin(argv.size() - 1, argv.data(), retval))
|
if (handle_builtin(argv.size() - 1, argv.data(), retval))
|
||||||
return 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();
|
pid_t child = fork();
|
||||||
if (!child) {
|
if (!child) {
|
||||||
setpgid(0, 0);
|
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()));
|
int rc = execvp(argv[0], const_cast<char* const*>(argv.data()));
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
if (errno == ENOENT)
|
if (errno == ENOENT) {
|
||||||
fprintf(stderr, "%s: Command not found.\n", argv[0]);
|
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));
|
fprintf(stderr, "execvp(%s): %s\n", argv[0], strerror(errno));
|
||||||
|
}
|
||||||
_exit(1);
|
_exit(1);
|
||||||
}
|
}
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue