VBoxModAPIMonitor.cpp revision 72b091c1ee2559c7fd09fbd8e60d1ac3b80a1f07
/* $Id$ */
/** @file
* VBoxModAPIMonitor - API monitor module for detecting host isolation.
*/
/*
* Copyright (C) 2012 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#ifndef VBOX_ONLY_DOCS
#endif /* !VBOX_ONLY_DOCS */
#include <package-generated.h>
#include <iprt/buildconfig.h>
#include <iprt/critsect.h>
#include <iprt/initterm.h>
#include <iprt/semaphore.h>
#include <map>
#include <string>
#include <signal.h>
#include "VBoxWatchdogInternal.h"
using namespace com;
#define VBOX_MOD_APIMON_NAME "apimon"
/**
* The module's RTGetOpt-IDs for the command line.
*/
enum GETOPTDEF_APIMON
{
GETOPTDEF_APIMON_ISLN_RESPONSE = 1000,
};
/**
* The module's command line arguments.
*/
static const RTGETOPTDEF g_aAPIMonitorOpts[] = {
};
static unsigned long g_ulAPIMonIslnTimeoutMS = 0;
static Bstr g_strAPIMonGroups;
static Bstr g_strAPIMonIslnCmdResp;
/* Callbacks. */
static DECLCALLBACK(int) VBoxModAPIMonitorPreInit(void)
{
return VINF_SUCCESS;
}
{
if (!argc) /* Take a shortcut. */
return -1;
0 /* First */, 0 /*fFlags*/);
if (RT_FAILURE(rc))
return rc;
rc = 0; /* Set default parsing result to valid. */
int c;
{
switch (c)
{
break;
if (g_ulAPIMonIslnTimeoutMS < 1000)
g_ulAPIMonIslnTimeoutMS = 1000;
break;
case GETOPTDEF_APIMON_GROUPS:
break;
default:
break;
}
}
return rc;
}
static DECLCALLBACK(int) VBoxModAPIMonitorInit(void)
{
do
{
/* Host isolation timeout (in ms). */
if (!g_ulAPIMonIslnTimeoutMS) /* Not set by command line? */
{
CHECK_ERROR_BREAK(g_pVirtualBox, GetExtraData(Bstr("VBoxInternal2/Watchdog/APIMonitor/IsolationTimeout").raw(),
bstrValue.asOutParam()));
}
if (!g_ulAPIMonIslnTimeoutMS)
{
/* Default is 30 seconds timeout. */
}
/* VM groups to watch for. */
{
CHECK_ERROR_BREAK(g_pVirtualBox, GetExtraData(Bstr("VBoxInternal2/Watchdog/APIMonitor/Groups").raw(),
}
/* Host isolation command response. */
{
CHECK_ERROR_BREAK(g_pVirtualBox, GetExtraData(Bstr("VBoxInternal2/Watchdog/APIMonitor/IsolationResponse").raw(),
}
} while (0);
}
static DECLCALLBACK(int) VBoxModAPIMonitorMain(void)
{
return VINF_SUCCESS; /* Nothing to do here right now. */
}
static DECLCALLBACK(int) VBoxModAPIMonitorStop(void)
{
return VINF_SUCCESS;
}
static DECLCALLBACK(void) VBoxModAPIMonitorTerm(void)
{
}
{
return VINF_SUCCESS;
}
{
return VINF_SUCCESS;
}
{
return VINF_SUCCESS;
}
{
return VINF_SUCCESS;
}
/**
* The 'apimonitor' module description.
*/
{
/* pszName. */
/* pszDescription. */
"API monitor for host isolation detection",
/* pszDepends. */
NULL,
/* uPriority. */
0 /* Not used */,
/* pszUsage. */
" [--apimon-isln-response=<cmd>] [--apimon-isln-timeout=<ms>]\n"
" [--apimon-groups=<string>]\n",
/* pszOptions. */
"--apimon-isln-response Sets the isolation response (shutdown VM).\n"
"--apimon-isln-timeout Sets the isolation timeout in ms (none).\n"
"--apimon-groups Sets the VM groups for monitoring (none).\n",
/* methods. */
/* callbacks. */
};