VBoxManage.cpp revision eaa687a9ede02b3b161a4595f7e42590a2e1b932
/* $Id$ */
/** @file
* VBoxManage - VirtualBox's command-line interface.
*/
/*
* Copyright (C) 2006-2010 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
*/
{
using namespace com;
ULONG ulLastPercent = 0;
if (!g_fDetailedProgress)
{
}
/* setup signal handling if cancelable */
bool fCanceledAlready = false;
fCancelable = FALSE;
if (fCancelable)
{
#ifdef SIGBREAK
#endif
}
{
if (g_fDetailedProgress)
{
if (ulLastOperation != ulOperation)
{
}
if ( ulCurrentPercent != ulLastPercent
)
{
RTStrmPrintf(g_pStdErr, "(%ld/%ld) %ls %ld%% => %ld%% (%d s remaining)\n", ulOperation + 1, cOperations, bstrOperationDescription.raw(), ulCurrentOperationPercent, ulCurrentPercent, lSecsRem);
}
}
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
}
else
return iRc;
}
#endif /* !VBOX_ONLY_DOCS */
{
/*
* Before we do anything, init the runtime without loading
* the support driver.
*/
RTR3Init();
/*
* Parse the global options
*/
bool fShowLogo = false;
bool fShowHelp = false;
int iCmd = 1;
int iCmdArg;
{
{
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++;
}
else
{
break;
}
}
if (fShowLogo)
#ifndef VBOX_ONLY_DOCS
/*
* Initialize COM.
*/
using namespace com;
/*
* The input is ASSUMED to be in the current process codeset (NT guarantees
* ACP, unixy systems doesn't guarantee anything). This loop converts all
* the argv[*] strings to UTF-8, which is a tad ugly but who cares.
* (As a rule all strings in VirtualBox are UTF-8.)
*/
{
char *pszConverted;
if (RT_SUCCESS(rc))
argv[i] = pszConverted;
else
/* Conversion was not possible,probably due to invalid characters.
* Keep in mind that we do RTStrFree on the whole array below. */
}
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
};
int commandIndex;
{
{
if ( fShowHelp
{
}
else
rcExit = (RTEXITCODE)s_commandHandlers[commandIndex].handler(&handlerArg); /** @todo Change to return RTEXITCODE. */
break;
}
}
/* 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);
/*
* Free converted argument vector
*/
{
}
return rcExit;
#else /* VBOX_ONLY_DOCS */
return RTEXITCODE_SUCCESS;
#endif /* VBOX_ONLY_DOCS */
}