VirtualBox

Changeset 93720 in vbox for trunk/src/VBox/Main/src-client


Ignore:
Timestamp:
Feb 14, 2022 12:10:12 PM (3 years ago)
Author:
vboxsync
Message:

Guest Control/Main: Return an error in IGuestProcess::terminate() if the guest process is not in a running state (anymore). Useful for testcases.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-client/GuestProcessImpl.cpp

    r93115 r93720  
    416416    LogFlowThisFuncEnter();
    417417
    418     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    419 
    420     *aStatus = mData.mStatus;
     418    *aStatus = i_getStatus();
    421419
    422420    return S_OK;
     
    513511
    514512    return rc;
     513}
     514
     515/**
     516 * Returns the current process status.
     517 *
     518 * @returns Current process status.
     519 *
     520 * @note    Takes the read lock.
     521 */
     522ProcessStatus_T GuestProcess::i_getStatus(void)
     523{
     524    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     525
     526    return mData.mStatus;
    515527}
    516528
     
    551563
    552564    return strErr;
     565}
     566
     567/**
     568 * Translates a process status to a human readable string.
     569 *
     570 * @returns Process status as a string.
     571 * @param   enmStatus           Guest process status to return string for.
     572 */
     573/* static */
     574Utf8Str GuestProcess::i_statusToString(ProcessStatus_T enmStatus)
     575{
     576    switch (enmStatus)
     577    {
     578        case ProcessStatus_Starting:
     579            return "starting";
     580        case ProcessStatus_Started:
     581            return "started";
     582        case ProcessStatus_Paused:
     583            return "paused";
     584        case ProcessStatus_Terminating:
     585            return "terminating";
     586        case ProcessStatus_TerminatedNormally:
     587            return "successfully terminated";
     588        case ProcessStatus_TerminatedSignal:
     589            return "terminated by signal";
     590        case ProcessStatus_TerminatedAbnormally:
     591            return "abnormally aborted";
     592        case ProcessStatus_TimedOutKilled:
     593            return "timed out";
     594        case ProcessStatus_TimedOutAbnormally:
     595            return "timed out, hanging";
     596        case ProcessStatus_Down:
     597            return "killed";
     598        case ProcessStatus_Error:
     599            return "error";
     600        default:
     601            break;
     602    }
     603
     604    AssertFailed(); /* Should never happen! */
     605    return "unknown";
    553606}
    554607
     
    20242077    int rcGuest = VERR_IPE_UNINITIALIZED_STATUS;
    20252078    int vrc = i_terminateProcess(30 * 1000 /* Timeout in ms */, &rcGuest);
    2026     if (RT_FAILURE(vrc))
    2027     {
    2028         switch (vrc)
    2029         {
    2030             case VERR_GSTCTL_GUEST_ERROR:
    2031             {
    2032                 GuestErrorInfo ge(GuestErrorInfo::Type_Process, rcGuest, mData.mProcess.mExecutable.c_str());
    2033                 hr = setErrorBoth(VBOX_E_IPRT_ERROR, rcGuest, tr("Terminating guest process failed: %s"),
    2034                                   GuestBase::getErrorAsString(ge).c_str());
    2035                 break;
    2036             }
    2037             case VERR_NOT_SUPPORTED:
    2038                 hr = setErrorBoth(VBOX_E_IPRT_ERROR, vrc,
    2039                                   tr("Terminating guest process \"%s\" (PID %RU32) not supported by installed Guest Additions"),
    2040                                   mData.mProcess.mExecutable.c_str(), mData.mPID);
    2041                 break;
    2042 
    2043             default:
    2044                 hr = setErrorBoth(VBOX_E_IPRT_ERROR, vrc, tr("Terminating guest process \"%s\" (PID %RU32) failed: %Rrc"),
    2045                                   mData.mProcess.mExecutable.c_str(), mData.mPID, vrc);
    2046                 break;
    2047         }
    2048     }
    2049 
    2050     if (vrc == VINF_SUCCESS) /* Note: Also could be VWRN_INVALID_STATE from i_terminateProcess(). */
     2079
     2080    switch (vrc)
     2081    {
     2082        case VINF_SUCCESS:
     2083            /* Nothing to do here, all good. */
     2084            break;
     2085
     2086        case VWRN_INVALID_STATE:
     2087        {
     2088            GuestErrorInfo ge(GuestErrorInfo::Type_Process, rcGuest, mData.mProcess.mExecutable.c_str());
     2089            hr = setErrorBoth(VBOX_E_IPRT_ERROR, VWRN_INVALID_STATE,
     2090                              tr("Guest process is not in '%s' state anymore (current is in '%s')"),
     2091                              GuestProcess::i_statusToString(ProcessStatus_Started).c_str(),
     2092                              GuestProcess::i_statusToString(i_getStatus()).c_str());
     2093            break;
     2094        }
     2095
     2096        case VERR_GSTCTL_GUEST_ERROR:
     2097        {
     2098            GuestErrorInfo ge(GuestErrorInfo::Type_Process, rcGuest, mData.mProcess.mExecutable.c_str());
     2099            hr = setErrorBoth(VBOX_E_IPRT_ERROR, rcGuest, tr("Terminating guest process failed: %s"),
     2100                              GuestBase::getErrorAsString(ge).c_str());
     2101            break;
     2102        }
     2103
     2104        case VERR_NOT_SUPPORTED:
     2105        {
     2106            hr = setErrorBoth(VBOX_E_IPRT_ERROR, vrc,
     2107                              tr("Terminating guest process \"%s\" (PID %RU32) not supported by installed Guest Additions"),
     2108                              mData.mProcess.mExecutable.c_str(), mData.mPID);
     2109            break;
     2110        }
     2111
     2112        default:
     2113            hr = setErrorBoth(VBOX_E_IPRT_ERROR, vrc, tr("Terminating guest process \"%s\" (PID %RU32) failed: %Rrc"),
     2114                              mData.mProcess.mExecutable.c_str(), mData.mPID, vrc);
     2115            break;
     2116    }
     2117
     2118    /* Note: Also could be VWRN_INVALID_STATE from i_terminateProcess().
     2119     *       In such a case we have to keep the process in our list in order to fullfill any upcoming responses / requests. */
     2120    if (vrc == VINF_SUCCESS)
    20512121    {
    20522122        /* Remove process from guest session list. Now only API clients
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