From a07187f46f80fc51e13d3f171e3a1252b47ede69 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Sun, 28 Nov 2021 14:19:01 +0100 Subject: [PATCH] Return proper exec error also for relative shebangs As seen in https://stackoverflow.com/questions/70139844/how-to-execute-custom-fish-scripts-in-custom-path-folder, making a shebang like #!usr/bin/fish won't work, and will error with the default "file does not exist" error *pointing to the file, not the interpreter*. Detect that interpreter properly. We might want to make this an even more specific error, but now it says ``` exec: Failed to execute process '/home/alfa/.local/bin/borken.fish': The file specified the interpreter 'usr/bin/fish', which is not an executable command. ``` Which is okay. --- src/postfork.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/postfork.cpp b/src/postfork.cpp index 0c7c6ef88..ef6858e1e 100644 --- a/src/postfork.cpp +++ b/src/postfork.cpp @@ -540,6 +540,9 @@ static char *get_interpreter(const char *command, char *buffer, size_t buff_size return buffer + 3; } else if (std::strncmp(buffer, "#!/", const_strlen("#!/")) == 0) { return buffer + 2; + } else if (std::strncmp(buffer, "#!", const_strlen("#!")) == 0) { + // Relative path, basically always an issue. + return buffer + 2; } return nullptr; };