Skip to content

Commit

Permalink
Shell: Print correct errno when execvp() fails
Browse files Browse the repository at this point in the history
Amusingly enough, this was caused by yet another bug.
  • Loading branch information
bugaevc authored and awesomekling committed May 15, 2020
1 parent 8883292 commit 7aad44b
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Shell/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1044,12 +1044,13 @@ static ExitCodeOrContinuationRequest run_command(const StringView& cmd)
} else
fprintf(stderr, "%s: Command not found.\n", argv[0]);
} else {
int saved_errno = errno;
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(saved_errno));
}
_exit(126);
}
Expand Down

0 comments on commit 7aad44b

Please sign in to comment.