1
Fork 0
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:
Linus Groh 2020-04-17 21:35:02 +01:00 committed by Andreas Kling
parent 0ec37c0d64
commit fc09767872

View file

@ -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);