VirtualBox

Changeset 49221 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Oct 22, 2013 7:35:56 AM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
90113
Message:

FE/VBoxManage/GuestCtrl: Integrated waiting for guest sessions to start in common startup code, save the session ID in command context.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageGuestCtrl.cpp

    r49166 r49221  
    116116    /** Pointer to the to be used guest session. */
    117117    ComPtr<IGuestSession> pGuestSession;
     118    /** The guest session ID. */
     119    ULONG uSessionID;
    118120
    119121} GCTLCMDCTX, *PGCTLCMDCTX;
     
    693695            else if (pCtx->fVerbose)
    694696                RTPrintf("Guest session detached\n");
     697
     698            pCtx->pGuestSession.setNull();
     699            g_pGuestSession.setNull();
    695700        }
    696701
     
    893898                                                              Bstr(pszSessionName).raw(),
    894899                                                              pCtx->pGuestSession.asOutParam()));
     900
     901                /*
     902                 * Wait for guest session to start.
     903                 */
     904                if (pCtx->fVerbose)
     905                    RTPrintf("Waiting for guest session to start ...\n");
     906
     907                com::SafeArray<GuestSessionWaitForFlag_T> aSessionWaitFlags;
     908                aSessionWaitFlags.push_back(GuestSessionWaitForFlag_Start);
     909                GuestSessionWaitResult_T sessionWaitResult;
     910                CHECK_ERROR_BREAK(pCtx->pGuestSession, WaitForArray(ComSafeArrayAsInParam(aSessionWaitFlags),
     911                                                                    /** @todo Make session handling timeouts configurable. */
     912                                                                    30 * 1000, &sessionWaitResult));
     913
     914                if (   sessionWaitResult == GuestSessionWaitResult_Start
     915                    /* Note: This might happen when Guest Additions < 4.3 are installed which don't
     916                     *       support dedicated guest sessions. */
     917                    || sessionWaitResult == GuestSessionWaitResult_WaitFlagNotSupported)
     918                {
     919                    CHECK_ERROR_BREAK(pCtx->pGuestSession, COMGETTER(Id)(&pCtx->uSessionID));
     920                    if (pCtx->fVerbose)
     921                        RTPrintf("Guest session (ID %RU32) has been started\n", pCtx->uSessionID);
     922                }
     923                else
     924                {
     925                    GuestSessionStatus_T sessionStatus;
     926                    CHECK_ERROR_BREAK(pCtx->pGuestSession, COMGETTER(Status)(&sessionStatus));
     927                    rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "Error starting guest session (current status is: %s)\n",
     928                                            ctrlSessionStatusToText(sessionStatus));
     929                    break;
     930                }
    895931            }
    896932
    897             if (!(uFlags & CTLCMDCTX_FLAGS_NO_SIGNAL_HANDLER))
     933            if (   SUCCEEDED(rc)
     934                && !(uFlags & CTLCMDCTX_FLAGS_NO_SIGNAL_HANDLER))
     935            {
     936                /* Add session to global for being accessible by the
     937                 * signal handler. */
     938                g_pGuestSession = pCtx->pGuestSession;
     939
    898940                ctrlSignalHandlerInstall();
     941            }
    899942
    900943        } while (0);
     
    11661209            uint64_t u64StartMS = RTTimeMilliTS();
    11671210
    1168             /*
    1169              * Wait for guest session to start.
    1170              */
    1171             if (pCtx->fVerbose)
    1172             {
    1173                 if (cMsTimeout == 0)
    1174                     RTPrintf("Waiting for guest session to start ...\n");
    1175                 else
    1176                     RTPrintf("Waiting for guest session to start (within %ums)\n", cMsTimeout);
    1177             }
    1178 
    1179             com::SafeArray<GuestSessionWaitForFlag_T> aSessionWaitFlags;
    1180             aSessionWaitFlags.push_back(GuestSessionWaitForFlag_Start);
    1181             GuestSessionWaitResult_T sessionWaitResult;
    1182             CHECK_ERROR_BREAK(g_pGuestSession, WaitForArray(ComSafeArrayAsInParam(aSessionWaitFlags), cMsTimeout, &sessionWaitResult));
    1183             ULONG uSessionID;
    1184             CHECK_ERROR_BREAK(g_pGuestSession, COMGETTER(Id)(&uSessionID));
    1185 
    1186             if (   sessionWaitResult == GuestSessionWaitResult_Start
    1187                 /* Note: This might happen when Guest Additions < 4.3 are installed which don't
    1188                  *       support dedicated guest sessions. */
    1189                 || sessionWaitResult == GuestSessionWaitResult_WaitFlagNotSupported)
    1190             {
    1191                 if (pCtx->fVerbose)
    1192                     RTPrintf("Guest session (ID %RU32) has been started\n", uSessionID);
    1193             }
    1194             else
    1195             {
    1196                 RTPrintf("Error starting guest session\n");
    1197                 break;
    1198             }
    1199 
    12001211            if (pCtx->fVerbose)
    12011212            {
     
    12101221             */
    12111222            ComPtr<IGuestProcess> pProcess;
    1212             CHECK_ERROR_BREAK(g_pGuestSession, ProcessCreate(Bstr(strCmd).raw(),
    1213                                                            ComSafeArrayAsInParam(aArgs),
    1214                                                            ComSafeArrayAsInParam(aEnv),
    1215                                                            ComSafeArrayAsInParam(aCreateFlags),
    1216                                                            cMsTimeout,
    1217                                                            pProcess.asOutParam()));
     1223            CHECK_ERROR_BREAK(pCtx->pGuestSession, ProcessCreate(Bstr(strCmd).raw(),
     1224                                                                 ComSafeArrayAsInParam(aArgs),
     1225                                                                 ComSafeArrayAsInParam(aEnv),
     1226                                                                 ComSafeArrayAsInParam(aCreateFlags),
     1227                                                                 cMsTimeout,
     1228                                                                 pProcess.asOutParam()));
    12181229
    12191230            /** @todo does this need signal handling? there's no progress object etc etc */
     
    12531264                            /* Just print plain PID to make it easier for scripts
    12541265                             * invoking VBoxManage. */
    1255                             RTPrintf("%RU32, session ID %RU32\n", uPID, uSessionID);
     1266                            RTPrintf("%RU32, session ID %RU32\n", uPID, pCtx->uSessionID);
    12561267                        }
    12571268
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