mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 07:55:07 +00:00
Shell: Explicitly check if command is a directory
This is a bit nicer than getting "Exec format error" after trying to execvp() a directory.
This commit is contained in:
parent
0ec37c0d64
commit
fc09767872
1 changed files with 6 additions and 0 deletions
|
@ -885,6 +885,12 @@ 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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue