/* $Id$ */
/** @file
* VBoxDTrace - Wrapper that selects the right dtrace implemetation and adds
* our library to the search path.
*/
/*
* Copyright (C) 2016 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* Development and Distribution License Version 1.0 (CDDL) only, as it
* comes in the "COPYING.CDDL" 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 *
*******************************************************************************/
#include <iprt/buildconfig.h>
#include <iprt/initterm.h>
#include "../../Main/include/ExtPackUtil.h"
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/** The VBoxDTrace extension pack name. */
/** The mangled version of VBOX_EXTPACK_VBOXDTRACE_NAME (also in Config.kmk). */
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/** The main function of VBoxDTrace.so/dylib/dll. */
{
/*
* Init IPRT.
*/
if (RT_FAILURE(rc))
return RTMsgInitFailure(rc);
/*
* Locate a native DTrace command binary.
*/
bool fIsNativeDTrace = false;
szDTraceCmd[0] = '\0';
#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS)
/*
* 1. Try native first on platforms where it's applicable.
*/
static const char * const s_apszNativeDTrace[] =
{
};
if (!RTEnvExist("VBOX_DTRACE_NO_NATIVE"))
if (RTFileExists(s_apszNativeDTrace[i]))
{
fIsNativeDTrace = true;
# ifdef RT_OS_LINUX
/** @todo Warn if the dtrace modules haven't been loaded or vboxdrv isn't
* compiled against them. */
# endif
break;
}
if (szDTraceCmd[0] == '\0')
#endif
{
/*
* 2. VBoxDTrace extension pack installed?
*
* Note! We cannot use the COM API here because this program is usually
* run thru sudo or directly as root, even if the target
* VirtualBox process is running as regular user. This is due to
* the privileges required to run dtrace scripts on a host.
*/
if (RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
if (RT_FAILURE(rc))
if (!RTFileExists(szDTraceCmd))
return RTMsgErrorExit(RTEXITCODE_FAILURE,
"Unable to find a DTrace implementation. VBoxDTrace Extension Pack installed?");
fIsNativeDTrace = false;
}
/*
* Construct a new command line that includes our libary.
*/
if (RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
if (RT_FAILURE(rc))
return RTMsgErrorExit(RTEXITCODE_FAILURE, "Error constructing dtrace library path for VBox: %Rrc", rc);
if (!papszArgs)
if (argc > 1)
{
}
for (int i = 1; i < argc; i++)
/*
* The native DTrace we execute as a sub-process and wait for.
*/
if (fIsNativeDTrace)
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
else
}
else
}
else
}
/*
* While the VBoxDTrace we load and call the main function of.
*/
else
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
else
rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "Error locating 'VBoxDTraceMain' in '%s': %Rrc", szDTraceCmd, rc);
}
else
rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "Error loading '%s': %Rrc (%s)", szDTraceCmd, rc, ErrInfo.szMsg);
}
return rcExit;
}