VBoxManageGuestCtrl.cpp revision 9e3df0b3642efd7ec296839d42217e8e0c9cf4d2
/* $Id$ */
/** @file
* VBoxManage - The 'guestcontrol' command.
*/
/*
* Copyright (C) 2010 Sun Microsystems, Inc.
*
* 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.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "VBoxManage.h"
#ifdef USE_XPCOM_QUEUE
# include <errno.h>
#endif
#ifdef RT_OS_DARWIN
# include <CoreFoundation/CFRunLoop.h>
#endif
using namespace com;
/**
* IVirtualBoxCallback implementation for handling the GuestControlCallback in
* relation to the "guestcontrol * wait" command.
*/
/** @todo */
void usageGuestControl(void)
{
RTPrintf("VBoxManage guestcontrol execute <vmname>|<uuid>\n"
" <path to program> [--arguments \"<arguments>\"] [--environment \"<NAME=VALUE NAME=VALUE>\"]\n"
" [--flags <flags>] [--timeout <msec>] [--username <name> [--password <password>]]\n"
" [--verbose] [--wait-for exit,stdout,stderr||]\n"
"\n");
}
static int handleExecProgram(HandlerArg *a)
{
/*
* Check the syntax. We can deduce the correct syntax from the number of
* arguments.
*/
uint32_t uTimeoutMS = 0;
bool waitForExit = false;
bool waitForStdOut = false;
bool waitForStdErr = false;
bool verbose = false;
/* Iterate through all possible commands (if available). */
bool usageOK = true;
{
{
if (i + 1 >= a->argc)
usageOK = false;
else
{
char **papszArg;
int cArgs;
if (RT_SUCCESS(vrc))
{
for (int j = 0; j < cArgs; j++)
}
++i;
}
}
{
if (i + 1 >= a->argc)
usageOK = false;
else
{
char **papszArg;
int cArgs;
if (RT_SUCCESS(vrc))
{
for (int j = 0; j < cArgs; j++)
}
++i;
}
}
{
if ( i + 1 >= a->argc
usageOK = false;
else
++i;
}
{
if (i + 1 >= a->argc)
usageOK = false;
else
{
++i;
}
}
{
if (i + 1 >= a->argc)
usageOK = false;
else
{
++i;
}
}
{
if ( i + 1 >= a->argc
usageOK = false;
else
++i;
}
{
if (i + 1 >= a->argc)
usageOK = false;
else
{
waitForExit = true;
{
waitForExit = true;
waitForStdOut = true;
}
{
waitForExit = true;
waitForStdErr = true;
}
else
usageOK = false;
++i;
}
}
{
verbose = true;
}
/** @todo Add fancy piping stuff here. */
else
{
return errorSyntax(USAGE_GUESTCONTROL,
}
}
if (!usageOK)
/* If a password was specified, check if we also got a user name. */
if ( !Utf8Password.isEmpty()
&& Utf8UserName.isEmpty())
{
return errorSyntax(USAGE_GUESTCONTROL,
"No user name for password specified!");
}
/* lookup VM. */
/* assume it's an UUID */
{
/* must be a name */
}
if (machine)
{
do
{
/* open an existing session for VM - so the VM has to be running */
/* get the mutable session machine */
/* get the associated console */
if (verbose)
{
if (uTimeoutMS == 0)
RTPrintf("Waiting for guest to start process ...\n");
else
}
/* Get current time stamp to later calculate rest of timeout left. */
/* Execute the process. */
if (waitForExit)
{
/* Calculate timeout value left after process has been started. */
if (uTimeoutMS)
if (verbose)
{
if (uTimeoutMS == 0)
RTPrintf("Waiting for process to exit ...\n");
else
}
/* Wait for process to exit ... */
{
if (uTimeoutMS)
RTPrintf("Process '%s' (PID: %u) did not end within %ums! Wait aborted.\n",
break;
}
else
{
{
RTPrintf("Process error details:\n");
RTPrintf("\n");
}
else
{
if (verbose)
RTPrintf("Process completed.\n");
}
/* Print output if wanted. */
if ( waitForStdOut
|| waitForStdErr)
{
while (true)
{
if (cbOutputData == 0)
break;
/* aOutputData has a platform dependent line ending, standardize on
s++, d++)
{
if (*s == '\r')
{
/* skip over CR, adjust destination */
d--;
}
else if (s != d)
*d = *s;
}
}
}
}
}
} while (0);
}
}
/**
* Access the guest control store.
*
* @returns 0 on success, 1 on failure
* @note see the command line API description for parameters
*/
int handleGuestControl(HandlerArg *a)
{
HandlerArg arg = *a;
if (a->argc == 0)
/* switch (cmd) */
return handleExecProgram(&arg);
/* default: */
}