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.
This commit is contained in:
Fabian Homborg 2021-11-28 14:19:01 +01:00
parent 29fa8b776c
commit a07187f46f

View File

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