VirtualBox

Changeset 70390 in vbox for trunk/src/VBox/Additions


Ignore:
Timestamp:
Dec 29, 2017 4:54:17 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
119995
Message:

VBoxServiceControlProcess.cpp: Don't try send async requests to a thread that already quit because the process didn't even start (like file not found). Fixed confused documentation on hNotificationPipeW, leaving confused (but harmless) cleanup code following return from vgsvcGstCtrlProcessProcLoop().

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControl.h

    r69500 r70390  
    244244      * needs (or is asked) to shutdown. */
    245245    bool volatile                   fShutdown;
    246     /** Whether the guest process thread was stopped
    247      *  or not. */
     246    /** Whether the guest process thread was stopped or not. */
    248247    bool volatile                   fStopped;
    249     /** Whether the guest process thread was started
    250      *  or not. */
     248    /** Whether the guest process thread was started or not. */
    251249    bool                            fStarted;
    252250    /** Client ID. */
     
    276274     *  guest process' stdout.*/
    277275    RTPIPE                          hPipeStdErrR;
    278     /** The notification pipe associated with this guest process.
     276
     277    /** The write end of the notification pipe that is used to poke the thread
     278     * monitoring the process.
    279279     *  This is NIL_RTPIPE for output pipes. */
    280280    RTPIPE                          hNotificationPipeW;
    281     /** The other end of hNotificationPipeW. */
     281    /** The other end of hNotificationPipeW, read by vgsvcGstCtrlProcessProcLoop(). */
    282282    RTPIPE                          hNotificationPipeR;
    283283} VBOXSERVICECTRLPROCESS;
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControlProcess.cpp

    r69500 r70390  
    5858static DECLCALLBACK(int)    vgsvcGstCtrlProcessOnOutput(PVBOXSERVICECTRLPROCESS pThis, const PVBGLR3GUESTCTRLCMDCTX pHostCtx,
    5959                                                        uint32_t uHandle, uint32_t cbToRead, uint32_t uFlags);
    60 static DECLCALLBACK(int)    vgsvcGstCtrlProcessOnTerm(PVBOXSERVICECTRLPROCESS pThis);
    6160
    6261
     
    254253            if (RT_SUCCESS(rc))
    255254            {
     255                pProcess->Thread = NIL_RTTHREAD;
    256256                VGSvcVerbose(3, "[PID %RU32]: Thread shutdown complete, thread rc=%Rrc\n", pProcess->uPID, rcThread);
    257257                if (prc)
     
    14851485     */
    14861486    char **papszArgs;
    1487     uint32_t uNumArgs = 0; /* Initialize in case of RTGetOptArgvFromString() is failing ... */
    1488     rc = RTGetOptArgvFromString(&papszArgs, (int*)&uNumArgs,
    1489                                 (pProcess->StartupInfo.uNumArgs > 0) ? pProcess->StartupInfo.szArgs : "",
     1487    int cArgs = 0; /* Initialize in case of RTGetOptArgvFromString() is failing ... */
     1488    rc = RTGetOptArgvFromString(&papszArgs, &cArgs,
     1489                                pProcess->StartupInfo.uNumArgs > 0 ? pProcess->StartupInfo.szArgs : "",
    14901490                                RTGETOPTARGV_CNV_QUOTE_BOURNE_SH, NULL);
    14911491    /* Did we get the same result? */
    1492     Assert(pProcess->StartupInfo.uNumArgs == uNumArgs + 1 /* Take argv[0] into account */);
     1492    Assert((int)pProcess->StartupInfo.uNumArgs == cArgs + 1 /* Take argv[0] into account */);
    14931493
    14941494    /*
     
    16521652                                         * So, NIL the handles to avoid closing them again.
    16531653                                         */
     1654                                        /** @todo r=bird: Can't see how hNotificationPipeR could be closed here!  Found (and fixed)
     1655                                         * confused comments documenting hNotificationPipeW, probably related. */
    16541656                                        if (RT_FAILURE(RTPollSetQueryHandle(pProcess->hPollSet,
    16551657                                                                            VBOXSERVICECTRLPIPEID_IPC_NOTIFY, NULL)))
     
    17251727        RTMemFree(papszEnv);
    17261728    }
    1727     if (uNumArgs)
     1729    if (cArgs)
    17281730        RTGetOptArgvFree(papszArgs);
    17291731
     
    17391741
    17401742    /* Finally, update stopped status. */
    1741     ASMAtomicXchgBool(&pProcess->fStopped, true);
     1743    ASMAtomicWriteBool(&pProcess->fStopped, true);
     1744    ASMAtomicWriteBool(&pProcess->fShutdown, true);
    17421745
    17431746    return rc;
     
    18261829            AssertRC(rc);
    18271830            if (   ASMAtomicReadBool(&pProcess->fShutdown)
     1831                || ASMAtomicReadBool(&pProcess->fStopped)
    18281832                || RT_FAILURE(rc))
    18291833            {
    18301834                VGSvcError("Thread for process '%s' failed to start, rc=%Rrc\n", pStartupInfo->szCmd, rc);
     1835                int rc2 = RTThreadWait(pProcess->Thread, RT_MS_1SEC * 30, NULL);
     1836                if (RT_SUCCESS(rc2))
     1837                    pProcess->Thread = NIL_RTTHREAD;
    18311838                VGSvcGstCtrlProcessFree(pProcess);
    18321839            }
     
    20542061            /* Wake up the process' notification pipe to get
    20552062             * the request being processed. */
    2056             Assert(pProcess->hNotificationPipeW != NIL_RTPIPE);
     2063            Assert(pProcess->hNotificationPipeW != NIL_RTPIPE || pProcess->fShutdown /* latter in case of race */);
    20572064            size_t cbWritten = 0;
    20582065            rc = RTPipeWrite(pProcess->hNotificationPipeW, "i", 1, &cbWritten);
     
    21222129                                   bool fPendingClose, void *pvBuf, uint32_t cbBuf)
    21232130{
    2124     if (!ASMAtomicReadBool(&pProcess->fShutdown))
     2131    if (!ASMAtomicReadBool(&pProcess->fShutdown) && !ASMAtomicReadBool(&pProcess->fStopped))
    21252132        return vgsvcGstCtrlProcessRequestAsync(pProcess, pHostCtx, (PFNRT)vgsvcGstCtrlProcessOnInput,
    21262133                                               5 /* cArgs */, pProcess, pHostCtx, fPendingClose, pvBuf, cbBuf);
     
    21332140                                    uint32_t uHandle, uint32_t cbToRead, uint32_t fFlags)
    21342141{
    2135     if (!ASMAtomicReadBool(&pProcess->fShutdown))
     2142    if (!ASMAtomicReadBool(&pProcess->fShutdown) && !ASMAtomicReadBool(&pProcess->fStopped))
    21362143        return vgsvcGstCtrlProcessRequestAsync(pProcess, pHostCtx, (PFNRT)vgsvcGstCtrlProcessOnOutput,
    21372144                                               5 /* cArgs */, pProcess, pHostCtx, uHandle, cbToRead, fFlags);
     
    21432150int VGSvcGstCtrlProcessHandleTerm(PVBOXSERVICECTRLPROCESS pProcess)
    21442151{
    2145     if (!ASMAtomicReadBool(&pProcess->fShutdown))
     2152    if (!ASMAtomicReadBool(&pProcess->fShutdown) && !ASMAtomicReadBool(&pProcess->fStopped))
    21462153        return vgsvcGstCtrlProcessRequestAsync(pProcess, NULL /* pHostCtx */, (PFNRT)vgsvcGstCtrlProcessOnTerm,
    21472154                                               1 /* cArgs */, pProcess);
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceToolBox.h

    r69500 r70390  
    2626RT_C_DECLS_END
    2727
    28 #endif /* ___VBoxServiceToolBox_h */
     28#endif /* !___VBoxServiceToolBox_h */
    2929
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