Detect windows line endings when executing a file

Fixes #2783.
This commit is contained in:
Fabian Homborg
2020-09-25 16:44:02 +02:00
parent d636918795
commit 0d0ee473fa
2 changed files with 21 additions and 4 deletions

View File

@@ -360,10 +360,17 @@ void safe_report_exec_error(int err, const char *actual_cmd, const char *const *
const char *interpreter =
get_interpreter(actual_cmd, interpreter_buff, sizeof interpreter_buff);
if (interpreter && 0 != access(interpreter, X_OK)) {
debug_safe(0,
"The file '%s' specified the interpreter '%s', which is not an "
"executable command.",
actual_cmd, interpreter);
// Detect windows line endings and complain specifically about them.
auto len = strlen(interpreter);
if (len && interpreter[len - 1] == '\r') {
debug_safe(0,
"The file uses windows line endings (\\r\\n). Run dos2unix or similar to fix it.");
} else {
debug_safe(0,
"The file '%s' specified the interpreter '%s', which is not an "
"executable command.",
actual_cmd, interpreter);
}
} else {
debug_safe(0, "The file '%s' does not exist or could not be executed.", actual_cmd);
}

View File

@@ -9,5 +9,15 @@ not exec cat <nosuchfile
#CHECKERR: open: No such file or directory
echo "neg failed: $status"
#CHECK: neg failed: 0
set -l f (mktemp)
echo "#!/bin/sh"\r\n"echo foo" > $f
chmod +x $f
$f
#CHECKERR: Failed to execute process '{{.*}}'. Reason:
#CHECKERR: The file uses windows line endings (\r\n). Run dos2unix or similar to fix it.
# This needs to be last, because it actually runs exec.
exec cat </dev/null
echo "not reached"