AutostartDb-generic.cpp revision 943753b96ed892c047b92ff6eb00bb100de8d6d2
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/** @todo: Make configurable through kmk/installer. */
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.
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsyncstatic int autostartModifyDb(bool fAutostart, bool fAddVM)
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsync uint64_t fOpen = RTFILE_O_DENY_ALL | RTFILE_O_READWRITE;
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsync AUTOSTART_DATABASE, 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. */
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsyncint AutostartDb::addAutostartVM(const char *pszVMId)
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsync rc = autostartModifyDb(true /* fAutostart */, true /* fAddVM */);
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsyncint AutostartDb::removeAutostartVM(const char *pszVMId)
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsync rc = autostartModifyDb(true /* fAutostart */, false /* fAddVM */);
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsync rc = autostartModifyDb(false /* fAutostart */, true /* fAddVM */);
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsyncint AutostartDb::removeAutostopVM(const char *pszVMId)
73bef7f249418907cb1dc8dce51319772a3dbeeevboxsync rc = autostartModifyDb(false /* fAutostart */, false /* fAddVM */);