VirtualBox

Changeset 83508 in vbox for trunk


Ignore:
Timestamp:
Apr 1, 2020 4:24:33 PM (5 years ago)
Author:
vboxsync
Message:

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

Location:
trunk/src/VBox/Additions/common/VBoxService
Files:
2 edited

Legend:

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

    r83420 r83508  
    10391039 *
    10401040 * @return IPRT status code.
    1041  * @param  pszArgv0         First argument (argv0), either original or modified version.  Optional.
     1041 * @param  pszArgv0         First argument (argv0), either original or modified version.
    10421042 * @param  papszArgs        Original argv command line from the host, starting at argv[1].
    10431043 * @param  fFlags           The process creation flags pass to us from the host.
     
    10481048                                           char ***ppapszArgv)
    10491049{
    1050     AssertPtrReturn(ppapszArgv, VERR_INVALID_POINTER);
    1051 
    10521050    VGSvcVerbose(3, "VGSvcGstCtrlProcessPrepareArgv: pszArgv0=%p, papszArgs=%p, fFlags=%#x, ppapszArgv=%p\n",
    10531051                 pszArgv0, papszArgs, fFlags, ppapszArgv);
     1052
     1053    AssertPtrReturn(pszArgv0,   VERR_INVALID_POINTER);
     1054    AssertPtrReturn(ppapszArgv, VERR_INVALID_POINTER);
    10541055
    10551056    int rc = VINF_SUCCESS;
     
    10671068        return VERR_NO_MEMORY;
    10681069
     1070    VGSvcVerbose(3, "VGSvcGstCtrlProcessAllocateArgv: pszArgv0 = '%s', cArgs=%RU32, cbSize=%zu\n", pszArgv0, cArgs, cbSize);
    10691071#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]);
    1073     VGSvcVerbose(3, "VGSvcGstCtrlProcessAllocateArgv: cbSize=%RU32, cArgs=%RU32\n", cbSize, cArgs);
     1072    if (cArgs)
     1073    {
     1074        for (uint32_t i = 0; i < cArgs; i++)
     1075            VGSvcVerbose(3, "VGSvcGstCtrlProcessAllocateArgv: papszArgs[%RU32] = '%s'\n", i, papszArgs[i]);
     1076    }
    10741077#endif
    10751078
     
    10811084        || !strpbrk(pszArgv0, " \t\n\r")
    10821085        || pszArgv0[0] == '"')
     1086    {
    10831087        rc = RTStrDupEx(&papszNewArgv[0], pszArgv0);
     1088    }
    10841089    else
    10851090    {
    10861091        size_t cchArgv0 = strlen(pszArgv0);
     1092        AssertReturn(cchArgv0, VERR_INVALID_PARAMETER); /* Paranoia. */
    10871093        rc = RTStrAllocEx(&papszNewArgv[0], 1 + cchArgv0 + 1 + 1);
    10881094        if (RT_SUCCESS(rc))
     
    13491355         *
    13501356         * - 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
     1357         *   unmodified executable name (pszExec) as the (default) argv[0]. This is wrong, but we can't do
    13521358         *   much about it. The rest (argv[1,2,n]) then gets set starting at papszArgs[0].
    13531359         *
     
    13571363        const bool fHasArgv0 = RT_BOOL(g_fControlHostFeatures0 & VBOX_GUESTCTRL_HF_0_PROCESS_ARGV0);
    13581364
     1365        const char *pcszArgv0 = (fHasArgv0 && papszArgs[0]) ? papszArgs[0] : pszExec;
     1366        AssertPtrReturn(pcszArgv0, VERR_INVALID_POINTER); /* Paranoia. */
     1367
     1368        const char * const *pcszArgvN = fHasArgv0 && papszArgs + 1 ? papszArgs + 1 : papszArgs;
     1369        AssertPtrReturn(pcszArgvN, VERR_INVALID_POINTER); /* Ditto. */
     1370
     1371        VGSvcVerbose(3, "vgsvcGstCtrlProcessCreateProcess: fHasArgv0=%RTbool, pcszArgv0=%p, pcszArgvN=%p, g_fControlHostFeatures0=%#x\n",
     1372                     fHasArgv0, pcszArgv0, pcszArgvN, g_fControlHostFeatures0);
     1373
    13591374        char **papszArgsExp;
    1360         rc = vgsvcGstCtrlProcessAllocateArgv(fHasArgv0 ?  papszArgs[0] :  pszExec,
    1361                                              fHasArgv0 ? &papszArgs[1] : &papszArgs[0],
    1362                                              fFlags, &papszArgsExp);
     1375        rc = vgsvcGstCtrlProcessAllocateArgv(pcszArgv0, pcszArgvN, fFlags, &papszArgsExp);
    13631376        if (RT_FAILURE(rc))
    13641377        {
     
    15261539
    15271540#ifdef VBOX_STRICT
    1528     const bool fHasArgv0 = RT_BOOL(g_fControlHostFeatures0 & VBOX_GUESTCTRL_HF_0_PROCESS_ARGV0);
     1541    const bool fHasArgv0    = RT_BOOL(g_fControlHostFeatures0 & VBOX_GUESTCTRL_HF_0_PROCESS_ARGV0); RT_NOREF(fHasArgv0);
     1542    const int  cArgsToCheck = cArgs; /** @ŧodo Do we still need to do this?    + (fHasArgv0 ? 0 : 1); */
    15291543
    15301544    /* Did we get the same result?
    15311545     * Take into account that we might not have supplied a (correct) argv[0] from the host. */
    1532     AssertMsg((int)pProcess->StartupInfo.uNumArgs == cArgs + fHasArgv0 ? 0 : 1,
    1533               ("StartupInfo.uNumArgs=%RU32 != cArgs=%d, fHostFeatures0=%#x\n",
    1534                pProcess->StartupInfo.uNumArgs, cArgs, g_fControlHostFeatures0));
     1546    AssertMsg((int)pProcess->StartupInfo.uNumArgs == cArgsToCheck,
     1547              ("rc=%Rrc, StartupInfo.uNumArgs=%RU32 != cArgsToCheck=%d, cArgs=%d, fHostFeatures0=%#x\n",
     1548               rc, pProcess->StartupInfo.uNumArgs, cArgsToCheck, cArgs, g_fControlHostFeatures0));
    15351549#endif
    15361550
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControlSession.cpp

    r83441 r83508  
    17201720    g_fControlSupportsOptimizations = VbglR3GuestCtrlSupportsOptimizations(idClient);
    17211721    g_idControlSvcClient            = idClient;
    1722     VbglR3GuestCtrlQueryFeatures(idClient, &g_fControlHostFeatures0);
     1722
     1723    int rc2 = VbglR3GuestCtrlQueryFeatures(idClient, &g_fControlHostFeatures0);
     1724    if (RT_FAILURE(rc2)) /* Querying host features is not fatal -- do not use rc here. */
     1725        VGSvcVerbose(1, "Querying host features failed with %Rrc\n", rc2);
    17231726
    17241727    rc = vgsvcGstCtrlSessionReadKeyAndAccept(idClient, pSession->StartupInfo.uSessionID);
    17251728    if (RT_SUCCESS(rc))
    17261729    {
    1727         VGSvcVerbose(1, "Using client ID=%RU32\n", idClient);
     1730        VGSvcVerbose(1, "Using client ID=%RU32, g_fControlHostFeatures0=%#x\n", idClient, g_fControlHostFeatures0);
    17281731
    17291732        /*
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