VirtualBox

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


Ignore:
Timestamp:
Sep 30, 2015 9:49:32 AM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
102948
Message:

VBoxServiceControlSession.cpp: feedback.

File:
1 edited

Legend:

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

    r57834 r57960  
    18451845            RTStrPrintf(szParmThreadId, sizeof(szParmThreadId), "--thread-id=%RU32", s_uCtrlSessionThread);
    18461846#endif
    1847             char szParmUserName[GUESTPROCESS_MAX_USER_LEN + 32];
    1848 
    1849             int iArgIdx = 0; /* Current index in argument vector. */
    1850             char const *papszArgs[16];
    1851 
    1852             papszArgs[iArgIdx++] = pszExeName;
    1853             papszArgs[iArgIdx++] = "guestsession";
    1854             papszArgs[iArgIdx++] = szParmSessionID;
    1855             papszArgs[iArgIdx++] = szParmSessionProto;
    1856 #ifdef DEBUG
    1857             papszArgs[iArgIdx++] = szParmThreadId;
     1847            int idxArg = 0; /* Next index in argument vector. */
     1848            char const *apszArgs[24];
     1849
     1850            apszArgs[idxArg++] = pszExeName;
     1851            apszArgs[idxArg++] = "guestsession";
     1852            apszArgs[idxArg++] = szParmSessionID;
     1853            apszArgs[idxArg++] = szParmSessionProto;
     1854#ifdef DEBUG
     1855            apszArgs[idxArg++] = szParmThreadId;
    18581856#endif
    18591857            if (!fAnonymous) /* Do we need to pass a user name? */
    18601858            {
    1861                 RTStrPrintf(szParmUserName, sizeof(szParmUserName), "--user=%s", pSessionThread->StartupInfo.szUser);
    1862                 papszArgs[iArgIdx++] = szParmUserName;
     1859                apszArgs[idxArg++] = "--user";
     1860                apszArgs[idxArg++] = pSessionThread->StartupInfo.szUser;
    18631861            }
    18641862
    18651863            /* Add same verbose flags as parent process. */
     1864/** @todo r=bird: how does this stuff work when g_cVerbosity = 0?  Also, why do you need rc2 here?  Do we actually care about the RC anyway? */
    18661865            int rc2 = VINF_SUCCESS;
    18671866            char szParmVerbose[32] = { 0 };
     
    18751874            }
    18761875            if (RT_SUCCESS(rc2))
    1877                 papszArgs[iArgIdx++] = szParmVerbose;
     1876                apszArgs[idxArg++] = szParmVerbose;
     1877
     1878/** @todo r=bird: As I already mentioned in the review comment you removed in
     1879 * r102561, the log file name handling is rather mangled.  You have a 4K stack
     1880 * buffer, but you insist on doing 2-5 heap allocations when constructing the
     1881 * name.  Either you do it in the stack buffer or you do it on the heap.
     1882 *
     1883 * Now, if you make sure szParmLogFile is, say, 128 byte larger than
     1884 * g_szLogFile, you won't need to consider overflows any more.  You can easily
     1885 * construct the whole thing with a strcpy, RTPathStripSuffix and a sprintf.
     1886 */
    18781887
    18791888            /* Add log file handling. Each session will have an own
    18801889             * log file, naming based on the parent log file. */
     1890#if 1
    18811891            char szParmLogFile[RTPATH_MAX];
    18821892            if (   RT_SUCCESS(rc2)
     
    19261936                }
    19271937                if (RT_SUCCESS(rc2))
    1928                     papszArgs[iArgIdx++] = szParmLogFile;
     1938                    apszArgs[idxArg++] = szParmLogFile;
    19291939
    19301940                rc = rc2;
     
    19321942            else if (RT_FAILURE(rc2))
    19331943                rc = rc2;
     1944#else
     1945            char szParmLogFile[sizeof(g_szLogFile) + 128];
     1946            if (g_szLogFile)
     1947            {
     1948                const char *pszSuffix = RTPathSuffix(g_szLogFile);
     1949                if (!pszSuffix)
     1950                    pszSuffix = strchr(g_szLogFile, '\0');
     1951                size_t cchBase = pszSuffix - g_szLogFile;
     1952#ifndef DEBUG
     1953                RTStrPrintf(szParmLogFile, sizeof(szParmLogFile), "%.*s-%RU32-%s%s",
     1954                            cchBase, g_szLogFile, pSessionStartupInfo->uSessionID, pSessionStartupInfo->szUser, pszSuffix);
     1955#else
     1956                RTStrPrintf(szParmLogFile, sizeof(szParmLogFile), "%.*s-%RU32-%RU32-%s%s",
     1957                            cchBase, g_szLogFile, pSessionStartupInfo->uSessionID, s_uCtrlSessionThread,
     1958                            pSessionStartupInfo->szUser, pszSuffix);
     1959#endif
     1960                apszArgs[idxArg++] = "--logfile";
     1961                apszArgs[idxArg++] = szParmLogFile;
     1962            }
     1963#endif /* alternative version */
    19341964#ifdef DEBUG
    19351965            VBoxServiceVerbose(4, "Argv building rc=%Rrc, session flags=%x\n", rc, g_Session.fFlags);
     
    19371967            {
    19381968                if (g_Session.fFlags & VBOXSERVICECTRLSESSION_FLAG_DUMPSTDOUT)
    1939                     papszArgs[iArgIdx++] = "--dump-stdout";
     1969                    apszArgs[idxArg++] = "--dump-stdout";
    19401970                if (g_Session.fFlags & VBOXSERVICECTRLSESSION_FLAG_DUMPSTDERR)
    1941                     papszArgs[iArgIdx++] = "--dump-stderr";
    1942             }
    1943 #endif
    1944             papszArgs[iArgIdx++] = NULL;
     1971                    apszArgs[idxArg++] = "--dump-stderr";
     1972            }
     1973#endif
     1974            apszArgs[idxArg] = NULL;
     1975            Assert(idxArg < RT_ELEMENTS(apszArgs));
    19451976
    19461977            if (g_cVerbosity > 3)
     
    19481979                VBoxServiceVerbose(4, "Spawning parameters:\n");
    19491980
    1950                 iArgIdx = 0;
    1951                 while (papszArgs[iArgIdx])
    1952                     VBoxServiceVerbose(4, "\t%s\n", papszArgs[iArgIdx++]);
     1981                idxArg = 0;
     1982                while (apszArgs[idxArg])
     1983                    VBoxServiceVerbose(4, "\t%s\n", apszArgs[idxArg++]);
    19531984            }
    19541985
     
    20252056
    20262057                    if (RT_SUCCESS(rc))
    2027                         rc = RTProcCreateEx(pszExeName, papszArgs, hEnv, uProcFlags,
     2058                        rc = RTProcCreateEx(pszExeName, apszArgs, hEnv, uProcFlags,
    20282059                                            pSession->StdIn.phChild, pSession->StdOut.phChild, pSession->StdErr.phChild,
    20292060                                            !fAnonymous ? pSession->StartupInfo.szUser : NULL,
     
    20592090                    hStdOutAndErr.enmType = RTHANDLETYPE_FILE;
    20602091
    2061                     rc = RTProcCreateEx(pszExeName, papszArgs, RTENV_DEFAULT, uProcFlags,
     2092                    rc = RTProcCreateEx(pszExeName, apszArgs, RTENV_DEFAULT, uProcFlags,
    20622093                                        &hStdIn, &hStdOutAndErr, &hStdOutAndErr,
    20632094                                        !fAnonymous ? pSessionThread->StartupInfo.szUser : NULL,
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