VBoxManage.cpp revision 824ae3158a8b8f8233fec3f5a12c81f139933698
/* $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();
bool fShowLogo = false;
bool fShowHelp = false;
int iCmd = 1;
int iCmdArg;
/* global options */
{
{
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)
#ifdef VBOX_ONLY_DOCS
int rc = 0;
#else /* !VBOX_ONLY_DOCS */
using namespace com;
{
RTMsgError("Failed to initialize COM!");
return rc;
}
/*
* The input is in the host OS'es codepage (NT guarantees ACP).
* For VBox we use UTF-8 and convert to UCS-2 when calling (XP)COM APIs.
* For simplicity, just convert the argv[] array here.
*/
{
char *converted;
if (converted)
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;
}
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
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);
#endif /* !VBOX_ONLY_DOCS */
/*
* Free converted argument vector
*/
return rc != 0;
}