VBoxHeadless.cpp revision bbb95a0ab03c6fcb2ccdcfe8e89b04ca13bea7ab
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync/* $Id$ */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync/** @file
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * VBoxHeadless - The VirtualBox Headless frontend for running VMs on servers.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync/*
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync * Copyright (C) 2006-2012 Oracle Corporation
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync *
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * available from http://www.virtualbox.org. This file is free software;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * you can redistribute it and/or modify it under the terms of the GNU
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * General Public License (GPL) as published by the Free Software
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include <VBox/com/com.h>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include <VBox/com/string.h>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include <VBox/com/array.h>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include <VBox/com/Guid.h>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include <VBox/com/ErrorInfo.h>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include <VBox/com/errorprint.h>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include <VBox/com/EventQueue.h>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include <VBox/com/VirtualBox.h>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include <VBox/com/listeners.h>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncusing namespace com;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#define LOG_GROUP LOG_GROUP_GUI
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include <VBox/log.h>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include <VBox/version.h>
628ddfbd43ad5365d69fddda4007598242956577vboxsync#include <iprt/buildconfig.h>
628ddfbd43ad5365d69fddda4007598242956577vboxsync#include <iprt/ctype.h>
628ddfbd43ad5365d69fddda4007598242956577vboxsync#include <iprt/initterm.h>
628ddfbd43ad5365d69fddda4007598242956577vboxsync#include <iprt/stream.h>
628ddfbd43ad5365d69fddda4007598242956577vboxsync#include <iprt/ldr.h>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include <iprt/getopt.h>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include <iprt/env.h>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include <VBox/err.h>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include <VBox/VBoxVideo.h>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#ifdef VBOX_WITH_VIDEO_REC
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include <cstdlib>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include <cerrno>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include "VBoxHeadless.h"
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync#include <iprt/env.h>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include <iprt/param.h>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include <iprt/process.h>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include <VBox/sup.h>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#endif
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync//#define VBOX_WITH_SAVESTATE_ON_SIGNAL
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#ifdef VBOX_WITH_SAVESTATE_ON_SIGNAL
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include <signal.h>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#endif
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include "Framebuffer.h"
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include "NullFramebuffer.h"
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync////////////////////////////////////////////////////////////////////////////////
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#define LogError(m,rc) \
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync do { \
2f0d866e126dd288169fed591c259c1c6b4016e5vboxsync Log(("VBoxHeadless: ERROR: " m " [rc=0x%08X]\n", rc)); \
ae5379e3e7573369566d4628ef6c597da693cc55vboxsync RTPrintf("%s\n", m); \
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync } while (0)
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync
ae5379e3e7573369566d4628ef6c597da693cc55vboxsync////////////////////////////////////////////////////////////////////////////////
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync/* global weak references (for event handlers) */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncstatic IConsole *gConsole = NULL;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncstatic EventQueue *gEventQ = NULL;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync/* flag whether frontend should terminate */
37e7010b28a4667800196960b59cd63b5434b7d7vboxsyncstatic volatile bool g_fTerminateFE = false;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync////////////////////////////////////////////////////////////////////////////////
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync/**
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Handler for VirtualBoxClient events.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncclass VirtualBoxClientEventListener
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync{
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncpublic:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync VirtualBoxClientEventListener()
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
54d3b0107d9bf326fe6e0de92e012c791dbb1587vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync virtual ~VirtualBoxClientEventListener()
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync HRESULT init()
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return S_OK;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync void uninit()
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STDMETHOD(HandleEvent)(VBoxEventType_T aType, IEvent *aEvent)
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync {
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync switch (aType)
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync {
77cce7691847be5aef145f31ba3f9d66fc2cf594vboxsync case VBoxEventType_OnVBoxSVCAvailabilityChanged:
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync {
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync ComPtr<IVBoxSVCAvailabilityChangedEvent> pVSACEv = aEvent;
54d3b0107d9bf326fe6e0de92e012c791dbb1587vboxsync Assert(pVSACEv);
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync BOOL fAvailable = FALSE;
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync pVSACEv->COMGETTER(Available)(&fAvailable);
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync if (!fAvailable)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync LogRel(("VBoxHeadless: VBoxSVC became unavailable, exiting.\n"));
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync RTPrintf("VBoxSVC became unavailable, exiting.\n");
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync /* Terminate the VM as cleanly as possible given that VBoxSVC
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * is no longer present. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync g_fTerminateFE = true;
9e293277b378073ce86910209a246b744b4caa2cvboxsync gEventQ->interruptEventQueueProcessing();
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync }
9e293277b378073ce86910209a246b744b4caa2cvboxsync break;
9e293277b378073ce86910209a246b744b4caa2cvboxsync }
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync default:
9e293277b378073ce86910209a246b744b4caa2cvboxsync AssertFailed();
9e293277b378073ce86910209a246b744b4caa2cvboxsync }
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync
bdd15592ca3578b623ff588055a561f58b7e5586vboxsync return S_OK;
bdd15592ca3578b623ff588055a561f58b7e5586vboxsync }
bdd15592ca3578b623ff588055a561f58b7e5586vboxsync
9e293277b378073ce86910209a246b744b4caa2cvboxsyncprivate:
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync};
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync/**
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync * Handler for global events.
f350b7cf96f1e2f3b0cfd34cfe8726c754f43584vboxsync */
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsyncclass VirtualBoxEventListener
f350b7cf96f1e2f3b0cfd34cfe8726c754f43584vboxsync{
f350b7cf96f1e2f3b0cfd34cfe8726c754f43584vboxsyncpublic:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync VirtualBoxEventListener()
f350b7cf96f1e2f3b0cfd34cfe8726c754f43584vboxsync {
f350b7cf96f1e2f3b0cfd34cfe8726c754f43584vboxsync mfNoLoggedInUsers = true;
f350b7cf96f1e2f3b0cfd34cfe8726c754f43584vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync virtual ~VirtualBoxEventListener()
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync HRESULT init()
f350b7cf96f1e2f3b0cfd34cfe8726c754f43584vboxsync {
551d9b8ee3568ad3e11b65ce6ef2867c36375f37vboxsync return S_OK;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync void uninit()
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync STDMETHOD(HandleEvent)(VBoxEventType_T aType, IEvent *aEvent)
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync switch (aType)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
8e0c2ca3abd721979958f95b9af73b60665478c8vboxsync case VBoxEventType_OnGuestPropertyChanged:
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync {
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync ComPtr<IGuestPropertyChangedEvent> gpcev = aEvent;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync Assert(gpcev);
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync Bstr aKey;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync gpcev->COMGETTER(Name)(aKey.asOutParam());
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (aKey == Bstr("/VirtualBox/GuestInfo/OS/NoLoggedInUsers"))
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync {
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync /* Check if this is our machine and the "disconnect on logout feature" is enabled. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync BOOL fProcessDisconnectOnGuestLogout = FALSE;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync ComPtr <IMachine> machine;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync HRESULT hrc = S_OK;
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync if (gConsole)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync hrc = gConsole->COMGETTER(Machine)(machine.asOutParam());
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (SUCCEEDED(hrc) && machine)
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync Bstr id, machineId;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync hrc = machine->COMGETTER(Id)(id.asOutParam());
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync gpcev->COMGETTER(MachineId)(machineId.asOutParam());
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync if (id == machineId)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
39592d8ff3243f6116c4e99be391bcf30a4ad187vboxsync Bstr value1;
39592d8ff3243f6116c4e99be391bcf30a4ad187vboxsync hrc = machine->GetExtraData(Bstr("VRDP/DisconnectOnGuestLogout").raw(),
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync value1.asOutParam());
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync if (SUCCEEDED(hrc) && value1 == "1")
39592d8ff3243f6116c4e99be391bcf30a4ad187vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync fProcessDisconnectOnGuestLogout = TRUE;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (fProcessDisconnectOnGuestLogout)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync bool fDropConnection = false;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync Bstr value;
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync gpcev->COMGETTER(Value)(value.asOutParam());
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync Utf8Str utf8Value = value;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (!mfNoLoggedInUsers) /* Only if the property really changes. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if ( utf8Value == "true"
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /* Guest property got deleted due to reset,
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * so it has no value anymore. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync || utf8Value.isEmpty())
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync mfNoLoggedInUsers = true;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync fDropConnection = true;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync else if (utf8Value == "false")
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync mfNoLoggedInUsers = false;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /* Guest property got deleted due to reset,
c77e7bff89c7639353778366984d51ff165ea0e3vboxsync * take the shortcut without touching the mfNoLoggedInUsers
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * state. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync else if (utf8Value.isEmpty())
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync fDropConnection = true;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (fDropConnection)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /* If there is a connection, drop it. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync ComPtr<IVRDEServerInfo> info;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync hrc = gConsole->COMGETTER(VRDEServerInfo)(info.asOutParam());
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (SUCCEEDED(hrc) && info)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync ULONG cClients = 0;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync hrc = info->COMGETTER(NumberOfClients)(&cClients);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (SUCCEEDED(hrc) && cClients > 0)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync ComPtr <IVRDEServer> vrdeServer;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync hrc = machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (SUCCEEDED(hrc) && vrdeServer)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync LogRel(("VRDE: the guest user has logged out, disconnecting remote clients.\n"));
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync vrdeServer->COMSETTER(Enabled)(FALSE);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync vrdeServer->COMSETTER(Enabled)(TRUE);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync default:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync AssertFailed();
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return S_OK;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncprivate:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync bool mfNoLoggedInUsers;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync};
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync/**
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Handler for machine events.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncclass ConsoleEventListener
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync{
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncpublic:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync ConsoleEventListener() :
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync mLastVRDEPort(-1),
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync m_fIgnorePowerOffEvents(false)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync virtual ~ConsoleEventListener()
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync HRESULT init()
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return S_OK;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync void uninit()
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STDMETHOD(HandleEvent)(VBoxEventType_T aType, IEvent *aEvent)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync switch (aType)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VBoxEventType_OnMouseCapabilityChanged:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync ComPtr<IMouseCapabilityChangedEvent> mccev = aEvent;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync Assert(mccev);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync BOOL fSupportsAbsolute = false;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync mccev->COMGETTER(SupportsAbsolute)(&fSupportsAbsolute);
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /* Emit absolute mouse event to actually enable the host mouse cursor. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (fSupportsAbsolute && gConsole)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync ComPtr<IMouse> mouse;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync gConsole->COMGETTER(Mouse)(mouse.asOutParam());
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (mouse)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync mouse->PutMouseEventAbsolute(-1, -1, 0, 0 /* Horizontal wheel */, 0);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VBoxEventType_OnStateChanged:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync ComPtr<IStateChangedEvent> scev = aEvent;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync Assert(scev);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync MachineState_T machineState;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync scev->COMGETTER(State)(&machineState);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /* Terminate any event wait operation if the machine has been
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * PoweredDown/Saved/Aborted. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (machineState < MachineState_Running && !m_fIgnorePowerOffEvents)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync g_fTerminateFE = true;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync gEventQ->interruptEventQueueProcessing();
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VBoxEventType_OnVRDEServerInfoChanged:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync ComPtr<IVRDEServerInfoChangedEvent> rdicev = aEvent;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync Assert(rdicev);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (gConsole)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync ComPtr<IVRDEServerInfo> info;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync gConsole->COMGETTER(VRDEServerInfo)(info.asOutParam());
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (info)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync LONG port;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync info->COMGETTER(Port)(&port);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (port != mLastVRDEPort)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (port == -1)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync RTPrintf("VRDE server is inactive.\n");
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync else if (port == 0)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync RTPrintf("VRDE server failed to start.\n");
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync else
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync RTPrintf("VRDE server is listening on port %d.\n", port);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync mLastVRDEPort = port;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VBoxEventType_OnCanShowWindow:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync ComPtr<ICanShowWindowEvent> cswev = aEvent;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync Assert(cswev);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync cswev->AddVeto(NULL);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VBoxEventType_OnShowWindow:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync ComPtr<IShowWindowEvent> swev = aEvent;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync Assert(swev);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync swev->COMSETTER(WinId)(0);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync default:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync AssertFailed();
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return S_OK;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync void ignorePowerOffEvents(bool fIgnore)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync m_fIgnorePowerOffEvents = fIgnore;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncprivate:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync long mLastVRDEPort;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync bool m_fIgnorePowerOffEvents;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync};
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsynctypedef ListenerImpl<VirtualBoxClientEventListener> VirtualBoxClientEventListenerImpl;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsynctypedef ListenerImpl<VirtualBoxEventListener> VirtualBoxEventListenerImpl;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsynctypedef ListenerImpl<ConsoleEventListener> ConsoleEventListenerImpl;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncVBOX_LISTENER_DECLARE(VirtualBoxClientEventListenerImpl)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncVBOX_LISTENER_DECLARE(VirtualBoxEventListenerImpl)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncVBOX_LISTENER_DECLARE(ConsoleEventListenerImpl)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#ifdef VBOX_WITH_SAVESTATE_ON_SIGNAL
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncstatic void SaveState(int sig)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync{
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync ComPtr <IProgress> progress = NULL;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync/** @todo Deal with nested signals, multithreaded signal dispatching (esp. on windows),
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * and multiple signals (both SIGINT and SIGTERM in some order).
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Consider processing the signal request asynchronously since there are lots of things
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * which aren't safe (like RTPrintf and printf IIRC) in a signal context. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync RTPrintf("Signal received, saving state.\n");
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync HRESULT rc = gConsole->SaveState(progress.asOutParam());
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (FAILED(rc))
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync RTPrintf("Error saving state! rc = 0x%x\n", rc);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync Assert(progress);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync LONG cPercent = 0;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync RTPrintf("0%%");
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync RTStrmFlush(g_pStdOut);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync for (;;)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync BOOL fCompleted = false;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync rc = progress->COMGETTER(Completed)(&fCompleted);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (FAILED(rc) || fCompleted)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync ULONG cPercentNow;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync rc = progress->COMGETTER(Percent)(&cPercentNow);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (FAILED(rc))
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if ((cPercentNow / 10) != (cPercent / 10))
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync cPercent = cPercentNow;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync RTPrintf("...%d%%", cPercentNow);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync RTStrmFlush(g_pStdOut);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /* wait */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync rc = progress->WaitForCompletion(100);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync HRESULT lrc;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync rc = progress->COMGETTER(ResultCode)(&lrc);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (FAILED(rc))
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync lrc = ~0;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (!lrc)
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync RTPrintf(" -- Saved the state successfully.\n");
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync RTThreadYield();
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
bac59dd15f093cbb8dae97ebd8f94f94786d1439vboxsync else
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync RTPrintf("-- Error saving state, lrc=%d (%#x)\n", lrc, lrc);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync}
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#endif /* VBOX_WITH_SAVESTATE_ON_SIGNAL */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync////////////////////////////////////////////////////////////////////////////////
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncstatic void show_usage()
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync{
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync RTPrintf("Usage:\n"
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync " -s, -startvm, --startvm <name|uuid> Start given VM (required argument)\n"
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync " -v, -vrde, --vrde on|off|config Enable (default) or disable the VRDE\n"
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync " server or don't change the setting\n"
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync " -e, -vrdeproperty, --vrdeproperty <name=[value]> Set a VRDE property:\n"
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync " \"TCP/Ports\" - comma-separated list of ports\n"
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync " the VRDE server can bind to. Use a dash between\n"
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync " two port numbers to specify a range\n"
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync " \"TCP/Address\" - interface IP the VRDE server\n"
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync " will bind to\n"
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#ifdef VBOX_WITH_VIDEO_REC
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync " -c, -capture, --capture Record the VM screen output to a file\n"
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync " -w, --width Frame width when recording\n"
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync " -h, --height Frame height when recording\n"
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync " -r, --bitrate Recording bit rate when recording\n"
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync " -f, --filename File name when recording. The codec\n"
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync " used will be chosen based on the\n"
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync " file extension\n"
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#endif
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync "\n");
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync}
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#ifdef VBOX_WITH_VIDEO_REC
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync/**
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Parse the environment for variables which can influence the FFMPEG settings.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * purely for backwards compatibility.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @param pulFrameWidth may be updated with a desired frame width
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @param pulFrameHeight may be updated with a desired frame height
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @param pulBitRate may be updated with a desired bit rate
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @param ppszFileName may be updated with a desired file name
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncstatic void parse_environ(unsigned long *pulFrameWidth, unsigned long *pulFrameHeight,
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync unsigned long *pulBitRate, const char **ppszFileName)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync{
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync const char *pszEnvTemp;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if ((pszEnvTemp = RTEnvGet("VBOX_CAPTUREWIDTH")) != 0)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync errno = 0;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync unsigned long ulFrameWidth = strtoul(pszEnvTemp, 0, 10);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (errno != 0)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync LogError("VBoxHeadless: ERROR: invalid VBOX_CAPTUREWIDTH environment variable", 0);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync else
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync *pulFrameWidth = ulFrameWidth;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if ((pszEnvTemp = RTEnvGet("VBOX_CAPTUREHEIGHT")) != 0)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync errno = 0;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync unsigned long ulFrameHeight = strtoul(pszEnvTemp, 0, 10);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (errno != 0)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync LogError("VBoxHeadless: ERROR: invalid VBOX_CAPTUREHEIGHT environment variable", 0);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync else
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync *pulFrameHeight = ulFrameHeight;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if ((pszEnvTemp = RTEnvGet("VBOX_CAPTUREBITRATE")) != 0)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync errno = 0;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync unsigned long ulBitRate = strtoul(pszEnvTemp, 0, 10);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (errno != 0)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync LogError("VBoxHeadless: ERROR: invalid VBOX_CAPTUREBITRATE environment variable", 0);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync else
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync *pulBitRate = ulBitRate;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if ((pszEnvTemp = RTEnvGet("VBOX_CAPTUREFILE")) != 0)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync *ppszFileName = pszEnvTemp;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync}
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#endif /* VBOX_WITH_VIDEO_REC defined */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#ifdef RT_OS_WINDOWS
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync// Required for ATL
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncstatic CComModule _Module;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#endif
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync/**
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Entry point.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncextern "C" DECLEXPORT(int) TrustedMain(int argc, char **argv, char **envp)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync{
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync const char *vrdePort = NULL;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync const char *vrdeAddress = NULL;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync const char *vrdeEnabled = NULL;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync unsigned cVRDEProperties = 0;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync const char *aVRDEProperties[16];
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync unsigned fRawR0 = ~0U;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync unsigned fRawR3 = ~0U;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync unsigned fPATM = ~0U;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync unsigned fCSAM = ~0U;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#ifdef VBOX_WITH_VIDEO_REC
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync unsigned fFFMPEG = 0;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync unsigned long ulFrameWidth = 800;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync unsigned long ulFrameHeight = 600;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync unsigned long ulBitRate = 300000;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync char pszMPEGFile[RTPATH_MAX];
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync const char *pszFileNameParam = "VBox-%d.vob";
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#endif /* VBOX_WITH_VIDEO_REC */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync LogFlow (("VBoxHeadless STARTED.\n"));
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync RTPrintf (VBOX_PRODUCT " Headless Interface " VBOX_VERSION_STRING "\n"
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync "(C) 2008-" VBOX_C_YEAR " " VBOX_VENDOR "\n"
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync "All rights reserved.\n\n");
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#ifdef VBOX_WITH_VIDEO_REC
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /* Parse the environment */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync parse_environ(&ulFrameWidth, &ulFrameHeight, &ulBitRate, &pszFileNameParam);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#endif
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync enum eHeadlessOptions
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync OPT_RAW_R0 = 0x100,
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync OPT_NO_RAW_R0,
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync OPT_RAW_R3,
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync OPT_NO_RAW_R3,
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync OPT_PATM,
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync OPT_NO_PATM,
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync OPT_CSAM,
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync OPT_NO_CSAM,
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync OPT_COMMENT
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync };
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync static const RTGETOPTDEF s_aOptions[] =
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync { "-startvm", 's', RTGETOPT_REQ_STRING },
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync { "--startvm", 's', RTGETOPT_REQ_STRING },
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync { "-vrdpport", 'p', RTGETOPT_REQ_STRING }, /* VRDE: deprecated. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync { "--vrdpport", 'p', RTGETOPT_REQ_STRING }, /* VRDE: deprecated. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync { "-vrdpaddress", 'a', RTGETOPT_REQ_STRING }, /* VRDE: deprecated. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync { "--vrdpaddress", 'a', RTGETOPT_REQ_STRING }, /* VRDE: deprecated. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync { "-vrdp", 'v', RTGETOPT_REQ_STRING }, /* VRDE: deprecated. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync { "--vrdp", 'v', RTGETOPT_REQ_STRING }, /* VRDE: deprecated. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync { "-vrde", 'v', RTGETOPT_REQ_STRING },
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync { "--vrde", 'v', RTGETOPT_REQ_STRING },
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync { "-vrdeproperty", 'e', RTGETOPT_REQ_STRING },
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync { "--vrdeproperty", 'e', RTGETOPT_REQ_STRING },
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync { "-rawr0", OPT_RAW_R0, 0 },
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync { "--rawr0", OPT_RAW_R0, 0 },
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync { "-norawr0", OPT_NO_RAW_R0, 0 },
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync { "--norawr0", OPT_NO_RAW_R0, 0 },
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync { "-rawr3", OPT_RAW_R3, 0 },
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync { "--rawr3", OPT_RAW_R3, 0 },
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync { "-norawr3", OPT_NO_RAW_R3, 0 },
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync { "--norawr3", OPT_NO_RAW_R3, 0 },
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync { "-patm", OPT_PATM, 0 },
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync { "--patm", OPT_PATM, 0 },
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync { "-nopatm", OPT_NO_PATM, 0 },
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync { "--nopatm", OPT_NO_PATM, 0 },
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync { "-csam", OPT_CSAM, 0 },
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync { "--csam", OPT_CSAM, 0 },
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync { "-nocsam", OPT_NO_CSAM, 0 },
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync { "--nocsam", OPT_NO_CSAM, 0 },
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#ifdef VBOX_WITH_VIDEO_REC
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync { "-capture", 'c', 0 },
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync { "--capture", 'c', 0 },
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync { "--width", 'w', RTGETOPT_REQ_UINT32 },
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync { "--height", 'h', RTGETOPT_REQ_UINT32 }, /* great choice of short option! */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync { "--bitrate", 'r', RTGETOPT_REQ_UINT32 },
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync { "--filename", 'f', RTGETOPT_REQ_STRING },
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#endif /* VBOX_WITH_VIDEO_REC defined */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync { "-comment", OPT_COMMENT, RTGETOPT_REQ_STRING },
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync { "--comment", OPT_COMMENT, RTGETOPT_REQ_STRING }
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync };
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync const char *pcszNameOrUUID = NULL;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync // parse the command line
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync int ch;
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync RTGETOPTUNION ValueUnion;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync RTGETOPTSTATE GetState;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1, 0 /* fFlags */);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync while ((ch = RTGetOpt(&GetState, &ValueUnion)))
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync switch(ch)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case 's':
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync pcszNameOrUUID = ValueUnion.psz;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case 'p':
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync RTPrintf("Warning: '-p' or '-vrdpport' are deprecated. Use '-e \"TCP/Ports=%s\"'\n", ValueUnion.psz);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync vrdePort = ValueUnion.psz;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case 'a':
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync RTPrintf("Warning: '-a' or '-vrdpaddress' are deprecated. Use '-e \"TCP/Address=%s\"'\n", ValueUnion.psz);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync vrdeAddress = ValueUnion.psz;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case 'v':
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync vrdeEnabled = ValueUnion.psz;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case 'e':
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (cVRDEProperties < RT_ELEMENTS(aVRDEProperties))
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync aVRDEProperties[cVRDEProperties++] = ValueUnion.psz;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync else
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync RTPrintf("Warning: too many VRDE properties. Ignored: '%s'\n", ValueUnion.psz);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case OPT_RAW_R0:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync fRawR0 = true;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case OPT_NO_RAW_R0:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync fRawR0 = false;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case OPT_RAW_R3:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync fRawR3 = true;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case OPT_NO_RAW_R3:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync fRawR3 = false;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case OPT_PATM:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync fPATM = true;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case OPT_NO_PATM:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync fPATM = false;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case OPT_CSAM:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync fCSAM = true;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case OPT_NO_CSAM:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync fCSAM = false;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#ifdef VBOX_WITH_VIDEO_REC
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case 'c':
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync fFFMPEG = true;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case 'w':
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync ulFrameWidth = ValueUnion.u32;
c77e7bff89c7639353778366984d51ff165ea0e3vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case 'r':
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync ulBitRate = ValueUnion.u32;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case 'f':
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync pszFileNameParam = ValueUnion.psz;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#endif /* VBOX_WITH_VIDEO_REC defined */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case 'h':
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#ifdef VBOX_WITH_VIDEO_REC
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if ((GetState.pDef->fFlags & RTGETOPT_REQ_MASK) != RTGETOPT_REQ_NOTHING)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync ulFrameHeight = ValueUnion.u32;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#endif
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync show_usage();
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return 0;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case OPT_COMMENT:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /* nothing to do */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case 'V':
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync RTPrintf("%sr%s\n", RTBldCfgVersion(), RTBldCfgRevisionStr());
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return 0;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync default:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync ch = RTGetOptPrintError(ch, &ValueUnion);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync show_usage();
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return ch;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#ifdef VBOX_WITH_VIDEO_REC
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (ulFrameWidth < 512 || ulFrameWidth > 2048 || ulFrameWidth % 2)
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync {
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync LogError("VBoxHeadless: ERROR: please specify an even frame width between 512 and 2048", 0);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return 1;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (ulFrameHeight < 384 || ulFrameHeight > 1536 || ulFrameHeight % 2)
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync LogError("VBoxHeadless: ERROR: please specify an even frame height between 384 and 1536", 0);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return 1;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (ulBitRate < 300000 || ulBitRate > 1000000)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync LogError("VBoxHeadless: ERROR: please specify an even bitrate between 300000 and 1000000", 0);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return 1;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /* Make sure we only have %d or %u (or none) in the file name specified */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync char *pcPercent = (char*)strchr(pszFileNameParam, '%');
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (pcPercent != 0 && *(pcPercent + 1) != 'd' && *(pcPercent + 1) != 'u')
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync LogError("VBoxHeadless: ERROR: Only %%d and %%u are allowed in the capture file name.", -1);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return 1;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /* And no more than one % in the name */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (pcPercent != 0 && strchr(pcPercent + 1, '%') != 0)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync LogError("VBoxHeadless: ERROR: Only one format modifier is allowed in the capture file name.", -1);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return 1;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync RTStrPrintf(&pszMPEGFile[0], RTPATH_MAX, pszFileNameParam, RTProcSelf());
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#endif /* defined VBOX_WITH_VIDEO_REC */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (!pcszNameOrUUID)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync show_usage();
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return 1;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync HRESULT rc;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync rc = com::Initialize();
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync#ifdef VBOX_WITH_XPCOM
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (rc == NS_ERROR_FILE_ACCESS_DENIED)
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync char szHome[RTPATH_MAX] = "";
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync com::GetVBoxUserHomeDirectory(szHome, sizeof(szHome));
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync RTPrintf("Failed to initialize COM because the global settings directory '%s' is not accessible!", szHome);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync return 1;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync#endif
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (FAILED(rc))
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync RTPrintf("VBoxHeadless: ERROR: failed to initialize COM!\n");
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync return 1;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync ComPtr<IVirtualBoxClient> pVirtualBoxClient;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync ComPtr<IVirtualBox> virtualBox;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync ComPtr<ISession> session;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync ComPtr<IMachine> machine;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync bool fSessionOpened = false;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync ComPtr<IEventListener> vboxClientListener;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync ComPtr<IEventListener> vboxListener;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync ComObjPtr<ConsoleEventListenerImpl> consoleListener;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync do
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync rc = pVirtualBoxClient.createInprocObject(CLSID_VirtualBoxClient);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (FAILED(rc))
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync RTPrintf("VBoxHeadless: ERROR: failed to create the VirtualBoxClient object!\n");
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync com::ErrorInfo info;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (!info.isFullAvailable() && !info.isBasicAvailable())
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync com::GluePrintRCMessage(rc);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync RTPrintf("Most likely, the VirtualBox COM server is not running or failed to start.\n");
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync else
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync GluePrintErrorInfo(info);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync break;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync rc = pVirtualBoxClient->COMGETTER(VirtualBox)(virtualBox.asOutParam());
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (FAILED(rc))
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync RTPrintf("Failed to get VirtualBox object (rc=%Rhrc)!\n", rc);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync break;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync rc = pVirtualBoxClient->COMGETTER(Session)(session.asOutParam());
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (FAILED(rc))
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync RTPrintf("Failed to get session object (rc=%Rhrc)!\n", rc);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync break;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync ComPtr<IMachine> m;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync rc = virtualBox->FindMachine(Bstr(pcszNameOrUUID).raw(), m.asOutParam());
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (FAILED(rc))
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync LogError("Invalid machine name or UUID!\n", rc);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync break;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync Bstr id;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync m->COMGETTER(Id)(id.asOutParam());
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync AssertComRC(rc);
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync if (FAILED(rc))
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync break;
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync Log(("VBoxHeadless: Opening a session with machine (id={%s})...\n",
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync Utf8Str(id).c_str()));
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync // open a session
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync CHECK_ERROR_BREAK(m, LockMachine(session, LockType_Write));
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync fSessionOpened = true;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync /* get the console */
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync ComPtr<IConsole> console;
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync CHECK_ERROR_BREAK(session, COMGETTER(Console)(console.asOutParam()));
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync /* get the mutable machine */
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync CHECK_ERROR_BREAK(console, COMGETTER(Machine)(machine.asOutParam()));
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync ComPtr<IDisplay> display;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync CHECK_ERROR_BREAK(console, COMGETTER(Display)(display.asOutParam()));
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync#ifdef VBOX_WITH_VIDEO_REC
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync IFramebuffer *pFramebuffer = 0;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync RTLDRMOD hLdrFFmpegFB;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync PFNREGISTERFFMPEGFB pfnRegisterFFmpegFB;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (fFFMPEG)
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync HRESULT rcc = S_OK;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync int rrc = VINF_SUCCESS;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync RTERRINFOSTATIC ErrInfo;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync Log2(("VBoxHeadless: loading VBoxFFmpegFB and libvpx shared library\n"));
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync RTErrInfoInitStatic(&ErrInfo);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync rrc = SUPR3HardenedLdrLoadAppPriv("VBoxFFmpegFB", &hLdrFFmpegFB, RTLDRLOAD_FLAGS_LOCAL, &ErrInfo.Core);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (RT_SUCCESS(rrc))
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync Log2(("VBoxHeadless: looking up symbol VBoxRegisterFFmpegFB\n"));
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync rrc = RTLdrGetSymbol(hLdrFFmpegFB, "VBoxRegisterFFmpegFB",
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync reinterpret_cast<void **>(&pfnRegisterFFmpegFB));
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (RT_FAILURE(rrc))
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync LogError("Failed to load the video capture extension, possibly due to a damaged file\n", rrc);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync else
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync LogError("Failed to load the video capture extension\n", rrc); /** @todo stupid function, no formatting options. */
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync if (RT_SUCCESS(rrc))
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync Log2(("VBoxHeadless: calling pfnRegisterFFmpegFB\n"));
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync rcc = pfnRegisterFFmpegFB(ulFrameWidth, ulFrameHeight, ulBitRate,
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync pszMPEGFile, &pFramebuffer);
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync if (rcc != S_OK)
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync LogError("Failed to initialise video capturing - make sure that the file format\n"
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync "you wish to use is supported on your system\n", rcc);
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (RT_SUCCESS(rrc) && rcc == S_OK)
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync Log2(("VBoxHeadless: Registering framebuffer\n"));
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync pFramebuffer->AddRef();
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync display->SetFramebuffer(VBOX_VIDEO_PRIMARY_SCREEN, pFramebuffer);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (!RT_SUCCESS(rrc) || rcc != S_OK)
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync rc = E_FAIL;
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (rc != S_OK)
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync {
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync break;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync#endif /* defined(VBOX_WITH_VIDEO_REC) */
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync ULONG cMonitors = 1;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync machine->COMGETTER(MonitorCount)(&cMonitors);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync unsigned uScreenId;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync for (uScreenId = 0; uScreenId < cMonitors; uScreenId++)
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync# ifdef VBOX_WITH_VIDEO_REC
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (fFFMPEG && uScreenId == 0)
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync /* Already registered. */
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync continue;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync# endif
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync VRDPFramebuffer *pVRDPFramebuffer = new VRDPFramebuffer();
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync if (!pVRDPFramebuffer)
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync RTPrintf("Error: could not create framebuffer object %d\n", uScreenId);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync break;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync pVRDPFramebuffer->AddRef();
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync display->SetFramebuffer(uScreenId, pVRDPFramebuffer);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (uScreenId < cMonitors)
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync break;
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync }
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync // fill in remaining slots with null framebuffers
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync for (uScreenId = 0; uScreenId < cMonitors; uScreenId++)
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync ComPtr<IFramebuffer> fb;
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync LONG xOrigin, yOrigin;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync HRESULT hrc2 = display->GetFramebuffer(uScreenId,
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync fb.asOutParam(),
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync &xOrigin, &yOrigin);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (hrc2 == S_OK && fb.isNull())
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync NullFB *pNullFB = new NullFB();
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync pNullFB->AddRef();
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync pNullFB->init();
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync display->SetFramebuffer(uScreenId, pNullFB);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync /* get the machine debugger (isn't necessarily available) */
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync ComPtr <IMachineDebugger> machineDebugger;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync console->COMGETTER(Debugger)(machineDebugger.asOutParam());
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (machineDebugger)
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync Log(("Machine debugger available!\n"));
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync if (fRawR0 != ~0U)
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (!machineDebugger)
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync RTPrintf("Error: No debugger object; -%srawr0 cannot be executed!\n", fRawR0 ? "" : "no");
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync break;
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync }
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync machineDebugger->COMSETTER(RecompileSupervisor)(!fRawR0);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (fRawR3 != ~0U)
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (!machineDebugger)
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync {
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync RTPrintf("Error: No debugger object; -%srawr3 cannot be executed!\n", fRawR3 ? "" : "no");
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync break;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync machineDebugger->COMSETTER(RecompileUser)(!fRawR3);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (fPATM != ~0U)
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (!machineDebugger)
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync RTPrintf("Error: No debugger object; -%spatm cannot be executed!\n", fPATM ? "" : "no");
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync break;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync machineDebugger->COMSETTER(PATMEnabled)(fPATM);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (fCSAM != ~0U)
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (!machineDebugger)
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync RTPrintf("Error: No debugger object; -%scsam cannot be executed!\n", fCSAM ? "" : "no");
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync break;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync machineDebugger->COMSETTER(CSAMEnabled)(fCSAM);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync /* initialize global references */
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync gConsole = console;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync gEventQ = com::EventQueue::getMainEventQueue();
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync /* VirtualBoxClient events registration. */
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync ComPtr<IEventSource> pES;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync CHECK_ERROR(pVirtualBoxClient, COMGETTER(EventSource)(pES.asOutParam()));
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync ComObjPtr<VirtualBoxClientEventListenerImpl> listener;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync listener.createObject();
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync listener->init(new VirtualBoxClientEventListener());
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync vboxClientListener = listener;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync com::SafeArray<VBoxEventType_T> eventTypes;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync eventTypes.push_back(VBoxEventType_OnVBoxSVCAvailabilityChanged);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync CHECK_ERROR(pES, RegisterListener(vboxClientListener, ComSafeArrayAsInParam(eventTypes), true));
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync /* Console events registration. */
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync ComPtr<IEventSource> es;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync CHECK_ERROR(console, COMGETTER(EventSource)(es.asOutParam()));
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync consoleListener.createObject();
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync consoleListener->init(new ConsoleEventListener());
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync com::SafeArray<VBoxEventType_T> eventTypes;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync eventTypes.push_back(VBoxEventType_OnMouseCapabilityChanged);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync eventTypes.push_back(VBoxEventType_OnStateChanged);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync eventTypes.push_back(VBoxEventType_OnVRDEServerInfoChanged);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync eventTypes.push_back(VBoxEventType_OnCanShowWindow);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync eventTypes.push_back(VBoxEventType_OnShowWindow);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync CHECK_ERROR(es, RegisterListener(consoleListener, ComSafeArrayAsInParam(eventTypes), true));
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync /* default is to enable the remote desktop server (backward compatibility) */
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync BOOL fVRDEEnable = true;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync BOOL fVRDEEnabled;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync ComPtr <IVRDEServer> vrdeServer;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync CHECK_ERROR_BREAK(machine, COMGETTER(VRDEServer)(vrdeServer.asOutParam()));
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync CHECK_ERROR_BREAK(vrdeServer, COMGETTER(Enabled)(&fVRDEEnabled));
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (vrdeEnabled != NULL)
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync /* -vrdeServer on|off|config */
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync if (!strcmp(vrdeEnabled, "off") || !strcmp(vrdeEnabled, "disable"))
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync fVRDEEnable = false;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync else if (!strcmp(vrdeEnabled, "config"))
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (!fVRDEEnabled)
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync fVRDEEnable = false;
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync }
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync else if (strcmp(vrdeEnabled, "on") && strcmp(vrdeEnabled, "enable"))
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync RTPrintf("-vrdeServer requires an argument (on|off|config)\n");
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync break;
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (fVRDEEnable)
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync Log(("VBoxHeadless: Enabling VRDE server...\n"));
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync /* set VRDE port if requested by the user */
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (vrdePort != NULL)
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync Bstr bstr = vrdePort;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync CHECK_ERROR_BREAK(vrdeServer, SetVRDEProperty(Bstr("TCP/Ports").raw(), bstr.raw()));
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync /* set VRDE address if requested by the user */
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (vrdeAddress != NULL)
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync CHECK_ERROR_BREAK(vrdeServer, SetVRDEProperty(Bstr("TCP/Address").raw(), Bstr(vrdeAddress).raw()));
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync /* Set VRDE properties. */
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (cVRDEProperties > 0)
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync for (unsigned i = 0; i < cVRDEProperties; i++)
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync /* Parse 'name=value' */
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync char *pszProperty = RTStrDup(aVRDEProperties[i]);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (pszProperty)
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync char *pDelimiter = strchr(pszProperty, '=');
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (pDelimiter)
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync *pDelimiter = '\0';
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync Bstr bstrName = pszProperty;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync Bstr bstrValue = &pDelimiter[1];
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync CHECK_ERROR_BREAK(vrdeServer, SetVRDEProperty(bstrName.raw(), bstrValue.raw()));
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync else
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync RTPrintf("Error: Invalid VRDE property '%s'\n", aVRDEProperties[i]);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync RTStrFree(pszProperty);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync rc = E_INVALIDARG;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync break;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync RTStrFree(pszProperty);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync else
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync RTPrintf("Error: Failed to allocate memory for VRDE property '%s'\n", aVRDEProperties[i]);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync rc = E_OUTOFMEMORY;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync break;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (FAILED(rc))
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync break;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync /* enable VRDE server (only if currently disabled) */
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (!fVRDEEnabled)
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync CHECK_ERROR_BREAK(vrdeServer, COMSETTER(Enabled)(TRUE));
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync else
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync /* disable VRDE server (only if currently enabled */
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (fVRDEEnabled)
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync CHECK_ERROR_BREAK(vrdeServer, COMSETTER(Enabled)(FALSE));
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync /* Disable the host clipboard before powering up */
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync console->COMSETTER(UseHostClipboard)(false);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync Log(("VBoxHeadless: Powering up the machine...\n"));
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync ComPtr <IProgress> progress;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync CHECK_ERROR_BREAK(console, PowerUp(progress.asOutParam()));
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync /*
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync * Wait for the result because there can be errors.
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync *
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync * It's vital to process events while waiting (teleportation deadlocks),
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync * so we'll poll for the completion instead of waiting on it.
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync */
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync for (;;)
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync BOOL fCompleted;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync rc = progress->COMGETTER(Completed)(&fCompleted);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (FAILED(rc) || fCompleted)
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync break;
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync /* Process pending events, then wait for new ones. Note, this
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync * processes NULL events signalling event loop termination. */
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync gEventQ->processEventQueue(0);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (!g_fTerminateFE)
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync gEventQ->processEventQueue(500);
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync }
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync if (SUCCEEDED(progress->WaitForCompletion(-1)))
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync {
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync /* Figure out if the operation completed with a failed status
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync * and print the error message. Terminate immediately, and let
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync * the cleanup code take care of potentially pending events. */
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync LONG progressRc;
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync progress->COMGETTER(ResultCode)(&progressRc);
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync rc = progressRc;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (FAILED(rc))
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync com::ProgressErrorInfo info(progress);
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync if (info.isBasicAvailable())
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync RTPrintf("Error: failed to start machine. Error message: %ls\n", info.getText().raw());
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync else
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync RTPrintf("Error: failed to start machine. No error message available!\n");
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync break;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync /* VirtualBox events registration. */
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync ComPtr<IEventSource> es;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync CHECK_ERROR(virtualBox, COMGETTER(EventSource)(es.asOutParam()));
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync ComObjPtr<VirtualBoxEventListenerImpl> listener;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync listener.createObject();
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync listener->init(new VirtualBoxEventListener());
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync vboxListener = listener;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync com::SafeArray<VBoxEventType_T> eventTypes;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync eventTypes.push_back(VBoxEventType_OnGuestPropertyChanged);
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync CHECK_ERROR(es, RegisterListener(vboxListener, ComSafeArrayAsInParam(eventTypes), true));
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync#ifdef VBOX_WITH_SAVESTATE_ON_SIGNAL
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync signal(SIGINT, SaveState);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync signal(SIGTERM, SaveState);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync#endif
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync Log(("VBoxHeadless: Waiting for PowerDown...\n"));
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync while ( !g_fTerminateFE
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync && RT_SUCCESS(gEventQ->processEventQueue(RT_INDEFINITE_WAIT)))
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync /* nothing */ ;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync Log(("VBoxHeadless: event loop has terminated...\n"));
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync#ifdef VBOX_WITH_VIDEO_REC
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (pFramebuffer)
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync pFramebuffer->Release();
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync Log(("Released framebuffer\n"));
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync pFramebuffer = NULL;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync#endif /* defined(VBOX_WITH_VIDEO_REC) */
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync /* we don't have to disable VRDE here because we don't save the settings of the VM */
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync while (0);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync /*
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync * Get the machine state.
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync */
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync MachineState_T machineState = MachineState_Aborted;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (!machine.isNull())
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync machine->COMGETTER(State)(&machineState);
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync /*
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync * Turn off the VM if it's running
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync */
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if ( gConsole
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync && ( machineState == MachineState_Running
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync || machineState == MachineState_Teleporting
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync || machineState == MachineState_LiveSnapshotting
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync /** @todo power off paused VMs too? */
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync )
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync )
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync do
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync consoleListener->getWrapped()->ignorePowerOffEvents(true);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync ComPtr<IProgress> pProgress;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync CHECK_ERROR_BREAK(gConsole, PowerDown(pProgress.asOutParam()));
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync CHECK_ERROR_BREAK(pProgress, WaitForCompletion(-1));
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync BOOL completed;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync CHECK_ERROR_BREAK(pProgress, COMGETTER(Completed)(&completed));
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync ASSERT(completed);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync LONG hrc;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync CHECK_ERROR_BREAK(pProgress, COMGETTER(ResultCode)(&hrc));
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (FAILED(hrc))
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync RTPrintf("VBoxHeadless: ERROR: Failed to power down VM!");
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync com::ErrorInfo info;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (!info.isFullAvailable() && !info.isBasicAvailable())
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync com::GluePrintRCMessage(hrc);
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync else
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync GluePrintErrorInfo(info);
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync break;
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync }
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync } while (0);
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync /* VirtualBox callback unregistration. */
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync if (vboxListener)
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync {
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync ComPtr<IEventSource> es;
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync CHECK_ERROR(virtualBox, COMGETTER(EventSource)(es.asOutParam()));
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync if (!es.isNull())
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync CHECK_ERROR(es, UnregisterListener(vboxListener));
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync vboxListener.setNull();
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync /* Console callback unregistration. */
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (consoleListener)
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync ComPtr<IEventSource> es;
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync CHECK_ERROR(gConsole, COMGETTER(EventSource)(es.asOutParam()));
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync if (!es.isNull())
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync CHECK_ERROR(es, UnregisterListener(consoleListener));
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync consoleListener.setNull();
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync /* VirtualBoxClient callback unregistration. */
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync if (vboxClientListener)
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync {
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync ComPtr<IEventSource> pES;
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync CHECK_ERROR(pVirtualBoxClient, COMGETTER(EventSource)(pES.asOutParam()));
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync if (!pES.isNull())
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync CHECK_ERROR(pES, UnregisterListener(vboxClientListener));
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync vboxClientListener.setNull();
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync /* No more access to the 'console' object, which will be uninitialized by the next session->Close call. */
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync gConsole = NULL;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync if (fSessionOpened)
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync {
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync /*
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync * Close the session. This will also uninitialize the console and
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync * unregister the callback we've registered before.
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync */
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync Log(("VBoxHeadless: Closing the session...\n"));
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync session->UnlockMachine();
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync /* Must be before com::Shutdown */
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync session.setNull();
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync virtualBox.setNull();
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync pVirtualBoxClient.setNull();
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync machine.setNull();
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync com::Shutdown();
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync LogFlow(("VBoxHeadless FINISHED.\n"));
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync return FAILED(rc) ? 1 : 0;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync}
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync#ifndef VBOX_WITH_HARDENING
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync/**
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync * Main entry point.
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync */
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsyncint main(int argc, char **argv, char **envp)
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync{
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync // initialize VBox Runtime
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync int rc = RTR3InitExe(argc, &argv, RTR3INIT_FLAGS_SUPLIB);
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync if (RT_FAILURE(rc))
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync RTPrintf("VBoxHeadless: Runtime Error:\n"
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync " %Rrc -- %Rrf\n", rc, rc);
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync switch (rc)
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync {
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync case VERR_VM_DRIVER_NOT_INSTALLED:
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync RTPrintf("Cannot access the kernel driver. Make sure the kernel module has been \n"
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync "loaded successfully. Aborting ...\n");
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync break;
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync default:
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync break;
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync return 1;
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync }
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync return TrustedMain(argc, argv, envp);
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync}
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync#endif /* !VBOX_WITH_HARDENING */
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync#ifdef VBOX_WITH_XPCOM
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsyncNS_DECL_CLASSINFO(NullFB)
37e7010b28a4667800196960b59cd63b5434b7d7vboxsyncNS_IMPL_THREADSAFE_ISUPPORTS1_CI(NullFB, IFramebuffer)
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync#endif
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync