/* $Id$ */
/** @file
* VBoxAutostart - VirtualBox Autostart service, stop machines during system shutdown.
*/
/*
* Copyright (C) 2012 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.
*/
#include <algorithm>
#include <list>
#include <string>
#include "VBoxAutostart.h"
using namespace com;
/**
* VM list entry.
*/
typedef struct AUTOSTOPVM
{
/** ID of the VM to start. */
/** Action to do with the VM. */
} AUTOSTOPVM;
{
do
{
bool fPaused = false;
{
bool fError = true;
if (rc == VBOX_E_INVALID_VM_STATE)
{
/* check if we are already paused */
/* the error code was lost by the previous instruction */
if (machineState != MachineState_Paused)
{
RTMsgError("Machine in invalid state %d -- %s\n",
}
else
{
fError = false;
fPaused = true;
}
}
if (fError)
break;
}
{
if (!fPaused)
break;
}
{
if (!fPaused)
}
} while (0);
return rc;
}
{
/*
* Build a list of all VMs we need to autostop first, apply the overrides
* from the configuration and start the VMs afterwards.
*/
{
/*
* Iterate through the collection and construct a list of machines
* we have to check.
*/
{
if (machines[i])
{
if (!fAccessible)
continue;
if (enmAutostopType != AutostopType_Disabled)
{
}
}
}
{
{
machine.asOutParam()));
/* Wait until the VM changes from a transient state back. */
while ( enmMachineState >= MachineState_FirstTransient
{
RTThreadSleep(1000);
}
/* Only power off running machines. */
if ( enmMachineState == MachineState_Running
{
/* open a session for the VM */
/* get the associated console */
switch ((*it).enmAutostopType)
{
case AutostopType_SaveState:
{
break;
}
case AutostopType_PowerOff:
{
break;
}
{
{
do
{
RTThreadSleep(1000);
} while (enmMachineState == MachineState_Running);
}
else
{
/* Use save state instead and log this to the console. */
autostartSvcLogWarning("The guest of VM \"%ls\" does not support ACPI shutdown or is currently paused, saving state...\n",
}
break;
}
default:
}
}
}
}
}
return rcExit;
}