VBoxManageGuestCtrl.cpp revision 17c18db1ef58bb54fde8cf82a01c8faa74706029
c36d095531b5355dba93be3b9b862bac18148109vboxsync * VBoxManage - Implementation of guestcontrol command.
c36d095531b5355dba93be3b9b862bac18148109vboxsync * Copyright (C) 2010-2011 Oracle Corporation
afc71ee9d14313aac9881860b235a74d7c8a683evboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
afc71ee9d14313aac9881860b235a74d7c8a683evboxsync * available from http://www.virtualbox.org. This file is free software;
afc71ee9d14313aac9881860b235a74d7c8a683evboxsync * you can redistribute it and/or modify it under the terms of the GNU
afc71ee9d14313aac9881860b235a74d7c8a683evboxsync * General Public License (GPL) as published by the Free Software
afc71ee9d14313aac9881860b235a74d7c8a683evboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
866306ba031a2f258907507dd4abb3b84b6983e7vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
866306ba031a2f258907507dd4abb3b84b6983e7vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
866306ba031a2f258907507dd4abb3b84b6983e7vboxsync/*******************************************************************************
866306ba031a2f258907507dd4abb3b84b6983e7vboxsync* Header Files *
866306ba031a2f258907507dd4abb3b84b6983e7vboxsync*******************************************************************************/
using namespace com;
static volatile bool g_fGuestCtrlCanceled = false;
typedef struct DIRECTORYENTRY
char *pszSourcePath;
char *pszDestPath;
* Special exit codes for returning errors/information of a
enum EXITCODE_EXEC
enum GETOPTDEF_EXEC
enum OUTPUTTYPE
OUTPUTTYPE_UNDEFINED = 0,
#ifndef VBOX_ONLY_DOCS
static void ctrlSignalHandlerInstall()
#ifdef SIGBREAK
static void ctrlSignalHandlerUninstall()
#ifdef SIGBREAK
switch (enmStatus)
switch (enmStatus)
return rc;
int rc;
&& fCanceled)
return rc;
return VERR_NOT_FOUND;
return VERR_VM_INVALID_VM_STATE;
if (pArg->argc < 2) /* At least the command we want to execute in the guest should be present :-). */
int ch;
bool fOutputBinary = false;
bool fWaitForExit = false;
bool fWaitForStdOut = false;
bool fWaitForStdErr = false;
bool fVerbose = false;
switch (ch)
case GETOPTDEF_EXEC_DOS2UNIX:
char **papszArg;
int cArgs;
for (int j = 0; j < cArgs; j++)
case GETOPTDEF_EXEC_UNIX2DOS:
fVerbose = true;
fWaitForExit = true;
fWaitForExit = true;
fWaitForStdOut = true;
fWaitForExit = true;
fWaitForStdErr = true;
case VINF_GETOPT_NOT_OPTION:
if (fVerbose)
if (cMsTimeout == 0)
int rcProc;
&uPID,
if (fVerbose)
if (fWaitForExit)
if (fVerbose)
bool fCanceledAlready = false;
if (fCancelable)
int cMilliesSleep = 0;
if ( fWaitForStdOut
|| fWaitForStdErr)
cbOutputData = 0;
if (cbOutputData > 0)
if (cbOutputData <= 0)
if (fCompleted)
g_fGuestCtrlCanceled = false;
&& fCanceled)
if ( cMsTimeout
if (fCancelable)
if (fCanceled)
if (fVerbose)
else if ( fCompleted
RTPrintf("Exit code=%u (Status=%u [%s], Flags=%u)\n", uRetExitCode, retStatus, ctrlExecProcessStatusToText(retStatus), uRetFlags);
if (fVerbose)
return RTEXITCODE_FAILURE;
return rcProc;
return VERR_NO_MEMORY;
if (pszFileSource)
if (pszFileDest)
return VINF_SUCCESS;
while (pNode)
if (fLast)
case RTDIRENTRYTYPE_DIRECTORY:
if (pszSubDir)
if (pszNewSub)
case RTDIRENTRYTYPE_SYMLINK:
case RTDIRENTRYTYPE_FILE:
if ( !pszFilter
if (pszFileSource)
if (pszFileDest)
return rc;
if (pszSourceAbs)
if (pszDestAbs)
if ( pszSourceAbsRoot
&& pszDestAbs)
if (pszFilter)
if (pszDestAbs)
if (pszSourceAbsRoot)
return rc;
static int ctrlCopyFileToGuest(IGuest *pGuest, bool fVerbose, const char *pszSource, const char *pszDest,
return vrc;
{ "--follow", 'F', RTGETOPT_REQ_NOTHING }, /**< @todo r=bird: This isn't a GNU cp option. This is instead spread over several options. */
{ "--password", 'p', RTGETOPT_REQ_STRING }, /**< @todo r=bird: Just drop these short options since (BSD, GNU, ++) cp uses '-p' to indicate that ownership, timestamp and other stuff should be preserved. Other file commands probably use '-p' as well. */
{ "--recursive", 'R', RTGETOPT_REQ_NOTHING }, /**< @todo r=bird: Most cp implementations treats '-r' as an alias for '-R'. */
{ "--username", 'u', RTGETOPT_REQ_STRING }, /**< @todo r=bird: Just drop these short options since GNU cp uses '-u' to indicate update-only (as does 4nt). Other file commands probably uses '-u' as well. */
int ch;
bool fVerbose = false;
bool fCopyRecursive = false;
bool fDryRun = false;
switch (ch)
fDryRun = true;
fVerbose = true;
case VINF_GETOPT_NOT_OPTION:
switch (idxNonOption)
/* @todo r=bird: VBoxManage guestcontrol execute <VMName> copyto hostfile.1 hostfile.2 hostfile.3 guestdir/
return errorSyntax(USAGE_GUESTCONTROL, "Too many parameters specified, only source and destination allowed!");
idxNonOption++;
if (fVerbose)
if (fDryRun)
switch (vrc)
case VERR_NOT_FOUND:
case VERR_FILE_NOT_FOUND:
if (fVerbose)
if (fCopyRecursive)
if (!fDryRun)
if (fVerbose)
if (!fDryRun)
iObject++;
int ch;
bool fVerbose = false;
switch (ch)
fVerbose = true;
case VINF_GETOPT_NOT_OPTION:
&listDirs);
cDirs++;
if (fVerbose)
return rcExit;
bool fVerbose = false;
int ch;
switch (ch)
fVerbose = true;
if (fVerbose)
#ifdef DEBUG_andy
if (fVerbose)
else if (fVerbose)
int rcExit;
return rcExit;
return RTEXITCODE_FAILURE;