From 4ceed7c482dceb56239d7624519492a511cc5ada Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Tue, 28 Dec 2021 15:30:04 +0100 Subject: [PATCH] Improve error message for fish scripts without shebang When we execute something and it doesn't have a shebang, typically we fall back on running it with /bin/sh. For .fish scripts, we still refuse to do this (assuming that /bin/sh won't handle .fish scripts properly). Only the error wasn't great. So we now explicitly mention when there's a missing shebang, and point towards the shebang line otherwise. --- src/postfork.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/postfork.cpp b/src/postfork.cpp index d74693342..fd44f713c 100644 --- a/src/postfork.cpp +++ b/src/postfork.cpp @@ -417,10 +417,21 @@ void safe_report_exec_error(int err, const char *actual_cmd, const char *const * } case ENOEXEC: { - FLOGF_SAFE(exec, - "The file '%s' is marked as an executable but could not be run by the " - "operating system.", - actual_cmd); + char interpreter_buff[128] = {}; + const char *interpreter = + get_interpreter(actual_cmd, interpreter_buff, sizeof interpreter_buff); + if (!interpreter) { + FLOGF_SAFE(exec, + "The file '%s' is executable but missing a Shebang (#!) line.", + actual_cmd); + } else { + // If the shebang line exists, we would get an ENOENT or similar instead, + // so I don't know how to reach this. + FLOGF_SAFE(exec, + "The file '%s' could not be run by the " + "operating system. Maybe the Shebang (#!) line is broken?", + actual_cmd); + } break; }