VirtualBox

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

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

Location:
trunk/src/VBox/Additions/common/VBoxService
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • 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