Implement shebang-fixup for /usr/bin/env to runtime_loader.

* silently replace invocations /usr/bin/env with /bin/env
This commit is contained in:
Oliver Tappe 2013-10-11 12:59:57 +02:00
parent eab89314ce
commit 8b08992799

View File

@ -289,6 +289,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.
@ -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;
}