VirtualBox

Changeset 83419 in vbox for trunk/src/VBox/Additions/common


Ignore:
Timestamp:
Mar 25, 2020 4:49:34 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
136638
Message:

Guest Control/Main + VBoxService: Resolved another @todo: Added ability for guest processes to use argv[0] independently of the actual execution command (follow-up to r136622). bugref:9320

File:
1 edited

Legend:

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

    r83405 r83419  
    10671067        return VERR_NO_MEMORY;
    10681068
    1069 #ifdef DEBUG
     1069#ifdef DEBUG /* Never log this stuff in release mode! */
     1070    VGSvcVerbose(3, "VGSvcGstCtrlProcessAllocateArgv: pszArgv0 = '%s'\n", pszArgv0);
     1071    for (uint32_t i = 0; i < cArgs; i++)
     1072        VGSvcVerbose(3, "VGSvcGstCtrlProcessAllocateArgv: papszArgs[%RU32] = '%s'\n", i, papszArgs[i]);
    10701073    VGSvcVerbose(3, "VGSvcGstCtrlProcessAllocateArgv: cbSize=%RU32, cArgs=%RU32\n", cbSize, cArgs);
    10711074#endif
     
    13421345    if (RT_SUCCESS(rc))
    13431346    {
    1344         const char *pszArgv0 = RT_BOOL(g_fControlHostFeatures0 & VBOX_GUESTCTRL_HF_0_PROCESS_ARGV0)
    1345                              ? papszArgs[0] : pszExec;
     1347        /**
     1348         * This one is a bit tricky to also support older hosts:
     1349         *
     1350         * - If the host does not provide a dedicated argv[0] (< VBox 6.1.x), we use the
     1351         *   executable name (pszExec) as the (default) argv[0]. This is wrong, but we can't do
     1352         *   much about it. The rest (argv[1,2,n]) then gets set starting at papszArgs[0].
     1353         *
     1354         * - Newer hosts (>= VBox 6.1.x) provide a correct argv[0] independently of the actual
     1355         *   executable name though, so actually use argv[0] *and* argv[1,2,n] as intended.
     1356         */
     1357        const bool fHasArgv0 = RT_BOOL(g_fControlHostFeatures0 & VBOX_GUESTCTRL_HF_0_PROCESS_ARGV0);
     1358
    13461359        char **papszArgsExp;
    1347         rc = vgsvcGstCtrlProcessAllocateArgv(pszArgv0, papszArgs,
     1360        rc = vgsvcGstCtrlProcessAllocateArgv(fHasArgv0 ?  papszArgs[0] :  pszExec,
     1361                                             fHasArgv0 ? &papszArgs[1] : &papszArgs[0],
    13481362                                             fFlags, &papszArgsExp);
    13491363        if (RT_FAILURE(rc))
     
    14981512     * Prepare argument list.
    14991513     */
     1514    VGSvcVerbose(3, "vgsvcGstCtrlProcessProcessWorker: fHostFeatures0       = %#x\n",     g_fControlHostFeatures0);
     1515    VGSvcVerbose(3, "vgsvcGstCtrlProcessProcessWorker: StartupInfo.szCmd    = '%s'\n",    pProcess->StartupInfo.szCmd);
     1516    VGSvcVerbose(3, "vgsvcGstCtrlProcessProcessWorker: StartupInfo.uNumArgs = '%RU32'\n", pProcess->StartupInfo.uNumArgs);
     1517#ifdef DEBUG /* Never log this stuff in release mode! */
     1518    VGSvcVerbose(3, "vgsvcGstCtrlProcessProcessWorker: StartupInfo.szArgs   = '%s'\n",    pProcess->StartupInfo.szArgs);
     1519#endif
     1520
    15001521    char **papszArgs;
    15011522    int cArgs = 0; /* Initialize in case of RTGetOptArgvFromString() is failing ... */
     
    15031524                                pProcess->StartupInfo.uNumArgs > 0 ? pProcess->StartupInfo.szArgs : "",
    15041525                                RTGETOPTARGV_CNV_QUOTE_BOURNE_SH, NULL);
    1505     /* Did we get the same result? */
    1506     Assert((int)pProcess->StartupInfo.uNumArgs == cArgs + 1 /* Take argv[0] into account */);
    1507 
     1526
     1527    const bool fHasArgv0 = RT_BOOL(g_fControlHostFeatures0 & VBOX_GUESTCTRL_HF_0_PROCESS_ARGV0);
     1528
     1529    /* Did we get the same result?
     1530     * Take into account that we might not have supplied a (correct) argv[0] from the host. */
     1531    AssertMsg((int)pProcess->StartupInfo.uNumArgs == cArgs + fHasArgv0 ? 0 : 1,
     1532              ("StartupInfo.uNumArgs=%RU32 != cArgs=%d, fHostFeatures0=%#x\n",
     1533               pProcess->StartupInfo.uNumArgs, cArgs, g_fControlHostFeatures0));
    15081534    /*
    15091535     * Create the environment.
Note: See TracChangeset for help on using the changeset viewer.

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