mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:07:45 +00:00
Kernel: Pass absolute path to shebang interpreter
When you invoke a binary with a shebang line, the `execve` syscall makes sure to pass along command line arguments to the shebang interpreter including the path to the binary to execute. This does not work well when the binary lives in $PATH. For example, given this script living in `/usr/local/bin/my-script`: #!/bin/my-interpreter echo "well hello friends" When executing it as `my-script` from outside `/usr/local/bin/`, it is executed as `/bin/my-interpreter my-script`. To make sure that the interpreter can find the binary to execute, we need to replace the first argument with an absolute path to the binary, so that the resulting command is: /bin/my-interpreter /usr/local/bin/my-script
This commit is contained in:
parent
26250779d1
commit
30abfc2b21
1 changed files with 1 additions and 0 deletions
|
@ -849,6 +849,7 @@ KResult Process::exec(String path, Vector<String> arguments, Vector<String> envi
|
|||
if (!shebang_result.is_error()) {
|
||||
auto shebang_words = shebang_result.release_value();
|
||||
auto shebang_path = shebang_words.first();
|
||||
arguments[0] = move(path);
|
||||
if (!arguments.try_prepend(move(shebang_words)))
|
||||
return ENOMEM;
|
||||
return exec(move(shebang_path), move(arguments), move(environment), ++recursion_depth);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue