From 30cce2777045e655a0ea301c3ccadb3d53ff1750 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Tue, 26 Feb 2008 00:03:51 +0000 Subject: [PATCH] Patch from kaliber: use path of executable instead of the command. Thanks! this fixes bug #1773 and #1824. I tested only #1773. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24131 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/libroot/libroot_private.h | 2 +- src/system/libroot/os/image.c | 9 ++++++--- src/system/libroot/posix/unistd/exec.c | 6 +++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/headers/private/libroot/libroot_private.h b/headers/private/libroot/libroot_private.h index 5742700c93..4d0e91ca2c 100644 --- a/headers/private/libroot/libroot_private.h +++ b/headers/private/libroot/libroot_private.h @@ -22,7 +22,7 @@ extern "C" { #endif status_t __parse_invoke_line(char *invoker, char ***_newArgs, - char * const **_oldArgs, int32 *_argCount); + char * const **_oldArgs, int32 *_argCount, const char *arg0); status_t __get_next_image_dependency(image_id id, uint32 *cookie, const char **_name); status_t __test_executable(const char *path, char *invoker); diff --git a/src/system/libroot/os/image.c b/src/system/libroot/os/image.c index 482c1747a7..a13f532cfd 100644 --- a/src/system/libroot/os/image.c +++ b/src/system/libroot/os/image.c @@ -33,7 +33,7 @@ load_image(int32 argCount, const char **args, const char **environ) if (invoker[0]) { status = __parse_invoke_line(invoker, &newArgs, - (char * const **)&args, &argCount); + (char * const **)&args, &argCount, args[1]); if (status < B_OK) return status; } @@ -146,7 +146,7 @@ next_argument(char **_start, bool separate) status_t __parse_invoke_line(char *invoker, char ***_newArgs, - char * const **_oldArgs, int32 *_argCount) + char * const **_oldArgs, int32 *_argCount, const char *arg0) { int32 i, count = 0; char *arg = invoker; @@ -169,7 +169,10 @@ __parse_invoke_line(char *invoker, char ***_newArgs, newArgs[i] = arg; } for (i = 0; i < *_argCount; i++) { - newArgs[i + count] = (char *)(*_oldArgs)[i]; + if (i == 0) + newArgs[i + count] = arg0; + else + newArgs[i + count] = (char *)(*_oldArgs)[i]; } newArgs[i + count] = NULL; diff --git a/src/system/libroot/posix/unistd/exec.c b/src/system/libroot/posix/unistd/exec.c index 38f643dbdc..e58dc8fe44 100644 --- a/src/system/libroot/posix/unistd/exec.c +++ b/src/system/libroot/posix/unistd/exec.c @@ -72,14 +72,14 @@ execve(const char *path, char * const args[], char * const environment[]) // test validity of executable + support for scripts { - status_t status = __test_executable(args[0], invoker); + status_t status = __test_executable(path, invoker); if (status < B_OK) { errno = status; return -1; } if (invoker[0]) { - status = __parse_invoke_line(invoker, &newArgs, &args, &argCount); + status = __parse_invoke_line(invoker, &newArgs, &args, &argCount, path); if (status < B_OK) { errno = status; return -1; @@ -94,7 +94,7 @@ execve(const char *path, char * const args[], char * const environment[]) // don't care and pass everything to the kernel - it will have to // do the right thing :) - errno = _kern_exec(path, argCount, args, envCount, environment); + errno = _kern_exec(path, argCount, newArgs ? newArgs : args, envCount, environment); // if this call returns, something definitely went wrong free(newArgs);