hrev46213 adds 1 changeset to branch 'master' old head: eab89314ceedf030ca7a1d42934357e9110f41f6 new head: 8b089927996b3d4c3228cf357e0c362aa9ebb1a6 overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=8b08992+%5Eeab8931 ---------------------------------------------------------------------------- 8b08992: Implement shebang-fixup for /usr/bin/env to runtime_loader. * silently replace invocations /usr/bin/env with /bin/env [ Oliver Tappe <zooey@xxxxxxxxxxxxxxx> ] ---------------------------------------------------------------------------- Revision: hrev46213 Commit: 8b089927996b3d4c3228cf357e0c362aa9ebb1a6 URL: http://cgit.haiku-os.org/haiku/commit/?id=8b08992 Author: Oliver Tappe <zooey@xxxxxxxxxxxxxxx> Date: Fri Oct 11 10:59:57 2013 UTC ---------------------------------------------------------------------------- 1 file changed, 25 insertions(+), 1 deletion(-) src/system/runtime_loader/runtime_loader.cpp | 26 +++++++++++++++++++++++- ---------------------------------------------------------------------------- diff --git a/src/system/runtime_loader/runtime_loader.cpp b/src/system/runtime_loader/runtime_loader.cpp index 1f0f574..392deac 100644 --- a/src/system/runtime_loader/runtime_loader.cpp +++ b/src/system/runtime_loader/runtime_loader.cpp @@ -290,6 +290,28 @@ open_executable(char *name, image_type type, const char *rpath, /*! + Applies haiku-specific fixes to a shebang line. +*/ +static void +fixup_shebang(char *invoker) +{ + char *current = invoker; + while (*current == ' ' || *current == '\t') { + ++current; + } + + char *commandStart = current; + while (*current != ' ' && *current != '\t' && *current != '\0') { + ++current; + } + + // replace /usr/bin/env with /bin/env + if (memcmp(commandStart, "/usr/bin/env", current - commandStart) == 0) + memmove(commandStart, commandStart + 4, strlen(commandStart + 4) + 1); +} + + +/*! Tests if there is an executable file at the provided path. It will also test if the file has a valid ELF header or is a shell script. Even if the runtime loader does not need to be able to deal with @@ -341,8 +363,10 @@ test_executable(const char *name, char *invoker) } else end[0] = '\0'; - if (invoker) + if (invoker) { strcpy(invoker, buffer + 2); + fixup_shebang(invoker); + } status = B_OK; }