VirtualBox

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


Ignore:
Timestamp:
Apr 6, 2020 6:21:34 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
136989
Message:

Guest Control/VBoxService: Cleaned up VGSvcGstCtrlSessionClose(), a bit of renaming, added vgsvcGstCtrlSessionProcessRemoveInternal(). bugref:9320

File:
1 edited

Legend:

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

    r83555 r83595  
    6363
    6464static int vgsvcGstCtrlSessionCleanupProcesses(const PVBOXSERVICECTRLSESSION pSession);
     65static int vgsvcGstCtrlSessionProcessRemoveInternal(PVBOXSERVICECTRLSESSION pSession, PVBOXSERVICECTRLPROCESS pProcess);
    6566
    6667
     
    9091
    9192
    92 static int vgsvcGstCtrlSessionFileDestroy(PVBOXSERVICECTRLFILE pFile)
     93static int vgsvcGstCtrlSessionFileFree(PVBOXSERVICECTRLFILE pFile)
    9394{
    9495    AssertPtrReturn(pFile, VERR_INVALID_POINTER);
     
    425426        {
    426427            VGSvcVerbose(2, "[File %s] Closing (handle=%RU32)\n", pFile ? pFile->szName : "<Not found>", uHandle);
    427             rc = vgsvcGstCtrlSessionFileDestroy(pFile);
     428            rc = vgsvcGstCtrlSessionFileFree(pFile);
    428429        }
    429430        else
     
    18901891
    18911892        /* Wait for all active threads to shutdown and destroy the active thread list. */
    1892         pProcess = RTListGetFirst(&pSession->lstProcesses, VBOXSERVICECTRLPROCESS, Node);
    1893         while (pProcess)
    1894         {
    1895             PVBOXSERVICECTRLPROCESS pNext = RTListNodeGetNext(&pProcess->Node, VBOXSERVICECTRLPROCESS, Node);
    1896             bool fLast = RTListNodeIsLast(&pSession->lstProcesses, &pProcess->Node);
    1897 
    1898             int rc2 = RTCritSectLeave(&pSession->CritSect);
    1899             AssertRC(rc2);
    1900 
    1901             rc2 = VGSvcGstCtrlProcessWait(pProcess, 30 * 1000 /* Wait 30 seconds max. */, NULL /* rc */);
    1902 
    1903             int rc3 = RTCritSectEnter(&pSession->CritSect);
     1893        PVBOXSERVICECTRLPROCESS pProcessNext;
     1894        RTListForEachSafe(&pSession->lstProcesses, pProcess, pProcessNext, VBOXSERVICECTRLPROCESS, Node)
     1895        {
     1896            int rc3 = RTCritSectLeave(&pSession->CritSect);
    19041897            AssertRC(rc3);
    19051898
     1899            int rc2 = VGSvcGstCtrlProcessWait(pProcess, 30 * 1000 /* Wait 30 seconds max. */, NULL /* rc */);
     1900
     1901            rc3 = RTCritSectEnter(&pSession->CritSect);
     1902            AssertRC(rc3);
     1903
    19061904            if (RT_SUCCESS(rc2))
    1907                 VGSvcGstCtrlProcessFree(pProcess);
    1908 
    1909             if (fLast)
    1910                 break;
    1911 
    1912             pProcess = pNext;
    1913         }
    1914 
    1915 #ifdef DEBUG
    1916         pProcess = RTListGetFirst(&pSession->lstProcesses, VBOXSERVICECTRLPROCESS, Node);
    1917         while (pProcess)
    1918         {
    1919             PVBOXSERVICECTRLPROCESS pNext = RTListNodeGetNext(&pProcess->Node, VBOXSERVICECTRLPROCESS, Node);
    1920             bool fLast = RTListNodeIsLast(&pSession->lstProcesses, &pProcess->Node);
    1921 
    1922             VGSvcVerbose(1, "Process %p (PID %RU32) still in list\n", pProcess, pProcess->uPID);
    1923             if (fLast)
    1924                 break;
    1925 
    1926             pProcess = pNext;
    1927         }
    1928 #endif
     1905            {
     1906                rc2 = vgsvcGstCtrlSessionProcessRemoveInternal(pSession, pProcess);
     1907                if (RT_SUCCESS(rc2))
     1908                {
     1909                    VGSvcGstCtrlProcessFree(pProcess);
     1910                    pProcess = NULL;
     1911                }
     1912            }
     1913        }
     1914
     1915        AssertMsg(pSession->cProcesses == 0,
     1916                  ("Session process list still contains %RU32 when it should not\n", pSession->cProcesses));
    19291917        AssertMsg(RTListIsEmpty(&pSession->lstProcesses),
    1930                   ("Guest process list still contains entries when it should not\n"));
     1918                  ("Session process list is not empty when it should\n"));
    19311919
    19321920        /*
     
    19351923        VGSvcVerbose(0, "Closing all guest files ...\n");
    19361924
    1937         PVBOXSERVICECTRLFILE pFile;
    1938         pFile = RTListGetFirst(&pSession->lstFiles, VBOXSERVICECTRLFILE, Node);
    1939         while (pFile)
    1940         {
    1941             PVBOXSERVICECTRLFILE pNext = RTListNodeGetNext(&pFile->Node, VBOXSERVICECTRLFILE, Node);
    1942             bool fLast = RTListNodeIsLast(&pSession->lstFiles, &pFile->Node);
    1943 
    1944             int rc2 = vgsvcGstCtrlSessionFileDestroy(pFile);
     1925        PVBOXSERVICECTRLFILE pFile, pFileNext;
     1926        RTListForEachSafe(&pSession->lstFiles, pFile, pFileNext, VBOXSERVICECTRLFILE, Node)
     1927        {
     1928            int rc2 = vgsvcGstCtrlSessionFileFree(pFile);
    19451929            if (RT_FAILURE(rc2))
    19461930            {
     
    19511935            }
    19521936
    1953             if (fLast)
    1954                 break;
    1955 
    1956             pFile = pNext;
    1957         }
    1958 
    1959         AssertMsg(RTListIsEmpty(&pSession->lstFiles), ("Guest file list still contains entries when it should not\n"));
     1937            pFile = NULL; /* To make it obvious. */
     1938        }
     1939
     1940        AssertMsg(pSession->cFiles == 0,
     1941                  ("Session file list still contains %RU32 when it should not\n", pSession->cFiles));
     1942        AssertMsg(RTListIsEmpty(&pSession->lstFiles),
     1943                  ("Session file list is not empty when it should\n"));
    19601944
    19611945        int rc2 = RTCritSectLeave(&pSession->CritSect);
     
    20332017}
    20342018
     2019/**
     2020 * Removes a guest process from a session's process list.
     2021 * Internal version, does not do locking.
     2022 *
     2023 * @return  VBox status code.
     2024 * @param   pSession                Guest session to remove process from.
     2025 * @param   pProcess                Guest process to remove.
     2026 */
     2027static int vgsvcGstCtrlSessionProcessRemoveInternal(PVBOXSERVICECTRLSESSION pSession, PVBOXSERVICECTRLPROCESS pProcess)
     2028{
     2029    VGSvcVerbose(3, "Removing process (PID %RU32) from session ID=%RU32\n", pProcess->uPID, pSession->StartupInfo.uSessionID);
     2030    AssertReturn(pProcess->cRefs == 0, VERR_WRONG_ORDER);
     2031
     2032    RTListNodeRemove(&pProcess->Node);
     2033
     2034    AssertReturn(pSession->cProcesses, VERR_WRONG_ORDER);
     2035    pSession->cProcesses--;
     2036    VGSvcVerbose(3, "Now session ID=%RU32 has %RU32 processes total\n",
     2037                 pSession->StartupInfo.uSessionID, pSession->cProcesses);
     2038
     2039    return VINF_SUCCESS;
     2040}
    20352041
    20362042/**
     
    20492055    if (RT_SUCCESS(rc))
    20502056    {
    2051         VGSvcVerbose(3, "Removing process (PID %RU32) from session ID=%RU32\n", pProcess->uPID, pSession->StartupInfo.uSessionID);
    2052         AssertReturn(pProcess->cRefs == 0, VERR_WRONG_ORDER);
    2053 
    2054         RTListNodeRemove(&pProcess->Node);
    2055 
    2056         AssertReturn(pSession->cProcesses, VERR_WRONG_ORDER);
    2057         pSession->cProcesses--;
    2058         VGSvcVerbose(3, "Now session ID=%RU32 has %RU32 processes total\n",
    2059                      pSession->StartupInfo.uSessionID, pSession->cProcesses);
     2057        rc = vgsvcGstCtrlSessionProcessRemoveInternal(pSession, pProcess);
    20602058
    20612059        int rc2 = RTCritSectLeave(&pSession->CritSect);
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