AutostartDb-generic.cpp revision 395d92a7732aad3c0b9baecedfabba5113b84485
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsync * VirtualBox Main - Autostart implementation.
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsync * Copyright (C) 2009-2010 Oracle Corporation
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsync * available from http://www.virtualbox.org. This file is free software;
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsync * you can redistribute it and/or modify it under the terms of the GNU
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsync * General Public License (GPL) as published by the Free Software
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsync * Modifies the autostart database.
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsync * @returns VBox status code.
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsync * @param fAutostart Flag whether the autostart or autostop database is modified.
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsync * @param fAddVM Flag whether a VM is added or removed from the database.
dc077b46399b3ef751ebd282053f0e9725518e1evboxsyncint AutostartDb::autostartModifyDb(bool fAutostart, bool fAddVM)
dc077b46399b3ef751ebd282053f0e9725518e1evboxsync /* Check if the path is set. */
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsync uint64_t fOpen = RTFILE_O_DENY_ALL | RTFILE_O_READWRITE;
dc077b46399b3ef751ebd282053f0e9725518e1evboxsync m_pszAutostartDbPath, pszUser, fAutostart ? "start" : "stop");
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsync * Files with more than 16 bytes are rejected because they just contain
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsync * a number of the amount of VMs with autostart configured, so they
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsync * should be really really small. Anything else is bogus.
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsync /* Check if the file was just created. */
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsync rc = RTFileRead(hAutostartFile, abBuf, cbFile, NULL);
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsync rc = RTStrToUInt32Ex(abBuf, NULL, 10 /* uBase */, &cAutostartVms);
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsync /* Modify VM counter and write back. */
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsync cbBuf = RTStrPrintf(abBuf, sizeof(abBuf), "%u", cAutostartVms);
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsync rc = RTFileWriteAt(hAutostartFile, 0, abBuf, cbBuf, NULL);
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsync /* Just delete the file if there are no VMs left. */
dc077b46399b3ef751ebd282053f0e9725518e1evboxsyncint AutostartDb::setAutostartDbPath(const char *pszAutostartDbPathNew)
dc077b46399b3ef751ebd282053f0e9725518e1evboxsync pszAutostartDbPathTmp = RTStrDup(pszAutostartDbPathNew);
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsyncint AutostartDb::addAutostartVM(const char *pszVMId)
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsync rc = autostartModifyDb(true /* fAutostart */, true /* fAddVM */);
395d92a7732aad3c0b9baecedfabba5113b84485vboxsync#elif defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS)
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsyncint AutostartDb::removeAutostartVM(const char *pszVMId)
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsync rc = autostartModifyDb(true /* fAutostart */, false /* fAddVM */);
395d92a7732aad3c0b9baecedfabba5113b84485vboxsync#elif defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS)
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsync rc = autostartModifyDb(false /* fAutostart */, true /* fAddVM */);
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsyncint AutostartDb::removeAutostopVM(const char *pszVMId)
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsync rc = autostartModifyDb(false /* fAutostart */, false /* fAddVM */);