ClientToken.cpp revision 5637660ed0c2a4a3a114e6d2d4c8294f2fd5f18f
/** @file
*
* VirtualBox API client crash token handling
*/
/*
* Copyright (C) 2004-2013 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 <iprt/semaphore.h>
# include <errno.h>
#endif
#include <vector>
#include "VirtualBoxBase.h"
#include "AutoCaller.h"
#include "ClientToken.h"
#include "MachineImpl.h"
{
}
{
#if defined(RT_OS_WINDOWS)
if (mClientToken)
if (mClientToken != NULLHANDLE)
#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
if (mClientToken >= 0)
# ifdef VBOX_WITH_NEW_SYS_V_KEYGEN
mClientTokenId = "0";
# endif /* VBOX_WITH_NEW_SYS_V_KEYGEN */
#else
# error "Port me!"
#endif
}
{
#if defined(RT_OS_WINDOWS)
("Cannot create token '%s', err=%d",
("Cannot create token '%s', arc=%ld",
#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
# ifdef VBOX_WITH_NEW_SYS_V_KEYGEN
/** @todo Check that this still works correctly. */
# else
# endif
mClientToken = -1;
mClientTokenId = "0";
{
{
mClientToken = sem;
if (sem >= 0)
break;
}
}
# else /* !VBOX_WITH_NEW_SYS_V_KEYGEN */
char *pszSemName = NULL;
# endif /* !VBOX_WITH_NEW_SYS_V_KEYGEN */
{
tr("Cannot create IPC semaphore. Most likely your host kernel lacks "
"support for SysV IPC. Check the host kernel configuration for "
"CONFIG_SYSVIPC=y"));
return;
}
/* ENOSPC can also be the result of VBoxSVC crashes without properly freeing
* the token */
{
#ifdef RT_OS_LINUX
tr("Cannot create IPC semaphore because the system limit for the "
"maximum number of semaphore sets (SEMMNI), or the system wide "
"maximum number of semaphores (SEMMNS) would be exceeded. The "
"current set of SysV IPC semaphores can be determined from "
#else
tr("Cannot create IPC semaphore because the system-imposed limit "
"on the maximum number of allowed semaphores or semaphore "
"identifiers system-wide would be exceeded"));
#endif
return;
}
/* set the initial value to 1 */
if (rv != 0)
{
}
#else
# error "Port me!"
#endif
}
{
return mClientToken != CTTOKENARG;
}
{
}
{
return mClientToken;
}
{
bool terminated = false;
#if defined(RT_OS_WINDOWS)
/* release the token */
terminated = true;
/* release the token */
terminated = true;
#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
if (val > 0)
{
/* the semaphore is signaled, meaning the session is terminated */
terminated = true;
}
#else
# error "Port me!"
#endif
return terminated;
}
/* vi: set tabstop=4 shiftwidth=4 expandtab: */