VirtualBox

Changeset 84548 in vbox


Ignore:
Timestamp:
May 26, 2020 5:43:31 PM (4 years ago)
Author:
vboxsync
Message:

Guest Control: Implemented guest side support for gracefully rebooting / shutting down the guest. Untested. bugref:9320

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/HostServices/GuestControlSvc.h

    r84243 r84548  
    211211     */
    212212    HOST_MSG_PATH_USER_HOME,
     213    /**
     214     * Issues a shutdown / reboot of the guest OS.
     215     */
     216    HOST_MSG_SHUTDOWN,
    213217
    214218    /** Blow the type up to 32-bits. */
     
    248252        RT_CASE_RET_STR(HOST_MSG_PATH_USER_DOCUMENTS);
    249253        RT_CASE_RET_STR(HOST_MSG_PATH_USER_HOME);
     254        RT_CASE_RET_STR(HOST_MSG_SHUTDOWN);
    250255        RT_CASE_RET_STR(HOST_MSG_32BIT_HACK);
    251256    }
     
    699704 *  GUESTPROCESS_DEFAULT_CMD_LEN / GUESTPROCESS_DEFAULT_ARGS_LEN / GUESTPROCESS_DEFAULT_ENV_LEN (bytes, in total). */
    700705#define VBOX_GUESTCTRL_GF_0_PROCESS_DYNAMIC_SIZES   RT_BIT_64(2)
     706/** Supports shutting down / rebooting the guest. */
     707#define VBOX_GUESTCTRL_GF_0_SHUTDOWN                RT_BIT_64(3)
    701708/** Bit that must be set in the 2nd parameter, will be cleared if the host reponds
    702709 * correctly (old hosts might not). */
     
    873880    HGCMFunctionParameter context;
    874881} HGCMMsgPathUserHome;
     882
     883/**
     884 * Shuts down / reboots the guest.
     885 */
     886typedef struct HGCMMsgShutdown
     887{
     888    VBGLIOCHGCMCALL hdr;
     889    /** UInt32: Context ID. */
     890    HGCMFunctionParameter context;
     891    /** UInt32: Action flags. */
     892    HGCMFunctionParameter action;
     893} HGCMMsgShutdown;
    875894
    876895/**
  • trunk/include/VBox/VBoxGuestLib.h

    r84215 r84548  
    10421042VBGLR3DECL(int) VbglR3GuestCtrlPathGetUserDocuments(PVBGLR3GUESTCTRLCMDCTX pCtx);
    10431043VBGLR3DECL(int) VbglR3GuestCtrlPathGetUserHome(PVBGLR3GUESTCTRLCMDCTX pCtx);
     1044VBGLR3DECL(int) VbglR3GuestCtrlGetShutdown(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t *pfAction);
    10441045/* Guest process execution. */
    10451046VBGLR3DECL(int) VbglR3GuestCtrlProcStartupInfoInit(PVBGLR3GUESTCTRLPROCSTARTUPINFO pStartupInfo);
  • trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR3LibGuestCtrl.cpp

    r84238 r84548  
    10271027
    10281028/**
     1029 * Retrieves a HOST_MSG_SHUTDOWN message.
     1030 *
     1031 * @returns VBox status code.
     1032 * @param   pCtx                Guest control command context to use.
     1033 * @param   pfAction            Where to store the action flags on success.
     1034 */
     1035VBGLR3DECL(int) VbglR3GuestCtrlGetShutdown(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t *pfAction)
     1036{
     1037    AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
     1038    AssertReturn(pCtx->uNumParms == 1, VERR_INVALID_PARAMETER);
     1039
     1040    int rc;
     1041    do
     1042    {
     1043        HGCMMsgShutdown Msg;
     1044        VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
     1045        VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_SHUTDOWN);
     1046
     1047        rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
     1048        if (RT_SUCCESS(rc))
     1049        {
     1050            Msg.context.GetUInt32(&pCtx->uContextID);
     1051            Msg.action.GetUInt32(pfAction);
     1052        }
     1053    } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
     1054    return rc;
     1055}
     1056
     1057/**
    10291058 * Initializes a process startup info, extended version.
    10301059 *
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControl.cpp

    r84243 r84548  
    247247        const uint64_t fGuestFeatures = VBOX_GUESTCTRL_GF_0_SET_SIZE
    248248                                      | VBOX_GUESTCTRL_GF_0_PROCESS_ARGV0
    249                                       | VBOX_GUESTCTRL_GF_0_PROCESS_DYNAMIC_SIZES;
     249                                      | VBOX_GUESTCTRL_GF_0_PROCESS_DYNAMIC_SIZES
     250                                      | VBOX_GUESTCTRL_GF_0_SHUTDOWN;
    250251
    251252        rc = VbglR3GuestCtrlReportFeatures(g_idControlSvcClient, fGuestFeatures, &g_fControlHostFeatures0);
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControlSession.cpp

    r84215 r84548  
    3434#include <iprt/process.h>
    3535#include <iprt/rand.h>
     36#include <iprt/system.h> /* For RTShutdown. */
    3637
    3738#include "VBoxServiceInternal.h"
     
    990991
    991992/**
     993 * Handles shutting down / rebooting the guest OS.
     994 *
     995 * @returns VBox status code.
     996 * @param   pSession        Guest session.
     997 * @param   pHostCtx        Host context.
     998 */
     999static int vgsvcGstCtrlSessionHandleShutdown(PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLCMDCTX pHostCtx)
     1000{
     1001    AssertPtrReturn(pSession, VERR_INVALID_POINTER);
     1002    AssertPtrReturn(pHostCtx, VERR_INVALID_POINTER);
     1003
     1004    /*
     1005     * Retrieve the request.
     1006     */
     1007    uint32_t fAction;
     1008    int rc = VbglR3GuestCtrlGetShutdown(pHostCtx, &fAction);
     1009    if (RT_SUCCESS(rc))
     1010    {
     1011        VGSvcVerbose(1, "Host requested to %s system ...\n", (fAction & RTSYSTEM_SHUTDOWN_REBOOT) ? "reboot" : "shutdown");
     1012
     1013        /* Reply first to the host, in order to avoid host hangs when issuing the guest shutdown. */
     1014        rc = VbglR3GuestCtrlMsgReply(pHostCtx, VINF_SUCCESS);
     1015        if (RT_FAILURE(rc))
     1016        {
     1017            VGSvcError("Failed to reply to shutdown / reboot request, rc=%Rrc\n", rc);
     1018        }
     1019        else
     1020        {
     1021            rc = RTSystemShutdown(0 /*cMsDelay*/,
     1022                                  fAction | RTSYSTEM_SHUTDOWN_PLANNED,
     1023                                  "VBoxService");
     1024            if (RT_FAILURE(rc))
     1025                VGSvcError("%s system failed with %Rrc\n", (fAction & RTSYSTEM_SHUTDOWN_REBOOT) ? "Rebooting" : "Shuting down");
     1026        }
     1027    }
     1028    else
     1029    {
     1030        VGSvcError("Error fetching parameters for shutdown / reboot request: %Rrc\n", rc);
     1031        VbglR3GuestCtrlMsgSkip(pHostCtx->uClientID, rc, UINT32_MAX);
     1032    }
     1033
     1034    return rc;
     1035}
     1036
     1037
     1038/**
    9921039 * Handles getting the user's home directory.
    9931040 *
     
    14121459            if (fImpersonated)
    14131460                rc = vgsvcGstCtrlSessionHandlePathUserHome(pSession, pHostCtx);
     1461            break;
     1462
     1463        case HOST_MSG_SHUTDOWN:
     1464            rc = vgsvcGstCtrlSessionHandleShutdown(pSession, pHostCtx);
    14141465            break;
    14151466
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