1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 19:17:41 +00:00

Shell: Print correct errno when execvp() fails

Amusingly enough, this was caused by yet another bug.
This commit is contained in:
Sergey Bugaev 2020-05-15 12:21:45 +03:00 committed by Andreas Kling
parent 888329233b
commit 7aad44b825

View file

@ -1044,12 +1044,13 @@ static ExitCodeOrContinuationRequest run_command(const StringView& cmd)
} else } else
fprintf(stderr, "%s: Command not found.\n", argv[0]); fprintf(stderr, "%s: Command not found.\n", argv[0]);
} else { } else {
int saved_errno = errno;
struct stat st; struct stat st;
if (stat(argv[0], &st) == 0 && S_ISDIR(st.st_mode)) { if (stat(argv[0], &st) == 0 && S_ISDIR(st.st_mode)) {
fprintf(stderr, "Shell: %s: Is a directory\n", argv[0]); fprintf(stderr, "Shell: %s: Is a directory\n", argv[0]);
_exit(126); _exit(126);
} }
fprintf(stderr, "execvp(%s): %s\n", argv[0], strerror(errno)); fprintf(stderr, "execvp(%s): %s\n", argv[0], strerror(saved_errno));
} }
_exit(126); _exit(126);
} }