VirtualBox

Changeset 49439 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Nov 11, 2013 3:30:42 PM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
90546
Message:

FE/VBoxManage: GuestCtrl: Explicitly wait for guest process to start, a bit more work on detached process handling.

File:
1 edited

Legend:

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

    r49397 r49439  
    559559}
    560560
     561const char *ctrlProcessWaitResultToText(ProcessWaitResult_T enmWaitResult)
     562{
     563    switch (enmWaitResult)
     564    {
     565        case ProcessWaitResult_Start:
     566            return "started";
     567        case ProcessWaitResult_Terminate:
     568            return "terminated";
     569        case ProcessWaitResult_Status:
     570            return "status changed";
     571        case ProcessWaitResult_Error:
     572            return "error";
     573        case ProcessWaitResult_Timeout:
     574            return "timed out";
     575        case ProcessWaitResult_StdIn:
     576            return "stdin ready";
     577        case ProcessWaitResult_StdOut:
     578            return "data on stdout";
     579        case ProcessWaitResult_StdErr:
     580            return "data on stderr";
     581        case ProcessWaitResult_WaitFlagNotSupported:
     582            return "waiting flag not supported";
     583        default:
     584            break;
     585    }
     586    return "unknown";
     587}
     588
    561589/**
    562590 * Translates a guest session status to a human readable
     
    12541282            {
    12551283                if (cMsTimeout == 0)
    1256                     RTPrintf("Waiting for guest process to start ...\n");
     1284                    RTPrintf("Starting guest process ...\n");
    12571285                else
    1258                     RTPrintf("Waiting for guest process to start (within %ums)\n", cMsTimeout);
     1286                    RTPrintf("Starting guest process (within %ums)\n", cMsTimeout);
    12591287            }
    12601288
     
    12671295                                                                 ComSafeArrayAsInParam(aEnv),
    12681296                                                                 ComSafeArrayAsInParam(aCreateFlags),
    1269                                                                  cMsTimeout,
     1297                                                                 ctrlExecGetRemainingTime(u64StartMS, cMsTimeout),
    12701298                                                                 pProcess.asOutParam()));
    12711299
    1272             /** @todo does this need signal handling? there's no progress object etc etc */
     1300            /*
     1301             * Explicitly wait for the guest process to be in a started
     1302             * state.
     1303             */
     1304            com::SafeArray<ProcessWaitForFlag_T> aWaitStartFlags;
     1305            aWaitStartFlags.push_back(ProcessWaitForFlag_Start);
     1306            ProcessWaitResult_T waitResult;
     1307            CHECK_ERROR_BREAK(pProcess, WaitForArray(ComSafeArrayAsInParam(aWaitStartFlags),
     1308                                                     ctrlExecGetRemainingTime(u64StartMS, cMsTimeout), &waitResult));
     1309            bool fCompleted = false;
     1310
     1311            ULONG uPID = 0;
     1312            CHECK_ERROR_BREAK(pProcess, COMGETTER(PID)(&uPID));
     1313            if (!fDetached && pCtx->fVerbose)
     1314            {
     1315                RTPrintf("Process '%s' (PID %RU32) started\n",
     1316                         strCmd.c_str(), uPID);
     1317            }
     1318            else if (fDetached) /** @todo Introduce a --quiet option for not printing this. */
     1319            {
     1320                /* Just print plain PID to make it easier for scripts
     1321                 * invoking VBoxManage. */
     1322                RTPrintf("[%RU32 - Session %RU32]\n", uPID, pCtx->uSessionID);
     1323            }
    12731324
    12741325            vrc = RTStrmSetMode(g_pStdOut, 1 /* Binary mode */, -1 /* Code set, unchanged */);
     
    12801331
    12811332            /* Wait for process to exit ... */
    1282             RTMSINTERVAL cMsTimeLeft = 1;
     1333            RTMSINTERVAL cMsTimeLeft = 1; /* Will be calculated. */
    12831334            bool fReadStdOut, fReadStdErr;
    12841335            fReadStdOut = fReadStdErr = false;
    12851336
    1286             bool fCompleted = false;
    1287             while (!fCompleted && cMsTimeLeft != 0)
     1337            while (   !fCompleted
     1338                   && !fDetached
     1339                   && cMsTimeLeft != 0)
    12881340            {
    12891341                cMsTimeLeft = ctrlExecGetRemainingTime(u64StartMS, cMsTimeout);
    1290                 ProcessWaitResult_T waitResult;
    12911342                CHECK_ERROR_BREAK(pProcess, WaitForArray(ComSafeArrayAsInParam(aWaitFlags),
    12921343                                                         cMsTimeLeft, &waitResult));
     
    12951346                    case ProcessWaitResult_Start:
    12961347                    {
    1297                         ULONG uPID = 0;
    1298                         CHECK_ERROR_BREAK(pProcess, COMGETTER(PID)(&uPID));
    1299                         if (pCtx->fVerbose)
    1300                         {
    1301                             RTPrintf("Process '%s' (PID %RU32) started\n",
    1302                                      strCmd.c_str(), uPID);
    1303                         }
    1304                         else /** @todo Introduce a --quiet option for not printing this. */
    1305                         {
    1306                             /* Just print plain PID to make it easier for scripts
    1307                              * invoking VBoxManage. */
    1308                             RTPrintf("%RU32, session ID %RU32\n", uPID, pCtx->uSessionID);
    1309                         }
    1310 
    13111348                        /* We're done here if we don't want to wait for termination. */
    13121349                        if (fDetached)
     
    13221359                        break;
    13231360                    case ProcessWaitResult_Terminate:
    1324                         /* Process terminated, we're done */
     1361                        if (pCtx->fVerbose)
     1362                            RTPrintf("Process terminated\n");
     1363                        /* Process terminated, we're done. */
    13251364                        fCompleted = true;
    13261365                        break;
     
    13721411            } /* while */
    13731412
    1374             /* Report status back to the user. */
    1375             if (   fCompleted
    1376                 && !g_fGuestCtrlCanceled)
     1413            if (!fDetached)
    13771414            {
    1378                 ProcessStatus_T procStatus;
    1379                 CHECK_ERROR_BREAK(pProcess, COMGETTER(Status)(&procStatus));
    1380                 if (   procStatus == ProcessStatus_TerminatedNormally
    1381                     || procStatus == ProcessStatus_TerminatedAbnormally
    1382                     || procStatus == ProcessStatus_TerminatedSignal)
     1415                /* Report status back to the user. */
     1416                if (   fCompleted
     1417                    && !g_fGuestCtrlCanceled)
    13831418                {
    1384                     LONG exitCode;
    1385                     CHECK_ERROR_BREAK(pProcess, COMGETTER(ExitCode)(&exitCode));
     1419
     1420                    {
     1421                        ProcessStatus_T procStatus;
     1422                        CHECK_ERROR_BREAK(pProcess, COMGETTER(Status)(&procStatus));
     1423                        if (   procStatus == ProcessStatus_TerminatedNormally
     1424                            || procStatus == ProcessStatus_TerminatedAbnormally
     1425                            || procStatus == ProcessStatus_TerminatedSignal)
     1426                        {
     1427                            LONG exitCode;
     1428                            CHECK_ERROR_BREAK(pProcess, COMGETTER(ExitCode)(&exitCode));
     1429                            if (pCtx->fVerbose)
     1430                                RTPrintf("Exit code=%u (Status=%u [%s])\n",
     1431                                         exitCode, procStatus, ctrlProcessStatusToText(procStatus));
     1432
     1433                            rcExit = (RTEXITCODE)ctrlExecProcessStatusToExitCode(procStatus, exitCode);
     1434                        }
     1435                        else if (pCtx->fVerbose)
     1436                            RTPrintf("Process now is in status [%s]\n", ctrlProcessStatusToText(procStatus));
     1437                    }
     1438                }
     1439                else
     1440                {
    13861441                    if (pCtx->fVerbose)
    1387                         RTPrintf("Exit code=%u (Status=%u [%s])\n",
    1388                                  exitCode, procStatus, ctrlProcessStatusToText(procStatus));
    1389 
    1390                     rcExit = (RTEXITCODE)ctrlExecProcessStatusToExitCode(procStatus, exitCode);
     1442                        RTPrintf("Process execution aborted!\n");
     1443
     1444                    rcExit = (RTEXITCODE)EXITCODEEXEC_TERM_ABEND;
    13911445                }
    1392                 else if (pCtx->fVerbose)
    1393                     RTPrintf("Process now is in status [%s]\n", ctrlProcessStatusToText(procStatus));
    13941446            }
    1395             else
    1396             {
    1397                 if (pCtx->fVerbose)
    1398                     RTPrintf("Process execution aborted!\n");
    1399 
    1400                 rcExit = (RTEXITCODE)EXITCODEEXEC_TERM_ABEND;
    1401             }
    14021447
    14031448        } while (0);
     
    14081453    }
    14091454
     1455    /*
     1456     * Decide what to do with the guest session. If we started a
     1457     * detached guest process (that is, without waiting for it to exit),
     1458     * don't close the guest session it is part of.
     1459     */
    14101460    bool fCloseSession = false;
    14111461    if (SUCCEEDED(rc))
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