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.
This commit is contained in:
Fabian Homborg 2021-12-28 15:30:04 +01:00
parent a9f6a38e37
commit 4ceed7c482

View File

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