Changeset 98614 in vbox
- Timestamp:
- Feb 17, 2023 1:09:38 AM (2 years ago)
- svn:sync-xref-src-repo-rev:
- 155906
- Location:
- trunk/src/VBox/Main
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/GuestProcessImpl.h
r98526 r98614 269 269 270 270 /** Wrapped @name Static run methods. 271 * @{ */ 272 static int run(GuestSession *pGuestSession, const GuestProcessStartupInfo &startupInfo, int *pvrcGuest); 273 274 static int runErrorInfo(GuestSession *pGuestSession, const GuestProcessStartupInfo &startupInfo, GuestProcessToolErrorInfo &errorInfo); 275 276 static int runEx(GuestSession *pGuestSession, const GuestProcessStartupInfo &startupInfo, 277 GuestCtrlStreamObjects *pStrmOutObjects, uint32_t cStrmOutObjects, int *pvrcGuest); 278 279 static int runExErrorInfo(GuestSession *pGuestSession, const GuestProcessStartupInfo &startupInfo, 280 GuestCtrlStreamObjects *pStrmOutObjects, uint32_t cStrmOutObjects, GuestProcessToolErrorInfo &errorInfo); 271 * @note Do not call anything 'run' here, it's way too common. 272 * @{ */ 273 static int runTool(GuestSession *pGuestSession, const GuestProcessStartupInfo &startupInfo, int *pvrcGuest, 274 GuestCtrlStreamObjects *pLstStdOutObjPairs = NULL, uint32_t cStdOutObjectsToRead = 1); 275 276 static int runToolWithErrorInfo(GuestSession *pGuestSession, const GuestProcessStartupInfo &startupInfo, 277 GuestProcessToolErrorInfo &errorInfo, 278 GuestCtrlStreamObjects *pLstStdOutObjPairs = NULL, uint32_t cStdOutObjectsToRead = 1); 281 279 /** @} */ 282 280 -
trunk/src/VBox/Main/src-client/GuestDirectoryImpl.cpp
r98528 r98614 619 619 RT_NOREF(objData); 620 620 vrc = VERR_NOT_SUPPORTED; 621 #else /* VBOX_WITH_GSTCTL_TOOLBOX_SUPPORT */621 #else 622 622 vrc = i_readInternalViaToolbox(objData, pvrcGuest); 623 #endif /* VBOX_WITH_GSTCTL_TOOLBOX_SUPPORT */623 #endif 624 624 #ifdef VBOX_WITH_GSTCTL_TOOLBOX_AS_CMDS 625 625 } -
trunk/src/VBox/Main/src-client/GuestProcessImpl.cpp
r98608 r98614 2417 2417 2418 2418 /** 2419 * Static helper function to start and wait for a certain toolbox tool. 2420 * 2421 * This function most likely is the one you want to use in the first place if you 2422 * want to just use a toolbox tool and wait for its result. See runEx() if you also 2423 * needs its output. 2424 * 2425 * @return VBox status code. 2419 * Static helper function to start and wait for output of a certain toolbox tool. 2420 * 2421 * The optional @a pLstStdOutObjects argument enables the caller to retrieve 2422 * so-called parsable guest stream objects containing additional information on 2423 * a key value pair basis. Those objects are emitted on the guest side by the 2424 * tool to convey retrieve additional information, like names in a directory or 2425 * file statistics, to the host. 2426 * 2427 * @return IPRT status code. 2426 2428 * @param pGuestSession Guest control session to use for starting the toolbox tool in. 2427 2429 * @param startupInfo Startup information about the toolbox tool. 2428 * @param pvrcGuest Where to store the toolbox tool's specific error code in case 2429 * VERR_GSTCTL_GUEST_ERROR is returned. 2430 * @param pvrcGuest Error code returned from the guest side if VERR_GSTCTL_GUEST_ERROR is returned. 2431 * @param pLstStdOutObjects Pointer to vector to receive the stdout 2432 * objects. Optional. 2433 * @param cStdOutObjectsToRead Number of parsable guest stream objects to 2434 * try receive and parse. Ignored when 2435 * pLstStdOutObjects is NULL. Optional. 2430 2436 */ 2431 2437 /* static */ 2432 int GuestProcessToolbox::run(GuestSession *pGuestSession, 2433 GuestProcessStartupInfo const &startupInfo, 2434 int *pvrcGuest /* = NULL */) 2438 int GuestProcessToolbox::runTool(GuestSession *pGuestSession, 2439 GuestProcessStartupInfo const &startupInfo, 2440 int *pvrcGuest, 2441 GuestCtrlStreamObjects *pLstStdOutObjects /* = NULL */, 2442 uint32_t cStdOutObjectsToRead /* = 1 */) 2435 2443 { 2436 2444 GuestProcessToolErrorInfo errorInfo = { VERR_IPE_UNINITIALIZED_STATUS, INT32_MAX }; 2437 int vrc = runErrorInfo(pGuestSession, startupInfo, errorInfo); 2445 int vrc = GuestProcessToolbox::runToolWithErrorInfo(pGuestSession, startupInfo, 2446 errorInfo, pLstStdOutObjects, cStdOutObjectsToRead); 2438 2447 if (RT_SUCCESS(vrc)) 2439 2448 { 2440 /** @todo r=bird: Seems like this is duplicated in the runErrInfo or 2441 * something, because it returns with VERR_GSTCTL_GUEST_ERROR. 2442 * Temporary fix is to always set pvrcGuest before returning. */ 2443 /* Make sure to check the error information we got from the guest tool. */ 2444 if (GuestProcess::i_isGuestError(errorInfo.vrcGuest)) 2445 { 2446 if (errorInfo.vrcGuest == VERR_GSTCTL_PROCESS_EXIT_CODE) /* Translate exit code to a meaningful error code. */ 2447 errorInfo.vrcGuest = GuestProcessToolbox::exitCodeToRc(startupInfo, errorInfo.iExitCode); 2449 /* Translate exit statuses to VBox statuses according to the guest tool: */ 2450 if (errorInfo.vrcGuest == VERR_GSTCTL_PROCESS_EXIT_CODE) 2451 { 2452 errorInfo.vrcGuest = GuestProcessToolbox::exitCodeToRc(startupInfo, errorInfo.iExitCode); 2448 2453 vrc = VERR_GSTCTL_GUEST_ERROR; 2449 2454 } 2450 } 2451 2452 /* See above. */ 2453 if (pvrcGuest) 2454 *pvrcGuest = errorInfo.vrcGuest; 2455 2455 /* In case of something else that may be relevant: */ 2456 else if (errorInfo.vrcGuest == VERR_GSTCTL_PROCESS_WRONG_STATE /* possible getTerminationStatus result, see below */) 2457 vrc = VERR_GSTCTL_GUEST_ERROR; 2458 else 2459 AssertMsg(errorInfo.vrcGuest == VERR_IPE_UNINITIALIZED_STATUS || errorInfo.vrcGuest == VINF_SUCCESS, 2460 ("vrcGuest=%Rrc iExitCode=%d vrc=%Rrc\n", errorInfo.vrcGuest, errorInfo.iExitCode, vrc)); 2461 } 2462 2463 *pvrcGuest = errorInfo.vrcGuest; 2456 2464 LogFlowFunc(("returns %Rrc - vrcGuest=%Rrc iExitCode=%d\n", vrc, errorInfo.vrcGuest, errorInfo.iExitCode)); 2457 2465 return vrc; … … 2459 2467 2460 2468 /** 2461 * Static helper function to start and wait for a certain toolbox tool, returning 2462 * extended error information from the guest. 2469 * Bare-bone version of runTool that doesn't translate exit codes to statuses. 2470 * 2471 * It's currently not used by anyone other than runTool(). 2463 2472 * 2464 2473 * @return VBox status code. … … 2466 2475 * @param startupInfo Startup information about the toolbox tool. 2467 2476 * @param errorInfo Error information returned for error handling. 2477 * @param pLstStdOutObjects Pointer to vector to receive the stdout 2478 * objects. Optional. 2479 * @param cStdOutObjectsToRead Number of parsable guest stream objects to 2480 * try receive and parse. Ignored when 2481 * pLstStdOutObjects is NULL. Optional. 2482 * 2483 * @note This will not do call exitCodeToRc, for that use runTool(). 2468 2484 */ 2469 2485 /* static */ 2470 int GuestProcessToolbox::runErrorInfo(GuestSession *pGuestSession, 2471 GuestProcessStartupInfo const &startupInfo, 2472 GuestProcessToolErrorInfo &errorInfo) 2473 { 2474 return runExErrorInfo(pGuestSession, startupInfo, NULL /* paStrmOutObjects */, 0 /* cStrmOutObjects */, errorInfo); 2475 } 2476 2477 /** 2478 * Static helper function to start and wait for output of a certain toolbox tool. 2479 * 2480 * @return IPRT status code. 2481 * @param pGuestSession Guest control session to use for starting the toolbox tool in. 2482 * @param startupInfo Startup information about the toolbox tool. 2483 * @param paStrmOutObjects Pointer to stream objects array to use for retrieving the output of the toolbox tool. 2484 * Optional. 2485 * @param cStrmOutObjects Number of stream objects passed in. Optional. 2486 * @param pvrcGuest Error code returned from the guest side if VERR_GSTCTL_GUEST_ERROR is returned. Optional. 2487 */ 2488 /* static */ 2489 int GuestProcessToolbox::runEx(GuestSession *pGuestSession, 2490 GuestProcessStartupInfo const &startupInfo, 2491 GuestCtrlStreamObjects *paStrmOutObjects, 2492 uint32_t cStrmOutObjects, 2493 int *pvrcGuest /* = NULL */) 2494 { 2495 int vrcGuest = VERR_IPE_UNINITIALIZED_STATUS; 2496 2497 GuestProcessToolErrorInfo errorInfo = { VERR_IPE_UNINITIALIZED_STATUS, INT32_MAX }; 2498 int vrc = GuestProcessToolbox::runExErrorInfo(pGuestSession, startupInfo, paStrmOutObjects, cStrmOutObjects, errorInfo); 2499 if (RT_SUCCESS(vrc)) 2500 { 2501 /* Make sure to check the error information we got from the guest tool. */ 2502 if (GuestProcess::i_isGuestError(errorInfo.vrcGuest)) 2503 { 2504 if (errorInfo.vrcGuest == VERR_GSTCTL_PROCESS_EXIT_CODE) /* Translate exit code to a meaningful error code. */ 2505 vrcGuest = GuestProcessToolbox::exitCodeToRc(startupInfo, errorInfo.iExitCode); 2506 else /* At least return something. */ 2507 vrcGuest = errorInfo.vrcGuest; 2508 2509 if (pvrcGuest) 2510 *pvrcGuest = vrcGuest; 2511 2512 vrc = VERR_GSTCTL_GUEST_ERROR; 2513 } 2514 } 2515 2516 LogFlowFunc(("returns %Rrc - vrcGuest=%Rrc iExitCode=%d\n", vrc, errorInfo.vrcGuest, errorInfo.iExitCode)); 2517 return vrc; 2518 } 2519 2520 /** 2521 * Static helper function to start and wait for output of a certain toolbox tool. 2522 * 2523 * This is the extended version, which addds the possibility of retrieving parsable so-called guest stream 2524 * objects. Those objects are issued on the guest side as part of VBoxService's toolbox tools (think of a BusyBox-like approach) 2525 * on stdout and can be used on the host side to retrieve more information about the actual command issued on the guest side. 2526 * 2527 * @return VBox status code. 2528 * @param pGuestSession Guest control session to use for starting the toolbox tool in. 2529 * @param startupInfo Startup information about the toolbox tool. 2530 * @param paStrmOutObjects Pointer to stream objects array to use for retrieving the output of the toolbox tool. 2531 * Optional. 2532 * @param cStrmOutObjects Number of stream objects passed in. Optional. 2533 * @param errorInfo Error information returned for error handling. 2534 */ 2535 /* static */ 2536 int GuestProcessToolbox::runExErrorInfo(GuestSession *pGuestSession, 2537 GuestProcessStartupInfo const &startupInfo, 2538 GuestCtrlStreamObjects *paStrmOutObjects, 2539 uint32_t cStrmOutObjects, 2540 GuestProcessToolErrorInfo &errorInfo) 2541 { 2542 AssertPtrReturn(pGuestSession, VERR_INVALID_POINTER); 2543 /* paStrmOutObjects is optional. */ 2544 2545 /** @todo Check if this is a valid toolbox. */ 2546 2486 int GuestProcessToolbox::runToolWithErrorInfo(GuestSession *pGuestSession, 2487 GuestProcessStartupInfo const &startupInfo, 2488 GuestProcessToolErrorInfo &errorInfo, 2489 GuestCtrlStreamObjects *pLstStdOutObjects /* = NULL */, 2490 uint32_t cStdOutObjectsToRead /* = 1 */) 2491 { 2547 2492 GuestProcessToolbox procTool; 2548 int vrc = procTool.init(pGuestSession, startupInfo, false /* Async */, &errorInfo.vrcGuest); 2549 if (RT_SUCCESS(vrc)) 2550 { 2551 while (cStrmOutObjects--) 2552 { 2493 int vrc = procTool.init(pGuestSession, startupInfo, false /* fAsync */, &errorInfo.vrcGuest); 2494 if (pLstStdOutObjects) 2495 while (RT_SUCCESS(vrc) && cStdOutObjectsToRead-- > 0) 2553 2496 try 2554 2497 { 2555 2498 GuestToolboxStreamBlock strmBlk; 2556 vrc = procTool.waitEx(paStrmOutObjects 2557 ? GUESTPROCESSTOOL_WAIT_FLAG_STDOUT_BLOCK 2558 : GUESTPROCESSTOOL_WAIT_FLAG_NONE, 2559 &strmBlk, &errorInfo.vrcGuest); 2560 if (paStrmOutObjects) 2561 paStrmOutObjects->push_back(strmBlk); 2499 vrc = procTool.waitEx(GUESTPROCESSTOOL_WAIT_FLAG_STDOUT_BLOCK, &strmBlk, &errorInfo.vrcGuest); 2500 pLstStdOutObjects->push_back(strmBlk); 2562 2501 } 2563 2502 catch (std::bad_alloc &) … … 2565 2504 vrc = VERR_NO_MEMORY; 2566 2505 } 2567 2568 if (RT_FAILURE(vrc))2569 break;2570 }2571 }2572 2573 2506 if (RT_SUCCESS(vrc)) 2574 2507 { … … 2587 2520 * Reports if the tool has been run correctly. 2588 2521 * 2589 * @ret urn Will return VERR_GSTCTL_PROCESS_EXIT_CODE if the tool process returned an exit code <> 0,2590 * VERR_GSTCTL_PROCESS_WRONG_STATE if the tool process is in a wrong state (e.g. still running),2591 * or VINF_SUCCESS otherwise.2522 * @retval VINF_SUCCESS if the process has stopped and the exit code is zero. 2523 * @retval VERR_GSTCTL_PROCESS_EXIT_CODE if the exit code is _not_ zero. 2524 * @retval VERR_GSTCTL_PROCESS_WRONG_STATE if still running. 2592 2525 * 2593 2526 * @param piExitCode Exit code of the tool. Optional. … … 2596 2529 { 2597 2530 Assert(!pProcess.isNull()); 2598 /* pExitCode is optional. */2531 AssertPtrNull(piExitCode); 2599 2532 2600 2533 int vrc; … … 2608 2541 *piExitCode = iExitCode; 2609 2542 2610 vrc = iExitCode != 0 ? VERR_GSTCTL_PROCESS_EXIT_CODE : VINF_SUCCESS;2543 vrc = iExitCode == 0 ? VINF_SUCCESS : VERR_GSTCTL_PROCESS_EXIT_CODE; 2611 2544 } 2612 2545 else 2546 { 2547 if (piExitCode) 2548 *piExitCode = -1; 2613 2549 vrc = VERR_GSTCTL_PROCESS_WRONG_STATE; 2550 } 2614 2551 2615 2552 LogFlowFuncLeaveRC(vrc); … … 2668 2605 bool fDone = false; 2669 2606 2670 BYTE byBuf[_64K];2607 BYTE abBuf[_64K]; 2671 2608 uint32_t cbRead; 2672 2609 … … 2690 2627 * Returns the remaining time (in ms). 2691 2628 */ 2692 #define GET_REMAINING_TIME \ 2693 uTimeoutMS == RT_INDEFINITE_WAIT \ 2694 ? RT_INDEFINITE_WAIT : uTimeoutMS - (uint32_t)u64ElapsedMS \ 2629 #define GET_REMAINING_TIME (uTimeoutMS == RT_INDEFINITE_WAIT ? RT_INDEFINITE_WAIT : uTimeoutMS - (uint32_t)u64ElapsedMS) 2695 2630 2696 2631 ProcessWaitResult_T waitRes = ProcessWaitResult_None; … … 2758 2693 2759 2694 cbRead = 0; 2760 vrc = pProcess->i_readData(GUEST_PROC_OUT_H_STDOUT, sizeof( byBuf),2695 vrc = pProcess->i_readData(GUEST_PROC_OUT_H_STDOUT, sizeof(abBuf), 2761 2696 GET_REMAINING_TIME, 2762 byBuf, sizeof(byBuf),2697 abBuf, sizeof(abBuf), 2763 2698 &cbRead, &vrcGuest); 2764 2699 if ( RT_FAILURE(vrc) … … 2769 2704 { 2770 2705 LogFlowThisFunc(("Received %RU32 bytes from stdout\n", cbRead)); 2771 vrc = mStdOut.AddData( byBuf, cbRead);2706 vrc = mStdOut.AddData(abBuf, cbRead); 2772 2707 2773 2708 if ( RT_SUCCESS(vrc) … … 2792 2727 2793 2728 cbRead = 0; 2794 vrc = pProcess->i_readData(GUEST_PROC_OUT_H_STDERR, sizeof( byBuf),2729 vrc = pProcess->i_readData(GUEST_PROC_OUT_H_STDERR, sizeof(abBuf), 2795 2730 GET_REMAINING_TIME, 2796 byBuf, sizeof(byBuf),2731 abBuf, sizeof(abBuf), 2797 2732 &cbRead, &vrcGuest); 2798 2733 if ( RT_FAILURE(vrc) … … 2803 2738 { 2804 2739 LogFlowThisFunc(("Received %RU32 bytes from stderr\n", cbRead)); 2805 vrc = mStdErr.AddData( byBuf, cbRead);2740 vrc = mStdErr.AddData(abBuf, cbRead); 2806 2741 } 2807 2742 -
trunk/src/VBox/Main/src-client/GuestSessionImpl.cpp
r98610 r98614 1029 1029 1030 1030 if (RT_SUCCESS(vrc)) 1031 vrc = GuestProcessToolbox::run (this, procInfo, pvrcGuest);1031 vrc = GuestProcessToolbox::runTool(this, procInfo, pvrcGuest); 1032 1032 #endif /* VBOX_WITH_GSTCTL_TOOLBOX_SUPPORT */ 1033 1033 } … … 1303 1303 1304 1304 GuestCtrlStreamObjects stdOut; 1305 vrc = GuestProcessToolbox::run Ex(this, procInfo, &stdOut, 1 /* cStrmOutObjects */, &vrcGuest);1305 vrc = GuestProcessToolbox::runTool(this, procInfo, &vrcGuest, &stdOut); 1306 1306 if (!GuestProcess::i_isGuestError(vrc)) 1307 1307 { … … 1734 1734 1735 1735 GuestCtrlStreamObjects stdOut; 1736 vrc = GuestProcessToolbox::run Ex(this, procInfo, &stdOut, 1 /* cStrmOutObjects */, &vrcGuest);1737 if ( GuestProcess::i_isGuestError(vrc))1736 vrc = GuestProcessToolbox::runTool(this, procInfo, &vrcGuest, &stdOut); 1737 if (!GuestProcess::i_isGuestError(vrc)) 1738 1738 { 1739 1739 if (!stdOut.empty()) … … 2040 2040 try 2041 2041 { 2042 procInfo.mExecutable = Utf8Str(VBOXSERVICE_TOOL_STAT);2042 procInfo.mExecutable = VBOXSERVICE_TOOL_STAT; 2043 2043 procInfo.mArguments.push_back(procInfo.mExecutable); /* Set argv0. */ 2044 2044 procInfo.mArguments.push_back(Utf8Str("--machinereadable")); … … 2055 2055 2056 2056 GuestCtrlStreamObjects stdOut; 2057 vrc = GuestProcessToolbox::run Ex(this, procInfo, &stdOut, 1 /* cStrmOutObjects */, &vrcGuest);2057 vrc = GuestProcessToolbox::runTool(this, procInfo, &vrcGuest, &stdOut); 2058 2058 if (!GuestProcess::i_isGuestError(vrc)) 2059 2059 {
Note:
See TracChangeset
for help on using the changeset viewer.