VBoxManage.cpp revision 0df8f2889273aee65079da0f4b5727a4ac6d3e7b
/* $Id$ */
/** @file
* VBoxManage - VirtualBox's command-line interface.
*/
/*
* Copyright (C) 2006-2015 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 <iprt/buildconfig.h>
#include <iprt/initterm.h>
#include <signal.h>
#include "VBoxManage.h"
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/*extern*/ bool g_fDetailedProgress = false;
#ifndef VBOX_ONLY_DOCS
/** Set by the signal handler. */
static volatile bool g_fCanceled = false;
/**
* Signal handler that sets g_fCanceled.
*
* This can be executed on any thread in the process, on Windows it may even be
* a thread dedicated to delivering this signal. Do not doing anything
* unnecessary here.
*/
static void showProgressSignalHandler(int iSignal)
{
ASMAtomicWriteBool(&g_fCanceled, true);
}
/**
* Print out progress on the console.
*
* This runs the main event queue every now and then to prevent piling up
* unhandled things (which doesn't cause real problems, just makes things
* react a little slower than in the ideal case).
*/
{
using namespace com;
ULONG ulCurrentPercent = 0;
ULONG ulLastPercent = 0;
{
return hrc;
}
/*
* Note: Outputting the progress info to stderr (g_pStdErr) is intentional
* to not get intermixed with other (raw) stdout data which might get
* written in the meanwhile.
*/
if (!g_fDetailedProgress)
{
}
/* setup signal handling if cancelable */
bool fCanceledAlready = false;
fCancelable = FALSE;
if (fCancelable)
{
#ifdef SIGBREAK
#endif
}
{
if (g_fDetailedProgress)
{
break;
break;
if (ulLastOperation != ulOperation)
{
break;
}
if ( ulCurrentPercent != ulLastPercent
)
{
RTStrmPrintf(g_pStdErr, "(%u/%u) %ls %02u%% => %02u%% (%d s remaining)\n", ulOperation + 1, cOperations,
}
}
else
{
/* did we cross a 10% mark? */
{
/* make sure to also print out missed steps */
for (ULONG curVal = (ulLastPercent / 10) * 10 + 10; curVal <= (ulCurrentPercent / 10) * 10; curVal += 10)
{
if (curVal < 100)
{
}
}
}
}
if (fCompleted)
break;
/* process async cancelation */
if (g_fCanceled && !fCanceledAlready)
{
fCanceledAlready = true;
else
g_fCanceled = false;
}
/* make sure the loop is not too tight */
}
/* undo signal handling */
if (fCancelable)
{
#ifdef SIGBREAK
#endif
}
/* complete the line. */
{
else if (g_fCanceled)
else
{
if (!g_fDetailedProgress)
}
}
else
{
if (!g_fDetailedProgress)
}
return hrc;
}
#ifdef RT_OS_WINDOWS
// Required for ATL
static CComModule _Module;
#endif
#endif /* !VBOX_ONLY_DOCS */
#ifndef VBOX_ONLY_DOCS
{
char szPasswd[512];
int vrc = VINF_SUCCESS;
if (!fStdIn)
else
if (RT_SUCCESS(vrc))
{
if (RT_SUCCESS(vrc))
{
rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "Provided password in file '%s' is too long", pszFilename);
else
{
unsigned i;
;
szPasswd[i] = '\0';
}
}
else
rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "Cannot read password from file '%s': %Rrc", pszFilename, vrc);
if (!fStdIn)
}
else
rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "Cannot open password file '%s' (%Rrc)", pszFilename, vrc);
return rcExit;
}
{
if (rcExit == RTEXITCODE_SUCCESS)
{
int rc;
}
return rcExit;
}
{
char aszPwdInput[_1K] = { 0 };
if (RT_SUCCESS(vrc))
{
bool fEchoOld = false;
if (RT_SUCCESS(vrc))
{
if (RT_SUCCESS(vrc))
{
if (RT_SUCCESS(vrc))
*pPassword = aszPwdInput;
else
}
else
rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to disable echoing typed characters (%Rrc)", vrc);
}
else
}
else
return rcExit;
}
#endif
{
/*
* Before we do anything, init the runtime without loading
* the support driver.
*/
/*
* Parse the global options
*/
bool fShowLogo = false;
bool fShowHelp = false;
int iCmd = 1;
int iCmdArg;
const char *g_pszSettingsPw = NULL;
const char *g_pszSettingsPwFile = NULL;
{
{
if (i >= argc - 1)
{
return 0;
}
fShowLogo = true;
fShowHelp = true;
iCmd++;
continue;
}
{
/* Print version number, and do nothing else. */
return 0;
}
{
/* Special option to dump really all commands,
* even the ones not understood on this platform. */
return 0;
}
{
/* suppress the logo */
fShowLogo = false;
iCmd++;
}
{
/* detailed progress report */
g_fDetailedProgress = true;
iCmd++;
}
{
if (i >= argc-1)
return RTMsgErrorExit(RTEXITCODE_FAILURE,
"Password expected");
/* password for certain settings */
iCmd += 2;
}
{
if (i >= argc-1)
return RTMsgErrorExit(RTEXITCODE_FAILURE,
"No password file specified");
iCmd += 2;
}
else
break;
}
if (fShowLogo)
#ifndef VBOX_ONLY_DOCS
/*
* Initialize COM.
*/
using namespace com;
# ifdef VBOX_WITH_XPCOM
if (hrc == NS_ERROR_FILE_ACCESS_DENIED)
{
return RTMsgErrorExit(RTEXITCODE_FAILURE,
"Failed to initialize COM because the global settings directory '%s' is not accessible!", szHome);
}
# endif
do
{
///////////////////////////////////////////////////////////////////////////
// scopes all the stuff till shutdown
/*
* convertfromraw: does not need a VirtualBox instantiation.
*/
{
break;
}
/*
* Get the remote VirtualBox object and create a local session object.
*/
RTMsgError("Failed to create the VirtualBox object!");
else
{
RTMsgError("Failed to create a session object!");
}
{
{
RTMsgError("Most likely, the VirtualBox COM server is not running or failed to start.");
}
else
break;
}
/*
* All registered command handlers
*/
static const struct
{
const char *command;
int (*handler)(HandlerArg *a);
} s_commandHandlers[] =
{
{ "internalcommands", 0, handleInternalCommands },
#ifdef VBOX_WITH_GUEST_PROPS
#endif
#ifdef VBOX_WITH_GUEST_CONTROL
#endif
#ifdef VBOX_WITH_NETFLT
#endif
#ifdef VBOX_WITH_NAT_SERVICE
#endif
};
if (g_pszSettingsPw)
{
int rc;
{
break;
}
}
else if (g_pszSettingsPwFile)
{
if (rcExit != RTEXITCODE_SUCCESS)
break;
}
int commandIndex;
{
{
if ( fShowHelp
{
}
else
rcExit = (RTEXITCODE)s_commandHandlers[commandIndex].handler(&handlerArg); /** @todo Change to return RTEXITCODE. */
break;
}
}
{
/* Help topics. */
{
RTPrintf("commands:\n");
if ( i == 0 /* skip backwards compatibility entries */
}
else
}
/* Although all handlers should always close the session if they open it,
* we do it here just in case if some of the handlers contains a bug --
* leaving the direct session not closed will turn the machine state to
* Aborted which may have unwanted side effects like killing the saved
* state file (if the machine was in the Saved state before). */
session->UnlockMachine();
// end "all-stuff" scope
///////////////////////////////////////////////////////////////////////////
} while (0);
return rcExit;
#else /* VBOX_ONLY_DOCS */
return RTEXITCODE_SUCCESS;
#endif /* VBOX_ONLY_DOCS */
}