Ticket #1824: arg0-fix.patch

File arg0-fix.patch, 2.7 KB (added by kaliber, 16 years ago)

Proposed patch for bug #1824 and #1773

  • src/system/libroot/os/image.c

     
    3333
    3434        if (invoker[0]) {
    3535            status = __parse_invoke_line(invoker, &newArgs,
    36                 (char * const **)&args, &argCount);
     36                (char * const **)&args, &argCount, args[1]);
    3737            if (status < B_OK)
    3838                return status;
    3939        }
     
    146146
    147147status_t
    148148__parse_invoke_line(char *invoker, char ***_newArgs,
    149     char * const **_oldArgs, int32 *_argCount)
     149    char * const **_oldArgs, int32 *_argCount, const char *arg0)
    150150{
    151151    int32 i, count = 0;
    152152    char *arg = invoker;
     
    166166    // copy invoker and old arguments and to newArgs
    167167
    168168    for (i = 0; (arg = next_argument(&invoker, true)) != NULL; i++) {
    169         newArgs[i] = arg;
     169        newArgs[i] = arg;
    170170    }
    171171    for (i = 0; i < *_argCount; i++) {
    172         newArgs[i + count] = (char *)(*_oldArgs)[i];
     172        if (i == 0)
     173            newArgs[i + count] = arg0;
     174        else
     175            newArgs[i + count] = (char *)(*_oldArgs)[i];
    173176    }
    174177
    175178    newArgs[i + count] = NULL;
  • src/system/libroot/posix/unistd/exec.c

     
    7272
    7373    // test validity of executable + support for scripts
    7474    {
    75         status_t status = __test_executable(args[0], invoker);
     75        status_t status = __test_executable(path, invoker);
    7676        if (status < B_OK) {
    7777            errno = status;
    7878            return -1;
    7979        }
    8080
    8181        if (invoker[0]) {
    82             status = __parse_invoke_line(invoker, &newArgs, &args, &argCount);
     82            status = __parse_invoke_line(invoker, &newArgs, &args, &argCount, path);
    8383            if (status < B_OK) {
    8484                errno = status;
    8585                return -1;
     
    9494    // don't care and pass everything to the kernel - it will have to
    9595    // do the right thing :)
    9696
    97     errno = _kern_exec(path, argCount, args, envCount, environment);
     97    errno = _kern_exec(path, argCount, newArgs ? newArgs : args, envCount, environment);
    9898        // if this call returns, something definitely went wrong
    9999
    100100    free(newArgs);
  • headers/private/libroot/libroot_private.h

     
    2222#endif
    2323
    2424status_t __parse_invoke_line(char *invoker, char ***_newArgs,
    25             char * const **_oldArgs, int32 *_argCount);
     25            char * const **_oldArgs, int32 *_argCount, const char *arg0);
    2626status_t __get_next_image_dependency(image_id id, uint32 *cookie,
    2727            const char **_name);
    2828status_t __test_executable(const char *path, char *invoker);