VirtualBox

Changeset 36733 in vbox


Ignore:
Timestamp:
Apr 19, 2011 4:03:27 PM (14 years ago)
Author:
vboxsync
Message:

VBoxService/GuestCtrl: Fix argv[0] handling when executing guest programs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControlExec.cpp

    r36548 r36733  
    707707#ifdef VBOXSERVICE_TOOLBOX
    708708/**
    709  * Constructs the argv command line of a VBoxService program
    710  * by first appending the full path of VBoxService along  with the given
    711  * tool name (e.g. "vbox_cat") + the tool's actual command line parameters.
     709 * Constructs the argv command line by resolving environment variables
     710 * and relative paths.
    712711 *
    713712 * @return IPRT status code.
    714  * @param  pszFileName      File name (full path) of this process.
    715  * @param  papszArgs        Original argv command line from the host.
     713 * @param  pszArgv0         First argument (argv0), either original or modified version.
     714 * @param  papszArgs        Original argv command line from the host, starting at argv[1].
    716715 * @param  ppapszArgv       Pointer to a pointer with the new argv command line.
    717716 *                          Needs to be freed with RTGetOptArgvFree.
    718717 */
    719 static int VBoxServiceControlExecPrepareArgv(const char *pszFileName,
     718static int VBoxServiceControlExecPrepareArgv(const char *pszArgv0,
    720719                                             const char * const *papszArgs, char ***ppapszArgv)
    721720{
    722     AssertPtrReturn(pszFileName, VERR_INVALID_PARAMETER);
    723     AssertPtrReturn(papszArgs, VERR_INVALID_PARAMETER);
     721    AssertPtrReturn(pszArgv0, VERR_INVALID_PARAMETER);
    724722    AssertPtrReturn(ppapszArgv, VERR_INVALID_PARAMETER);
    725 
    726 /** @todo r=bird: Obvious misdesign: argv[0] does NOT have to be the same as
    727  *        the full path to the executable file name!!   I thought we went thru
    728  *        all that when you did the VBoxService toolbox stuff, i.e. how busybox
    729  *        works? */
    730723
    731724/** @todo RTGetOptArgvToString converts to MSC quoted string, while
     
    737730                                  RTGETOPTARGV_CNV_QUOTE_MS_CRT); /* RTGETOPTARGV_CNV_QUOTE_BOURNE_SH */
    738731    if (   RT_SUCCESS(rc)
    739         && pszArgs) /**< @todo pszArg will never be NULL on a successfull return. Perhaps *pszArgs was meant? */
     732        && *pszArgs)
    740733    {
    741734        /*
     
    748741        {
    749742            char *pszNewArgs;
    750             if (RTStrAPrintf(&pszNewArgs, "%s %s", pszFileName, szArgsExp))
     743            if (RTStrAPrintf(&pszNewArgs, "%s %s", pszArgv0, szArgsExp))
    751744            {
    752745#ifdef DEBUG
     
    766759        int iNumArgsIgnored;
    767760        rc = RTGetOptArgvFromString(ppapszArgv, &iNumArgsIgnored,
    768                                     pszFileName, NULL /* Use standard separators. */);
     761                                    pszArgv0, NULL /* Use standard separators. */);
    769762    }
    770763    return rc;
     
    829822        {
    830823            char **papszArgsExp;
    831             rc = VBoxServiceControlExecPrepareArgv(szSysprepCmd, papszArgs, &papszArgsExp);
     824            rc = VBoxServiceControlExecPrepareArgv(szSysprepCmd /* argv0 */, &papszArgs[1], &papszArgsExp);
    832825            if (RT_SUCCESS(rc))
    833826            {
     
    849842    {
    850843        char **papszArgsExp;
    851         rc = VBoxServiceControlExecPrepareArgv(szExecExp, papszArgs, &papszArgsExp);
     844        rc = VBoxServiceControlExecPrepareArgv(szExecExp /* argv0 */, &papszArgs[1], &papszArgsExp);
    852845        if (RT_SUCCESS(rc))
    853846        {
     
    870863#ifdef DEBUG
    871864            char *pszCmdLine;
    872             rc = RTGetOptArgvToString(&pszCmdLine, papszArgsExp, 0 /* Default */);
     865            rc = RTGetOptArgvToString(&pszCmdLine, papszArgsExp, 0 /* Default */);
    873866            AssertRC(rc);
    874867            VBoxServiceVerbose(3, "ControlExec: Executing: %s %s\n",
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette