summaryrefslogtreecommitdiff
path: root/Shell/main.cpp
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2020-04-17 21:35:02 +0100
committerAndreas Kling <kling@serenityos.org>2020-04-19 15:37:07 +0200
commitfc097678720d7ee7148a482c20d2ffad4fd58b37 (patch)
tree2e98f3f9dd3e2e9c220556367bafa205cac37cee /Shell/main.cpp
parent0ec37c0d64d9f5a8093521041700dd76fbcefb57 (diff)
downloadserenity-fc097678720d7ee7148a482c20d2ffad4fd58b37.zip
Shell: Explicitly check if command is a directory
This is a bit nicer than getting "Exec format error" after trying to execvp() a directory.
Diffstat (limited to 'Shell/main.cpp')
-rw-r--r--Shell/main.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/Shell/main.cpp b/Shell/main.cpp
index 3e5aec114c..d6d7b12ef8 100644
--- a/Shell/main.cpp
+++ b/Shell/main.cpp
@@ -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);