VBoxHeadless.cpp revision 0f299115229ed1bfd92c030c82b8f9930f109f2d
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync/** @file
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync *
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * VBox frontends: VBoxHeadless (headless frontend):
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Headless server executable
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync/*
29a65fa8b740a860f86812328cf900b8d68d93bevboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync *
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * available from http://www.virtualbox.org. This file is free software;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * you can redistribute it and/or modify it under the terms of the GNU
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * General Public License (GPL) as published by the Free Software
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync *
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * additional information or have any questions.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync#include <VBox/com/com.h>
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync#include <VBox/com/string.h>
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync#include <VBox/com/Guid.h>
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync#include <VBox/com/ErrorInfo.h>
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#include <VBox/com/errorprint2.h>
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#include <VBox/com/EventQueue.h>
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#include <VBox/com/VirtualBox.h>
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncusing namespace com;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#define LOG_GROUP LOG_GROUP_GUI
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#include <VBox/log.h>
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#include <VBox/version.h>
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#ifdef VBOX_WITH_VRDP
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync# include <VBox/vrdpapi.h>
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#endif
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#include <iprt/ctype.h>
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#include <iprt/initterm.h>
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#include <iprt/stream.h>
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#include <iprt/ldr.h>
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#include <iprt/getopt.h>
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#include <iprt/env.h>
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#include <VBox/err.h>
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#ifdef VBOX_FFMPEG
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#include <cstdlib>
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#include <cerrno>
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync#include "VBoxHeadless.h"
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync#include <iprt/env.h>
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync#include <iprt/param.h>
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#include <iprt/process.h>
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#include <VBox/sup.h>
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#endif
acca7ab818eb8c2832aa27e27ce53133fba927dbvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync//#define VBOX_WITH_SAVESTATE_ON_SIGNAL
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#ifdef VBOX_WITH_SAVESTATE_ON_SIGNAL
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync#include <signal.h>
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync#endif
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync#ifdef VBOX_WITH_VRDP
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync# include "Framebuffer.h"
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync#endif
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync////////////////////////////////////////////////////////////////////////////////
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync#define LogError(m,rc) \
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync do { \
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync Log (("VBoxHeadless: ERROR: " m " [rc=0x%08X]\n", rc)); \
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync RTPrintf ("%s\n", m); \
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync } while (0)
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync////////////////////////////////////////////////////////////////////////////////
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
dbec828311ed2a5cf6fbc68fe4391d516ba4f92fvboxsync/* global weak references (for event handlers) */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncstatic ComPtr <ISession, ComWeakRef> gSession;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncstatic ComPtr <IConsole, ComWeakRef> gConsole;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncstatic EventQueue *gEventQ = NULL;
5eb36887f6970e0033f63fa135f3bb8fbfd6059bvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync////////////////////////////////////////////////////////////////////////////////
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync/**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * State change event.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncclass StateChangeEvent : public Event
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync{
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncpublic:
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync StateChangeEvent (MachineState_T state) : mState (state) {}
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncprotected:
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync void *handler()
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync LogFlow (("VBoxHeadless: StateChangeEvent: %d\n", mState));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* post the termination event if the machine has been PoweredDown/Saved/Aborted */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (mState < MachineState_Running)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync gEventQ->postEvent (NULL);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return 0;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncprivate:
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync MachineState_T mState;
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync};
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync/**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Callback handler for machine events.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncclass ConsoleCallback : public IConsoleCallback
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync{
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncpublic:
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ConsoleCallback ()
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#ifndef VBOX_WITH_XPCOM
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync refcnt = 0;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#endif
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync }
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync virtual ~ConsoleCallback() {}
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync NS_DECL_ISUPPORTS
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync#ifndef VBOX_WITH_XPCOM
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync STDMETHOD_(ULONG, AddRef)()
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return ::InterlockedIncrement(&refcnt);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync STDMETHOD_(ULONG, Release)()
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync long cnt = ::InterlockedDecrement(&refcnt);
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync if (cnt == 0)
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync delete this;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return cnt;
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync }
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync STDMETHOD(QueryInterface) (REFIID riid , void **ppObj)
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync {
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync if (riid == IID_IUnknown)
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync {
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync *ppObj = this;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync AddRef();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return S_OK;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (riid == IID_IConsoleCallback)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync *ppObj = this;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync AddRef();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return S_OK;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync *ppObj = NULL;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return E_NOINTERFACE;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#endif
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync STDMETHOD(OnMousePointerShapeChange) (BOOL visible, BOOL alpha, ULONG xHot, ULONG yHot,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ULONG width, ULONG height, BYTE *shape)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return S_OK;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync STDMETHOD(OnMouseCapabilityChange) (BOOL supportsAbsolute, BOOL needsHostCursor)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Emit absolute mouse event to actually enable the host mouse cursor. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (supportsAbsolute && gConsole)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ComPtr<IMouse> mouse;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync gConsole->COMGETTER(Mouse)(mouse.asOutParam());
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (mouse)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync mouse->PutMouseEventAbsolute(-1, -1, 0, 0);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return S_OK;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync STDMETHOD(OnKeyboardLedsChange)(BOOL fNumLock, BOOL fCapsLock, BOOL fScrollLock)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return S_OK;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync STDMETHOD(OnStateChange) (MachineState_T machineState)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync gEventQ->postEvent (new StateChangeEvent (machineState));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return S_OK;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync STDMETHOD(OnExtraDataChange) (BSTR key)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return S_OK;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync STDMETHOD(OnAdditionsStateChange)()
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return S_OK;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync STDMETHOD(OnDVDDriveChange)()
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return S_OK;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync STDMETHOD(OnFloppyDriveChange)()
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return S_OK;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync STDMETHOD(OnNetworkAdapterChange) (INetworkAdapter *aNetworkAdapter)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return S_OK;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync STDMETHOD(OnSerialPortChange) (ISerialPort *aSerialPort)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return S_OK;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync STDMETHOD(OnParallelPortChange) (IParallelPort *aParallelPort)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return S_OK;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
7755c0a4b7b215f612d9d27848c2584ffafe7a66vboxsync STDMETHOD(OnVRDPServerChange)()
7755c0a4b7b215f612d9d27848c2584ffafe7a66vboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return S_OK;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync STDMETHOD(OnUSBControllerChange)()
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return S_OK;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync STDMETHOD(OnStorageControllerChange)()
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync return S_OK;
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync }
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync STDMETHOD(OnUSBDeviceStateChange) (IUSBDevice *aDevice, BOOL aAttached,
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync IVirtualBoxErrorInfo *aError)
602e0e27740395dba64bee2e0a8aef023ebd7650vboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return S_OK;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync STDMETHOD(OnSharedFolderChange) (Scope_T aScope)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return S_OK;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync STDMETHOD(OnRuntimeError)(BOOL fatal, IN_BSTR id, IN_BSTR message)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return S_OK;
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync }
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync STDMETHOD(OnCanShowWindow)(BOOL *canShow)
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync {
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync if (!canShow)
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync return E_POINTER;
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync /* Headless windows should not be shown */
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync *canShow = FALSE;
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync return S_OK;
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync }
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync STDMETHOD(OnShowWindow) (ULONG64 *winId)
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync {
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync /* OnCanShowWindow() always returns FALSE, so this call should never
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync * happen. */
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync AssertFailed();
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync if (!winId)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return E_POINTER;
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync *winId = 0;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return E_NOTIMPL;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncprivate:
78df65edff21c11c537f38e736707ea434ab5623vboxsync
78df65edff21c11c537f38e736707ea434ab5623vboxsync#ifndef VBOX_WITH_XPCOM
78df65edff21c11c537f38e736707ea434ab5623vboxsync long refcnt;
78df65edff21c11c537f38e736707ea434ab5623vboxsync#endif
78df65edff21c11c537f38e736707ea434ab5623vboxsync};
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync#ifdef VBOX_WITH_XPCOM
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsyncNS_DECL_CLASSINFO (ConsoleCallback)
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsyncNS_IMPL_THREADSAFE_ISUPPORTS1_CI (ConsoleCallback, IConsoleCallback)
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync#endif
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync#ifdef VBOX_WITH_SAVESTATE_ON_SIGNAL
78df65edff21c11c537f38e736707ea434ab5623vboxsyncstatic void SaveState(int sig)
78df65edff21c11c537f38e736707ea434ab5623vboxsync{
78df65edff21c11c537f38e736707ea434ab5623vboxsync ComPtr <IProgress> progress = NULL;
78df65edff21c11c537f38e736707ea434ab5623vboxsync
78df65edff21c11c537f38e736707ea434ab5623vboxsync/** @todo Deal with nested signals, multithreaded signal dispatching (esp. on windows),
78df65edff21c11c537f38e736707ea434ab5623vboxsync * and multiple signals (both SIGINT and SIGTERM in some order).
78df65edff21c11c537f38e736707ea434ab5623vboxsync * Consider processing the signal request asynchronously since there are lots of things
78df65edff21c11c537f38e736707ea434ab5623vboxsync * which aren't safe (like RTPrintf and printf IIRC) in a signal context. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTPrintf("Signal received, saving state.\n");
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync HRESULT rc = gConsole->SaveState(progress.asOutParam());
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (FAILED(S_OK))
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync {
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync RTPrintf("Error saving state! rc = 0x%x\n", rc);
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync return;
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync }
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync Assert(progress);
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync LONG cPercent = 0;
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTPrintf("0%%");
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTStrmFlush(g_pStdOut);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync for (;;)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync BOOL fCompleted = false;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync rc = progress->COMGETTER(Completed)(&fCompleted);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (FAILED(rc) || fCompleted)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync break;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ULONG cPercentNow;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync rc = progress->COMGETTER(Percent)(&cPercentNow);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (FAILED(rc))
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync break;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if ((cPercentNow / 10) != (cPercent / 10))
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync cPercent = cPercentNow;
78df65edff21c11c537f38e736707ea434ab5623vboxsync RTPrintf("...%d%%", cPercentNow);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTStrmFlush(g_pStdOut);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
78df65edff21c11c537f38e736707ea434ab5623vboxsync /* wait */
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync rc = progress->WaitForCompletion(100);
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync }
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync HRESULT lrc;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync rc = progress->COMGETTER(ResultCode)(&lrc);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (FAILED(rc))
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync lrc = ~0;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (!lrc)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync RTPrintf(" -- Saved the state successfully.\n");
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync RTThreadYield();
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync }
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync else
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync RTPrintf("-- Error saving state, lrc=%d (%#x)\n", lrc, lrc);
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync}
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync#endif /* VBOX_WITH_SAVESTATE_ON_SIGNAL */
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync////////////////////////////////////////////////////////////////////////////////
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncstatic void show_usage()
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync{
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTPrintf("Usage:\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " -s, -startvm, --startvm <name|uuid> Start given VM (required argument)\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#ifdef VBOX_WITH_VRDP
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " -v, -vrdp, --vrdp on|off|config Enable (default) or disable the VRDP\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " server or don't change the setting\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " -p, -vrdpport, --vrdpport <port> Port number the VRDP server will bind\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " to\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " -a, -vrdpaddress, --vrdpaddress <ip> Interface IP the VRDP will bind to \n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#endif
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#ifdef VBOX_FFMPEG
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " -c, -capture, --capture Record the VM screen output to a file\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " -w, --width Frame width when recording\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " -h, --height Frame height when recording\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " -r, --bitrate Recording bit rate when recording\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " -f, --filename File name when recording. The codec\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " used will be chosen based on the\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " file extension\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#endif
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync "\n");
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync}
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#ifdef VBOX_FFMPEG
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync/**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Parse the environment for variables which can influence the FFMPEG settings.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * purely for backwards compatibility.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param pulFrameWidth may be updated with a desired frame width
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param pulFrameHeight may be updated with a desired frame height
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param pulBitRate may be updated with a desired bit rate
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param ppszFileName may be updated with a desired file name
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncstatic void parse_environ(unsigned long *pulFrameWidth, unsigned long *pulFrameHeight,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync unsigned long *pulBitRate, const char **ppszFileName)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync{
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync const char *pszEnvTemp;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if ((pszEnvTemp = RTEnvGet("VBOX_CAPTUREWIDTH")) != 0)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync errno = 0;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync unsigned long ulFrameWidth = strtoul(pszEnvTemp, 0, 10);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (errno != 0)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync LogError("VBoxHeadless: ERROR: invalid VBOX_CAPTUREWIDTH environment variable", 0);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync else
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync *pulFrameWidth = ulFrameWidth;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if ((pszEnvTemp = RTEnvGet("VBOX_CAPTUREHEIGHT")) != 0)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync errno = 0;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync unsigned long ulFrameHeight = strtoul(pszEnvTemp, 0, 10);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (errno != 0)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync LogError("VBoxHeadless: ERROR: invalid VBOX_CAPTUREHEIGHT environment variable", 0);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync else
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync *pulFrameHeight = ulFrameHeight;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if ((pszEnvTemp = RTEnvGet("VBOX_CAPTUREBITRATE")) != 0)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync errno = 0;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync unsigned long ulBitRate = strtoul(pszEnvTemp, 0, 10);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (errno != 0)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync LogError("VBoxHeadless: ERROR: invalid VBOX_CAPTUREBITRATE environment variable", 0);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync else
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync *pulBitRate = ulBitRate;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if ((pszEnvTemp = RTEnvGet("VBOX_CAPTUREFILE")) != 0)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync *ppszFileName = pszEnvTemp;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync}
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#endif /* VBOX_FFMPEG defined */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync/**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Entry point.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncextern "C" DECLEXPORT (int) TrustedMain (int argc, char **argv, char **envp)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync{
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#ifdef VBOX_WITH_VRDP
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ULONG vrdpPort = ~0U;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync const char *vrdpAddress = NULL;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync const char *vrdpEnabled = NULL;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#endif
7fee49908ea4b9f6cb4f9cc745633c4969ed6318vboxsync unsigned fRawR0 = ~0U;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync unsigned fRawR3 = ~0U;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync unsigned fPATM = ~0U;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync unsigned fCSAM = ~0U;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#ifdef VBOX_FFMPEG
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync unsigned fFFMPEG = 0;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync unsigned long ulFrameWidth = 800;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync unsigned long ulFrameHeight = 600;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync unsigned long ulBitRate = 300000;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync char pszMPEGFile[RTPATH_MAX];
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync const char *pszFileNameParam = "VBox-%d.vob";
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#endif /* VBOX_FFMPEG */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Make sure that DISPLAY is unset, so that X11 bits do not get initialised
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * on X11-using OSes. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /** @todo this should really be taken care of in Main. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTEnvUnset("DISPLAY");
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync LogFlow (("VBoxHeadless STARTED.\n"));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTPrintf ("VirtualBox Headless Interface %s\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync "(C) 2008-2009 Sun Microsystems, Inc.\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync "All rights reserved.\n\n",
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync VBOX_VERSION_STRING);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Guid id;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* the below cannot be Bstr because on Linux Bstr doesn't work until XPCOM (nsMemory) is initialized */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync const char *name = NULL;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#ifdef VBOX_FFMPEG
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Parse the environment */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync parse_environ(&ulFrameWidth, &ulFrameHeight, &ulBitRate, &pszFileNameParam);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#endif
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync enum eHeadlessOptions
7fee49908ea4b9f6cb4f9cc745633c4969ed6318vboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync OPT_RAW_R0 = 0x100,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync OPT_NO_RAW_R0,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync OPT_RAW_R3,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync OPT_NO_RAW_R3,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync OPT_PATM,
7fee49908ea4b9f6cb4f9cc745633c4969ed6318vboxsync OPT_NO_PATM,
7fee49908ea4b9f6cb4f9cc745633c4969ed6318vboxsync OPT_CSAM,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync OPT_NO_CSAM,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync OPT_COMMENT,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync };
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
090c459b9e90ca46e2ce2b8c81533ade3b23f3e9vboxsync static const RTGETOPTDEF s_aOptions[] =
090c459b9e90ca46e2ce2b8c81533ade3b23f3e9vboxsync {
090c459b9e90ca46e2ce2b8c81533ade3b23f3e9vboxsync { "-startvm", 's', RTGETOPT_REQ_STRING },
7fee49908ea4b9f6cb4f9cc745633c4969ed6318vboxsync { "--startvm", 's', RTGETOPT_REQ_STRING },
7fee49908ea4b9f6cb4f9cc745633c4969ed6318vboxsync#ifdef VBOX_WITH_VRDP
7fee49908ea4b9f6cb4f9cc745633c4969ed6318vboxsync { "-vrdpport", 'p', RTGETOPT_REQ_UINT32 },
7fee49908ea4b9f6cb4f9cc745633c4969ed6318vboxsync { "--vrdpport", 'p', RTGETOPT_REQ_UINT32 },
7fee49908ea4b9f6cb4f9cc745633c4969ed6318vboxsync { "-vrdpaddress", 'a', RTGETOPT_REQ_STRING },
7fee49908ea4b9f6cb4f9cc745633c4969ed6318vboxsync { "--vrdpaddress", 'a', RTGETOPT_REQ_STRING },
7fee49908ea4b9f6cb4f9cc745633c4969ed6318vboxsync { "-vrdp", 'v', RTGETOPT_REQ_STRING },
7fee49908ea4b9f6cb4f9cc745633c4969ed6318vboxsync { "--vrdp", 'v', RTGETOPT_REQ_STRING },
7fee49908ea4b9f6cb4f9cc745633c4969ed6318vboxsync#endif /* VBOX_WITH_VRDP defined */
7fee49908ea4b9f6cb4f9cc745633c4969ed6318vboxsync { "-rawr0", OPT_RAW_R0, 0 },
090c459b9e90ca46e2ce2b8c81533ade3b23f3e9vboxsync { "--rawr0", OPT_RAW_R0, 0 },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync { "-norawr0", OPT_NO_RAW_R0, 0 },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync { "--norawr0", OPT_NO_RAW_R0, 0 },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync { "-rawr3", OPT_RAW_R3, 0 },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync { "--rawr3", OPT_RAW_R3, 0 },
090c459b9e90ca46e2ce2b8c81533ade3b23f3e9vboxsync { "-norawr3", OPT_NO_RAW_R3, 0 },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync { "--norawr3", OPT_NO_RAW_R3, 0 },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync { "-patm", OPT_PATM, 0 },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync { "--patm", OPT_PATM, 0 },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync { "-nopatm", OPT_NO_PATM, 0 },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync { "--nopatm", OPT_NO_PATM, 0 },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync { "-csam", OPT_CSAM, 0 },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync { "--csam", OPT_CSAM, 0 },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync { "-nocsam", OPT_NO_CSAM, 0 },
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync { "--nocsam", OPT_NO_CSAM, 0 },
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync#ifdef VBOX_FFMPEG
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync { "-capture", 'c', 0 },
7fee49908ea4b9f6cb4f9cc745633c4969ed6318vboxsync { "--capture", 'c', 0 },
7fee49908ea4b9f6cb4f9cc745633c4969ed6318vboxsync { "--width", 'w', RTGETOPT_REQ_UINT32 },
7fee49908ea4b9f6cb4f9cc745633c4969ed6318vboxsync { "--height", 'h', RTGETOPT_REQ_UINT32 },
7fee49908ea4b9f6cb4f9cc745633c4969ed6318vboxsync { "--bitrate", 'r', RTGETOPT_REQ_UINT32 },
7fee49908ea4b9f6cb4f9cc745633c4969ed6318vboxsync { "--filename", 'f', RTGETOPT_REQ_STRING },
7fee49908ea4b9f6cb4f9cc745633c4969ed6318vboxsync#endif /* VBOX_FFMPEG defined */
7fee49908ea4b9f6cb4f9cc745633c4969ed6318vboxsync { "-comment", OPT_COMMENT, RTGETOPT_REQ_STRING },
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync { "--comment", OPT_COMMENT, RTGETOPT_REQ_STRING }
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync };
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync // parse the command line
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync int ch;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTGETOPTUNION ValueUnion;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTGETOPTSTATE GetState;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1, 0 /* fFlags */);
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync while ((ch = RTGetOpt(&GetState, &ValueUnion)))
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync {
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync switch(ch)
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync {
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync case 's':
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync id = ValueUnion.psz;
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync /* If the argument was not a UUID, then it must be a name. */
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync if (!id)
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync name = ValueUnion.psz;
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync break;
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync#ifdef VBOX_WITH_VRDP
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync case 'p':
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync vrdpPort = ValueUnion.u32;
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync break;
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync case 'a':
a86135e41c89c7b599607649347a4240809c784bvboxsync vrdpAddress = ValueUnion.psz;
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync break;
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync case 'v':
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync vrdpEnabled = ValueUnion.psz;
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync break;
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync#endif /* VBOX_WITH_VRDP defined */
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync case OPT_RAW_R0:
7fee49908ea4b9f6cb4f9cc745633c4969ed6318vboxsync fRawR0 = true;
7fee49908ea4b9f6cb4f9cc745633c4969ed6318vboxsync break;
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync case OPT_NO_RAW_R0:
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync fRawR0 = false;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync break;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync case OPT_RAW_R3:
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync fRawR3 = true;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync break;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync case OPT_NO_RAW_R3:
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync fRawR3 = false;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync break;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync case OPT_PATM:
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync fPATM = true;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync break;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync case OPT_NO_PATM:
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync fPATM = false;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync break;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync case OPT_CSAM:
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync fCSAM = true;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync break;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync case OPT_NO_CSAM:
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync fCSAM = false;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync break;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#ifdef VBOX_FFMPEG
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync case 'c':
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync fFFMPEG = true;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync break;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync case 'w':
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ulFrameWidth = ValueUnion.u32;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync break;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync case 'h':
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ulFrameHeight = ValueUnion.u32;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync break;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync case 'r':
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ulBitRate = ValueUnion.u32;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync break;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync case 'f':
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync pszFileNameParam = ValueUnion.psz;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync break;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#endif /* VBOX_FFMPEG defined */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync case VINF_GETOPT_NOT_OPTION:
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTPrintf("Invalid parameter '%s'\n\n", ValueUnion.psz);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync show_usage();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return -1;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync default:
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (ch > 0)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (RT_C_IS_PRINT(ch))
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTPrintf("Invalid option -%c\n\n", ch);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync else
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTPrintf("Invalid option case %i", ch);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync else if (ch == VERR_GETOPT_UNKNOWN_OPTION)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTPrintf("Unknown option: %s\n\n", ValueUnion.psz);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync else if (ValueUnion.pDef)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTPrintf("%s: %Rrs\n\n", ValueUnion.pDef->pszLong, ch);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync else
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTPrintf("Error: %Rrs", ch);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync show_usage();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return -1;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#ifdef VBOX_FFMPEG
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (ulFrameWidth < 512 || ulFrameWidth > 2048 || ulFrameWidth % 2)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync LogError("VBoxHeadless: ERROR: please specify an even frame width between 512 and 2048", 0);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return -1;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (ulFrameHeight < 384 || ulFrameHeight > 1536 || ulFrameHeight % 2)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync LogError("VBoxHeadless: ERROR: please specify an even frame height between 384 and 1536", 0);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return -1;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (ulBitRate < 300000 || ulBitRate > 1000000)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync LogError("VBoxHeadless: ERROR: please specify an even bitrate between 300000 and 1000000", 0);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return -1;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Make sure we only have %d or %u (or none) in the file name specified */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync char *pcPercent = (char*)strchr(pszFileNameParam, '%');
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (pcPercent != 0 && *(pcPercent + 1) != 'd' && *(pcPercent + 1) != 'u')
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync LogError("VBoxHeadless: ERROR: Only %%d and %%u are allowed in the capture file name.", -1);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return -1;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* And no more than one % in the name */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (pcPercent != 0 && strchr(pcPercent + 1, '%') != 0)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync LogError("VBoxHeadless: ERROR: Only one format modifier is allowed in the capture file name.", -1);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return -1;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTStrPrintf(&pszMPEGFile[0], RTPATH_MAX, pszFileNameParam, RTProcSelf());
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#endif /* defined VBOX_FFMPEG */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (!id && !name)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync show_usage();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return -1;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync HRESULT rc;
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync rc = com::Initialize();
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync if (FAILED(rc))
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync {
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync RTPrintf("VBoxHeadless: ERROR: failed to initialize COM!\n");
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync return rc;
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync }
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync do
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync {
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync ComPtr<IVirtualBox> virtualBox;
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync ComPtr<ISession> session;
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync rc = virtualBox.createLocalObject(CLSID_VirtualBox);
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync if (FAILED(rc))
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync RTPrintf("VBoxHeadless: ERROR: failed to create the VirtualBox object!\n");
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync else
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync {
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync rc = session.createInprocObject(CLSID_Session);
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync if (FAILED(rc))
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync RTPrintf("VBoxHeadless: ERROR: failed to create a session object!\n");
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync }
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync if (FAILED(rc))
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync {
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync com::ErrorInfo info;
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync if (!info.isFullAvailable() && !info.isBasicAvailable())
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync {
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync com::GluePrintRCMessage(rc);
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync RTPrintf("Most likely, the VirtualBox COM server is not running or failed to start.\n");
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync }
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync else
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync GluePrintErrorInfo(info);
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync break;
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync }
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync /* find ID by name */
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync if (!id)
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync {
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync ComPtr <IMachine> m;
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync rc = virtualBox->FindMachine (Bstr (name), m.asOutParam());
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync if (FAILED (rc))
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync LogError ("Invalid machine name!\n", rc);
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync break;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync m->COMGETTER(Id) (id.asOutParam());
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync AssertComRC (rc);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (FAILED (rc))
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync break;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Log (("VBoxHeadless: Opening a session with machine (id={%s})...\n",
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync id.toString().raw()));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync // open a session
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync CHECK_ERROR_BREAK(virtualBox, OpenSession (session, id));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync /* get the console */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ComPtr <IConsole> console;
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync CHECK_ERROR_BREAK(session, COMGETTER (Console) (console.asOutParam()));
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync /* get the machine */
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync ComPtr <IMachine> machine;
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync CHECK_ERROR_BREAK(console, COMGETTER(Machine) (machine.asOutParam()));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ComPtr <IDisplay> display;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync CHECK_ERROR_BREAK(console, COMGETTER(Display) (display.asOutParam()));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#ifdef VBOX_FFMPEG
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync IFramebuffer *pFramebuffer = 0;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTLDRMOD hLdrFFmpegFB;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync PFNREGISTERFFMPEGFB pfnRegisterFFmpegFB;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (fFFMPEG)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync int rrc = VINF_SUCCESS, rcc = S_OK;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Log2(("VBoxHeadless: loading VBoxFFmpegFB shared library\n"));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync rrc = SUPR3HardenedLdrLoadAppPriv("VBoxFFmpegFB", &hLdrFFmpegFB);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (RT_SUCCESS(rrc))
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Log2(("VBoxHeadless: looking up symbol VBoxRegisterFFmpegFB\n"));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync rrc = RTLdrGetSymbol(hLdrFFmpegFB, "VBoxRegisterFFmpegFB",
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync reinterpret_cast<void **>(&pfnRegisterFFmpegFB));
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync if (RT_FAILURE(rrc))
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync LogError("Failed to load the video capture extension, possibly due to a damaged file\n", rrc);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync else
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync LogError("Failed to load the video capture extension\n", rrc);
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync if (RT_SUCCESS(rrc))
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Log2(("VBoxHeadless: calling pfnRegisterFFmpegFB\n"));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync rcc = pfnRegisterFFmpegFB(ulFrameWidth, ulFrameHeight, ulBitRate,
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync pszMPEGFile, &pFramebuffer);
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync if (rcc != S_OK)
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync LogError("Failed to initialise video capturing - make sure that the file format\n"
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync "you wish to use is supported on your system\n", rcc);
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync }
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync if (RT_SUCCESS(rrc) && (S_OK == rcc))
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync {
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync Log2(("VBoxHeadless: Registering framebuffer\n"));
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync pFramebuffer->AddRef();
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync display->RegisterExternalFramebuffer(pFramebuffer);
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync }
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync if (!RT_SUCCESS(rrc) || (rcc != S_OK))
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync rc = E_FAIL;
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync }
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync if (rc != S_OK)
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync {
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync return -1;
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync }
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync#endif /* defined(VBOX_FFMPEG) */
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync ULONG cMonitors = 1;
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync machine->COMGETTER(MonitorCount)(&cMonitors);
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#ifdef VBOX_WITH_VRDP
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync unsigned uScreenId;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync for (uScreenId = 0; uScreenId < cMonitors; uScreenId++)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#ifdef VBOX_FFMPEG
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (fFFMPEG && uScreenId == 0)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Already registered. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync continue;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#endif /* defined(VBOX_FFMPEG) */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync VRDPFramebuffer *pFramebuffer = new VRDPFramebuffer ();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (!pFramebuffer)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTPrintf("Error: could not create framebuffer object %d\n", uScreenId);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return -1;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync pFramebuffer->AddRef();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync display->SetFramebuffer(uScreenId, pFramebuffer);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#endif
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* get the machine debugger (isn't necessarily available) */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ComPtr <IMachineDebugger> machineDebugger;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync console->COMGETTER(Debugger)(machineDebugger.asOutParam());
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (machineDebugger)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Log(("Machine debugger available!\n"));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (fRawR0 != ~0U)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (!machineDebugger)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTPrintf("Error: No debugger object; -%srawr0 cannot be executed!\n", fRawR0 ? "" : "no");
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync break;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync machineDebugger->COMSETTER(RecompileSupervisor)(!fRawR0);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (fRawR3 != ~0U)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (!machineDebugger)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTPrintf("Error: No debugger object; -%srawr3 cannot be executed!\n", fRawR0 ? "" : "no");
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync break;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync machineDebugger->COMSETTER(RecompileUser)(!fRawR3);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (fPATM != ~0U)
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (!machineDebugger)
6abae205eac4f4a16f6ad5a2a71ed1f36d6a57b0vboxsync {
6abae205eac4f4a16f6ad5a2a71ed1f36d6a57b0vboxsync RTPrintf("Error: No debugger object; -%spatm cannot be executed!\n", fRawR0 ? "" : "no");
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync break;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync machineDebugger->COMSETTER(PATMEnabled)(fPATM);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (fCSAM != ~0U)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (!machineDebugger)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTPrintf("Error: No debugger object; -%scsam cannot be executed!\n", fRawR0 ? "" : "no");
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync break;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync machineDebugger->COMSETTER(CSAMEnabled)(fCSAM);
6abae205eac4f4a16f6ad5a2a71ed1f36d6a57b0vboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* create an event queue */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync EventQueue eventQ;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* initialize global references */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync gSession = session;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync gConsole = console;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync gEventQ = &eventQ;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* register a callback for machine events */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ConsoleCallback *callback = new ConsoleCallback ();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync callback->AddRef();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync CHECK_ERROR(console, RegisterCallback (callback));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync callback->Release();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (FAILED (rc))
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync break;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#ifdef VBOX_WITH_VRDP
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* default is to enable the RDP server (backward compatibility) */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync BOOL fVRDPEnable = true;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync BOOL fVRDPEnabled;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ComPtr <IVRDPServer> vrdpServer;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync CHECK_ERROR_BREAK(machine, COMGETTER (VRDPServer) (vrdpServer.asOutParam()));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync CHECK_ERROR_BREAK(vrdpServer, COMGETTER(Enabled) (&fVRDPEnabled));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (vrdpEnabled != NULL)
6abae205eac4f4a16f6ad5a2a71ed1f36d6a57b0vboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* -vrdp on|off|config */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (!strcmp(vrdpEnabled, "off") || !strcmp(vrdpEnabled, "disable"))
6abae205eac4f4a16f6ad5a2a71ed1f36d6a57b0vboxsync fVRDPEnable = false;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync else if (!strcmp(vrdpEnabled, "config"))
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (!fVRDPEnabled)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync fVRDPEnable = false;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync else if (strcmp(vrdpEnabled, "on") && strcmp(vrdpEnabled, "enable"))
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTPrintf("-vrdp requires an argument (on|off|config)\n");
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync break;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (fVRDPEnable)
29a65fa8b740a860f86812328cf900b8d68d93bevboxsync {
37a7e3e6f9ce5f6cabeb3f734044e9e8ca9cb1bfvboxsync Log (("VBoxHeadless: Enabling VRDP server...\n"));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* set VRDP port if requested by the user */
29a65fa8b740a860f86812328cf900b8d68d93bevboxsync if (vrdpPort != ~0U)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync CHECK_ERROR_BREAK(vrdpServer, COMSETTER(Port)(vrdpPort));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync else
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync CHECK_ERROR_BREAK(vrdpServer, COMGETTER(Port)(&vrdpPort));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* set VRDP address if requested by the user */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (vrdpAddress != NULL)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync CHECK_ERROR_BREAK(vrdpServer, COMSETTER(NetAddress)(Bstr(vrdpAddress)));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* enable VRDP server (only if currently disabled) */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (!fVRDPEnabled)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync CHECK_ERROR_BREAK(vrdpServer, COMSETTER(Enabled) (TRUE));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
090c459b9e90ca46e2ce2b8c81533ade3b23f3e9vboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync else
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* disable VRDP server (only if currently enabled */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (fVRDPEnabled)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync CHECK_ERROR_BREAK(vrdpServer, COMSETTER(Enabled) (FALSE));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#endif
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Log (("VBoxHeadless: Powering up the machine...\n"));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#ifdef VBOX_WITH_VRDP
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (fVRDPEnable)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTPrintf("Listening on port %d\n", !vrdpPort ? VRDP_DEFAULT_PORT : vrdpPort);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#endif
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ComPtr <IProgress> progress;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync CHECK_ERROR_BREAK(console, PowerUp (progress.asOutParam()));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* wait for result because there can be errors */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (SUCCEEDED(progress->WaitForCompletion (-1)))
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync progress->COMGETTER(ResultCode)(&rc);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (FAILED(rc))
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync com::ProgressErrorInfo info(progress);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (info.isBasicAvailable())
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTPrintf("Error: failed to start machine. Error message: %lS\n", info.getText().raw());
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync else
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync RTPrintf("Error: failed to start machine. No error message available!\n");
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync }
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync }
af0a09edb4c1431b606fe207d4138da008f67f13vboxsync }
af0a09edb4c1431b606fe207d4138da008f67f13vboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#ifdef VBOX_WITH_SAVESTATE_ON_SIGNAL
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync signal(SIGINT, SaveState);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync signal(SIGTERM, SaveState);
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync#endif
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync Log (("VBoxHeadless: Waiting for PowerDown...\n"));
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync
602e0e27740395dba64bee2e0a8aef023ebd7650vboxsync Event *e;
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync while (eventQ.waitForEvent (&e) && e)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync eventQ.handleEvent (e);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Log (("VBoxHeadless: event loop has terminated...\n"));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#ifdef VBOX_FFMPEG
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (pFramebuffer)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync pFramebuffer->Release ();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Log(("Released framebuffer\n"));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync pFramebuffer = NULL;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#endif /* defined(VBOX_FFMPEG) */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* we don't have to disable VRDP here because we don't save the settings of the VM */
6abae205eac4f4a16f6ad5a2a71ed1f36d6a57b0vboxsync
6abae205eac4f4a16f6ad5a2a71ed1f36d6a57b0vboxsync /*
6abae205eac4f4a16f6ad5a2a71ed1f36d6a57b0vboxsync * Close the session. This will also uninitialize the console and
6abae205eac4f4a16f6ad5a2a71ed1f36d6a57b0vboxsync * unregister the callback we've registered before.
6abae205eac4f4a16f6ad5a2a71ed1f36d6a57b0vboxsync */
6abae205eac4f4a16f6ad5a2a71ed1f36d6a57b0vboxsync Log (("VBoxHeadless: Closing the session...\n"));
6abae205eac4f4a16f6ad5a2a71ed1f36d6a57b0vboxsync session->Close();
6abae205eac4f4a16f6ad5a2a71ed1f36d6a57b0vboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync while (0);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync com::Shutdown();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync LogFlow (("VBoxHeadless FINISHED.\n"));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return rc;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync}
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#ifndef VBOX_WITH_HARDENING
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync/**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Main entry point.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncint main (int argc, char **argv, char **envp)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync{
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync // initialize VBox Runtime
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync int rc = RTR3InitAndSUPLib();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (RT_FAILURE(rc))
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTPrintf("VBoxHeadless: Runtime Error!\n");
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync switch (rc)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync case VERR_VM_DRIVER_NOT_INSTALLED:
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTPrintf("Cannot access the kernel driver. Make sure the kernel module has been \n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync "loaded successfully. Aborting ...\n");
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync break;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync default:
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync break;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return 1;
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync return TrustedMain (argc, argv, envp);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync}
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#endif /* !VBOX_WITH_HARDENING */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync