VBoxServiceVMInfo.cpp revision c1a200b0143781501feaf6309ab831992316ef7e
/* $Id$ */
/** @file
* VBoxService - Virtual Machine Information for the Host.
*/
/*
* Copyright (C) 2009-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.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#ifdef RT_OS_WINDOWS
# ifdef TARGET_NT4 /* HACK ALERT! PMIB_IPSTATS undefined if 0x0400 with newer SDKs. */
# define _WIN32_WINNT 0x0500
# endif
# include <winsock2.h>
# include <iphlpapi.h>
# include <ws2tcpip.h>
# include <windows.h>
# include <Ntsecapi.h>
#else
# define __STDC_LIMIT_MACROS
# include <errno.h>
# include <pwd.h> /* getpwuid */
# include <unistd.h>
# include <utmpx.h> /* @todo FreeBSD 9 should have this. */
# endif
# ifdef RT_OS_SOLARIS
# endif
# if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
# include <ifaddrs.h> /* getifaddrs, freeifaddrs */
# include <netdb.h> /* getnameinfo */
# endif
# ifdef VBOX_WITH_DBUS
# endif
#endif
#include <iprt/semaphore.h>
#include <VBox/VBoxGuestLib.h>
#include "VBoxServiceInternal.h"
#include "VBoxServiceUtils.h"
#include "VBoxServicePropCache.h"
/** Structure containing information about a location awarness
* client provided by the host. */
/** @todo Move this (and functions) into VbglR3. */
typedef struct VBOXSERVICELACLIENTINFO
{
char *pszName;
char *pszLocation;
char *pszDomain;
bool fAttached;
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/** The vminfo interval (milliseconds). */
static uint32_t g_cMsVMInfoInterval = 0;
/** The semaphore we're blocking on. */
/** The guest property service client ID. */
static uint32_t g_uVMInfoGuestPropSvcClientID = 0;
/** Number of currently logged in users in OS. */
static uint32_t g_cVMInfoLoggedInUsers = 0;
/** The guest property cache. */
static const char *g_pszPropCacheValLoggedInUsersList = "/VirtualBox/GuestInfo/OS/LoggedInUsersList";
static const char *g_pszPropCacheValLoggedInUsers = "/VirtualBox/GuestInfo/OS/LoggedInUsers";
static const char *g_pszPropCacheValNoLoggedInUsers = "/VirtualBox/GuestInfo/OS/NoLoggedInUsers";
static const char *g_pszPropCacheValNetCount = "/VirtualBox/GuestInfo/Net/Count";
/** A guest user's guest property root key. */
static const char *g_pszPropCacheValUser = "/VirtualBox/GuestInfo/User/";
/** The VM session ID. Changes whenever the VM is restored or reset. */
static uint64_t g_idVMInfoSession;
/** The last attached locartion awareness (LA) client timestamp. */
static uint64_t g_LAClientAttachedTS = 0;
/** The current LA client info. */
/** User idle threshold. This specifies the minimum time a user is considered
* being idle and then will be reported to the host. Default is 5s. */
/*******************************************************************************
* Defines *
*******************************************************************************/
static const char *g_pszLAActiveClient = "/VirtualBox/HostInfo/VRDP/ActiveClient";
#ifdef VBOX_WITH_DBUS
/** ConsoleKit defines (taken from 0.4.5). */
#define CK_NAME "org.freedesktop.ConsoleKit"
#define CK_PATH "/org/freedesktop/ConsoleKit"
#define CK_INTERFACE "org.freedesktop.ConsoleKit"
#define CK_MANAGER_PATH "/org/freedesktop/ConsoleKit/Manager"
#define CK_MANAGER_INTERFACE "org.freedesktop.ConsoleKit.Manager"
#define CK_SEAT_INTERFACE "org.freedesktop.ConsoleKit.Seat"
#define CK_SESSION_INTERFACE "org.freedesktop.ConsoleKit.Session"
#endif
/**
* Signals the event so that a re-enumeration of VM-specific
* information (like logged in users) can happen.
*
* @return IPRT status code.
*/
int VBoxServiceVMInfoSignal(void)
{
/* Trigger a re-enumeration of all logged-in users by unblocking
* the multi event semaphore of the VMInfo thread. */
if (g_hVMInfoEvent)
return RTSemEventMultiSignal(g_hVMInfoEvent);
return VINF_SUCCESS;
}
/** @copydoc VBOXSERVICE::pfnPreInit */
static DECLCALLBACK(int) VBoxServiceVMInfoPreInit(void)
{
return VINF_SUCCESS;
}
/** @copydoc VBOXSERVICE::pfnOption */
static DECLCALLBACK(int) VBoxServiceVMInfoOption(const char **ppszShort, int argc, char **argv, int *pi)
{
/** @todo Use RTGetOpt here. */
int rc = -1;
if (ppszShort)
/* no short options */;
return rc;
}
/** @copydoc VBOXSERVICE::pfnInit */
static DECLCALLBACK(int) VBoxServiceVMInfoInit(void)
{
/*
* If not specified, find the right interval default.
* Then create the event sem to block on.
*/
if (!g_cMsVMInfoInterval)
if (!g_cMsVMInfoInterval)
{
/* Set it to 5s by default for location awareness checks. */
}
/* The status code is ignored as this information is not available with VBox < 3.2.10. */
/* Initialize the LA client object. */
if (RT_SUCCESS(rc))
else
{
/* If the service was not found, we disable this service without
causing VBoxService to fail. */
{
VBoxServiceVerbose(0, "Guest property service is not available, disabling the service\n");
}
else
}
if (RT_SUCCESS(rc))
{
/*
* Declare some guest properties with flags and reset values.
*/
VBOXSERVICEPROPCACHEFLAG_TEMPORARY | VBOXSERVICEPROPCACHEFLAG_TRANSIENT, NULL /* Delete on exit */);
if (RT_FAILURE(rc2))
VBoxServiceError("Failed to init property cache value \"%s\", rc=%Rrc\n", g_pszPropCacheValLoggedInUsersList, rc2);
if (RT_FAILURE(rc2))
VBoxServiceError("Failed to init property cache value \"%s\", rc=%Rrc\n", g_pszPropCacheValLoggedInUsers, rc2);
if (RT_FAILURE(rc2))
VBoxServiceError("Failed to init property cache value \"%s\", rc=%Rrc\n", g_pszPropCacheValNoLoggedInUsers, rc2);
VBOXSERVICEPROPCACHEFLAG_TEMPORARY | VBOXSERVICEPROPCACHEFLAG_ALWAYS_UPDATE, NULL /* Delete on exit */);
if (RT_FAILURE(rc2))
VBoxServiceError("Failed to init property cache value \"%s\", rc=%Rrc\n", g_pszPropCacheValNetCount, rc2);
/*
* Get configuration guest properties from the host.
* Note: All properties should have sensible defaults in case the lookup here fails.
*/
char *pszValue;
rc2 = VBoxServiceReadHostProp(g_uVMInfoGuestPropSvcClientID, "/VirtualBox/GuestAdd/VBoxService/--vminfo-user-idle-threshold", true /* Read only */,
if (RT_SUCCESS(rc2))
{
}
}
return rc;
}
/**
* Retrieves a specifiy client LA property.
*
* @return IPRT status code.
* @param uClientID LA client ID to retrieve property for.
* @param pszProperty Property (without path) to retrieve.
* @param ppszValue Where to store value of property.
* @param puTimestamp Timestamp of property to retrieve. Optional.
*/
{
int rc;
char pszClientPath[255];
{
}
else
rc = VERR_NO_MEMORY;
return rc;
}
/**
* Retrieves LA client information. On success the returned structure will have allocated
* objects which need to be free'd with vboxServiceFreeLAClientInfo.
*
* @return IPRT status code.
* @param uClientID Client ID to retrieve information for.
* @param pClient Pointer where to store the client information.
*/
{
NULL /* Timestamp */);
if (RT_SUCCESS(rc))
{
char *pszAttach;
&pClient->uAttachedTS);
if (RT_SUCCESS(rc))
{
}
}
if (RT_SUCCESS(rc))
NULL /* Timestamp */);
if (RT_SUCCESS(rc))
NULL /* Timestamp */);
if (RT_SUCCESS(rc))
return rc;
}
/**
* Frees all allocated LA client information of a structure.
*
* @param pClient Pointer to client information structure to free.
*/
{
if (pClient)
{
{
}
if (pClient->pszLocation)
{
}
{
}
}
}
/**
* Updates a per-guest user guest property inside the given property cache.
*
* @return IPRT status code.
* @param pCache Pointer to guest property cache to update user in.
* @param pszUser Name of guest user to update.
* @param pszDomain Domain of guest user to update. Optional.
* @param pszKey Key name of guest property to update.
* @param pszValueFormat Guest property value to set. Pass NULL for deleting
* the property.
*/
int vboxServiceUserUpdateF(PVBOXSERVICEVEPROPCACHE pCache, const char *pszUser, const char *pszDomain,
const char *pszKey, const char *pszValueFormat, ...)
{
/* pszDomain is optional. */
/* pszValueFormat is optional. */
int rc = VINF_SUCCESS;
char *pszName;
if (pszDomain)
rc = VERR_NO_MEMORY;
else
rc = VERR_NO_MEMORY;
if ( RT_SUCCESS(rc)
&& pszValueFormat)
{
rc = VERR_NO_MEMORY;
if ( RT_SUCCESS(rc)
&& !pszValue)
}
if (RT_SUCCESS(rc))
{
/** @todo Combine updating flags w/ updating the actual value. */
NULL /* Delete on exit */);
}
return rc;
}
/**
* Writes the properties that won't change while the service is running.
*
* Errors are ignored.
*/
static void vboxserviceVMInfoWriteFixedProperties(void)
{
/*
* First get OS information that won't change.
*/
char szInfo[256];
/*
* Retrieve version information about Guest Additions and installed files (components).
*/
char *pszAddVer;
char *pszAddVerExt;
char *pszAddRev;
if (RT_SUCCESS(rc))
{
}
#ifdef RT_OS_WINDOWS
/*
* Do windows specific properties.
*/
char *pszInstDir;
if (RT_SUCCESS(rc))
#endif
}
/*
* Simple wrapper to work around compiler-specific va_list madness.
*/
int first_arg_type,
...)
{
first_arg_type, va);
return ret;
}
#endif
/**
* Provide information about active users.
*/
static int vboxserviceVMInfoWriteUsers(void)
{
int rc = VINF_SUCCESS;
char *pszUserList = NULL;
uint32_t cUsersInList = 0;
#ifdef RT_OS_WINDOWS
# ifndef TARGET_NT4
&pszUserList, &cUsersInList);
# else
# endif
#elif defined(RT_OS_FREEBSD)
/** @todo FreeBSD: Port logged on user info retrieval.
* However, FreeBSD 9 supports utmpx, so we could use the code
* block below (?). */
#elif defined(RT_OS_HAIKU)
/** @todo Haiku: Port logged on user info retrieval. */
#else
setutxent();
/* Allocate a first array to hold 32 users max. */
if (papszUsers == NULL)
rc = VERR_NO_MEMORY;
/* Process all entries in the utmp file.
* Note: This only handles */
&& RT_SUCCESS(rc))
{
#ifdef RT_OS_DARWIN /* No ut_user->ut_session on Darwin */
#else
#endif
if (cUsersInList > cListSize)
{
cListSize += 32;
papszUsers = (char **)pvNew;
}
/* Make sure we don't add user names which are not
* part of type USER_PROCES. */
{
bool fFound = false;
if (!fFound)
{
if (RT_FAILURE(rc))
break;
cUsersInList++;
}
}
}
#ifdef VBOX_WITH_DBUS
# if defined(RT_OS_LINUX) /* Not yet for Solaris/FreeBSB. */
int rc2 = RTDBusLoadLib();
if (RT_SUCCESS(rc2))
{
/* Handle desktop sessions using ConsoleKit. */
}
if ( pConnection
&& !dbus_error_is_set(&dbErr))
{
/* Get all available sessions. */
"org.freedesktop.ConsoleKit.Manager",
"GetSessions");
if ( pMsgSessions
{
&dbErr);
if ( pReplySessions
&& !dbus_error_is_set(&dbErr))
{
char **ppszSessions; int cSessions;
DBUS_TYPE_INVALID /* Termination */))
{
char **ppszCurSession = ppszSessions;
for (ppszCurSession;
{
/* Only respect active sessions .*/
bool fActive = false;
"org.freedesktop.ConsoleKit.Session",
"IsActive");
if ( pMsgSessionActive
{
&dbErr);
if ( pReplySessionActive
&& !dbus_error_is_set(&dbErr))
{
{
/* Get uid from message. */
int val;
}
if (pReplySessionActive)
}
if (pMsgSessionActive)
}
/* *ppszCurSession now contains the object path
* (e.g. "/org/freedesktop/ConsoleKit/Session1"). */
"org.freedesktop.ConsoleKit.Session",
"GetUnixUser");
if ( fActive
&& pMsgUnixUser
{
&dbErr);
if ( pReplyUnixUser
&& !dbus_error_is_set(&dbErr))
{
{
/* Get uid from message. */
/** @todo Add support for getting UID_MIN (/etc/login.defs on
* Debian). */
/* Look up user name (realname) from uid. */
setpwent();
if ( ppwEntry
{
bool fFound = false;
if (!fFound)
{
if (RT_FAILURE(rc))
break;
cUsersInList++;
}
}
else
}
else
AssertMsgFailed(("ConsoleKit: GetUnixUser returned a wrong argument type\n"));
}
if (pReplyUnixUser)
}
else
VBoxServiceError("ConsoleKit: unable to retrieve user for session '%s' (msg type=%d): %s",
if (pMsgUnixUser)
}
}
else
{
VBoxServiceError("ConsoleKit: unable to retrieve session parameters (msg type=%d): %s",
}
}
if (pMsgSessions)
{
pMsgSessions = NULL;
}
}
else
{
static int s_iBitchedAboutConsoleKit = 0;
if (s_iBitchedAboutConsoleKit++ < 3)
VBoxServiceError("Unable to invoke ConsoleKit (%d/3) -- maybe not installed / used? Error: %s\n",
}
if (pMsgSessions)
}
else
{
static int s_iBitchedAboutDBus = 0;
if (s_iBitchedAboutDBus++ < 3)
}
if ( pConnection
&& dbus_error_is_set(&dbErr))
# endif /* RT_OS_LINUX */
#endif /* VBOX_WITH_DBUS */
/* Calc the string length. */
size_t cchUserList = 0;
if (RT_SUCCESS(rc))
{
for (uint32_t i = 0; i < cUsersInList; i++)
}
/* Build the user list. */
if (RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
{
char *psz = pszUserList;
for (uint32_t i = 0; i < cUsersInList; i++)
{
if (i != 0)
*psz++ = ',';
}
*psz = '\0';
}
/* Cleanup. */
for (uint32_t i = 0; i < cUsersInList; i++)
RTStrFree(papszUsers[i]);
endutxent(); /* Close utmpx file. */
#endif
/* If the user enumeration above failed, reset the user count to 0 except
* we didn't have enough memory anymore. In that case we want to preserve
* the previous user count in order to not confuse third party tools which
* rely on that count. */
if (RT_FAILURE(rc))
{
if (rc == VERR_NO_MEMORY)
{
static int s_iVMInfoBitchedOOM = 0;
if (s_iVMInfoBitchedOOM++ < 3)
VBoxServiceVerbose(0, "Warning: Not enough memory available to enumerate users! Keeping old value (%RU32)\n",
}
else
cUsersInList = 0;
}
else /* Preserve logged in users count. */
if (pszUserList)
{
rc = VBoxServicePropCacheUpdate(&g_VMInfoPropCache, g_pszPropCacheValLoggedInUsersList, "%s", pszUserList);
}
else
if (RT_FAILURE(rc))
rc = VBoxServicePropCacheUpdate(&g_VMInfoPropCache, g_pszPropCacheValLoggedInUsers, "%RU32", cUsersInList);
if (RT_FAILURE(rc))
if (RT_FAILURE(rc))
if (pszUserList)
return rc;
}
/**
* Provide information about the guest network.
*/
static int vboxserviceVMInfoWriteNetwork(void)
{
int rc = VINF_SUCCESS;
uint32_t cIfacesReport = 0;
char szPropPath[256];
#ifdef RT_OS_WINDOWS
# ifndef TARGET_NT4
if (!pAdpInfo)
{
VBoxServiceError("VMInfo/Network: Failed to allocate IP_ADAPTER_INFO\n");
return VERR_NO_MEMORY;
}
if (dwRet == ERROR_BUFFER_OVERFLOW)
{
if (pAdpInfoNew)
{
}
}
else if (dwRet == ERROR_NO_DATA)
{
/* If no network adapters available / present in the
* system we pretend success to not bail out too early. */
}
if (dwRet != ERROR_SUCCESS)
{
if (pAdpInfo)
return RTErrConvertFromWin32(dwRet);
}
# endif /* !TARGET_NT4 */
{
int wsaErr = WSAGetLastError();
* on NT4 due to start up when not connected shares dialogs pop up. */
if (WSAENETDOWN == wsaErr)
{
VBoxServiceVerbose(0, "VMInfo/Network: Network is not up yet.\n");
}
else
if (pAdpInfo)
return RTErrConvertFromWin32(wsaErr);
}
unsigned long nBytesReturned = 0;
0,
0,
sizeof(InterfaceList),
0,
0) == SOCKET_ERROR)
{
if (pAdpInfo)
return RTErrConvertFromWin32(WSAGetLastError());
}
/** @todo Use GetAdaptersInfo() and GetAdapterAddresses (IPv4 + IPv6) for more information. */
for (int i = 0; i < cIfacesSystem; ++i)
{
continue;
char szIp[32];
RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/IP", cIfacesReport);
RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/Broadcast", cIfacesReport);
RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/Netmask", cIfacesReport);
RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/Status", cIfacesReport);
# ifndef TARGET_NT4
break;
if (pAdp)
{
char szMac[32];
}
else
# endif /* !TARGET_NT4 */
}
if (pAdpInfo)
if (sd >= 0)
#elif defined(RT_OS_HAIKU)
/** @todo Haiku: implement network info. retreival */
return VERR_NOT_IMPLEMENTED;
/* Get all available interfaces */
if (rc < 0)
{
VBoxServiceError("VMInfo/Network: Failed to get all interfaces: Error %Rrc\n");
return rc;
}
/* Loop through all interfaces and set the data. */
{
/*
* Only AF_INET and no loopback interfaces
* @todo: IPv6 interfaces
*/
{
char szInetAddr[NI_MAXHOST];
RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/IP", cIfacesReport);
RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/Broadcast", cIfacesReport);
RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/Netmask", cIfacesReport);
/* Search for the AF_LINK interface of the current AF_INET one and get the mac. */
{
{
char szMac[32];
break;
}
}
RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/Status", cIfacesReport);
VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, pIfCurr->ifa_flags & IFF_UP ? "Up" : "Down");
}
}
/* Free allocated resources. */
#else /* !RT_OS_WINDOWS && !RT_OS_FREEBSD */
if (sd < 0)
{
return rc;
}
char buffer[1024] = {0};
{
return rc;
}
for (int i = 0; i < cIfacesSystem; ++i)
{
{
break;
}
continue;
RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/IP", cIfacesReport);
{
break;
}
RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/Broadcast", cIfacesReport);
{
break;
}
# if defined(RT_OS_OS2) || defined(RT_OS_SOLARIS)
# else
# endif
RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/Netmask", cIfacesReport);
# if defined(RT_OS_SOLARIS)
/*
* "ifreq" is obsolete on Solaris. We use the recommended "lifreq".
* We might fail if the interface has not been assigned an IP address.
* That doesn't matter; as long as it's plumbed we can pick it up.
* But, if it has not acquired an IP address we cannot obtain it's MAC
* address this way, so we just use all zeros there.
*/
{
else
{
break;
}
}
else
{
VBoxServiceVerbose(2, "VMInfo/Network: Interface %d has no assigned IP address, skipping ...\n", i);
continue;
}
# else
# ifndef RT_OS_OS2 /** @todo port this to OS/2 */
{
break;
}
# endif
# endif
# ifndef RT_OS_OS2 /** @todo port this to OS/2 */
char szMac[32];
# if defined(RT_OS_SOLARIS)
# else
# endif
# endif /* !OS/2*/
RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/Status", cIfacesReport);
} /* For all interfaces */
if (RT_FAILURE(rc))
VBoxServiceError("VMInfo/Network: Network enumeration for interface %RU32 failed with error %Rrc\n", cIfacesReport, rc);
#endif /* !RT_OS_WINDOWS */
#if 0 /* Zapping not enabled yet, needs more testing first. */
/*
* Zap all stale network interface data if the former (saved) network ifaces count
* is bigger than the current one.
*/
/* Get former count. */
rc = VBoxServiceReadPropUInt32(g_uVMInfoGuestPropSvcClientID, g_pszPropCacheValNetCount, &cIfacesReportOld,
if ( RT_SUCCESS(rc)
{
VBoxServiceVerbose(3, "VMInfo/Network: Stale interface data detected (%RU32 old vs. %RU32 current)\n",
do
{
VBoxServiceVerbose(3, "VMInfo/Network: Deleting stale data of interface %d ...\n", uIfaceDeleteIdx);
rc = VBoxServicePropCacheUpdateByPath(&g_VMInfoPropCache, NULL /* Value, delete */, 0 /* Flags */, "/VirtualBox/GuestInfo/Net/%RU32", uIfaceDeleteIdx++);
} while (RT_SUCCESS(rc));
}
else if ( RT_FAILURE(rc)
&& rc != VERR_NOT_FOUND)
{
VBoxServiceError("VMInfo/Network: Failed retrieving old network interfaces count with error %Rrc\n", rc);
}
#endif
/*
* This property is a beacon which is _always_ written, even if the network configuration
* does not change. If this property is missing, the host assumes that all other GuestInfo
* properties are no longer valid.
*/
/* Don't fail here; just report everything we got. */
return VINF_SUCCESS;
}
/** @copydoc VBOXSERVICE::pfnWorker */
{
int rc;
/*
* Tell the control thread that it can continue
* spawning services.
*/
#ifdef RT_OS_WINDOWS
/* Required for network information (must be called per thread). */
VBoxServiceError("VMInfo/Network: WSAStartup failed! Error: %Rrc\n", RTErrConvertFromWin32(WSAGetLastError()));
#endif /* RT_OS_WINDOWS */
/*
* Write the fixed properties first.
*/
/*
* Now enter the loop retrieving runtime data continuously.
*/
for (;;)
{
if (RT_FAILURE(rc))
break;
if (RT_FAILURE(rc))
break;
/* Whether to wait for event semaphore or not. */
bool fWait = true;
/* Check for location awareness. This most likely only
* works with VBox (latest) 4.1 and up. */
/* Check for new connection. */
char *pszLAClientID = NULL;
int rc2 = VBoxServiceReadHostProp(g_uVMInfoGuestPropSvcClientID, g_pszLAActiveClient, true /* Read only */,
if (RT_SUCCESS(rc2))
{
{
/* Peek at "Attach" value to figure out if hotdesking happened. */
if ( RT_SUCCESS(rc2)
&& ( !g_LAClientAttachedTS
|| (g_LAClientAttachedTS != uLAClientAttachedTS)))
{
/* Note: There is a race between setting the guest properties by the host and getting them by
* the guest. */
if (RT_SUCCESS(rc2))
{
/* If g_LAClientAttachedTS is 0 this means there already was an active
* hotdesk session when VBoxService started. */
/* Don't wait for event semaphore below anymore because we now know that the client
* changed. This means we need to iterate all VM information again immediately. */
fWait = false;
}
else
{
static int s_iBitchedAboutLAClientInfo = 0;
if (s_iBitchedAboutLAClientInfo++ < 10)
}
}
else if (RT_FAILURE(rc2))
VBoxServiceError("Error getting attached value of location awareness client %RU32, rc=%Rrc\n",
uLAClientID, rc2);
if (pszAttach)
}
else
{
}
}
else
{
static int s_iBitchedAboutLAClient = 0;
&& s_iBitchedAboutLAClient++ < 3)
}
/*
* Flush all properties if we were restored.
*/
if (idNewSession != g_idVMInfoSession)
{
}
/*
* Block for a while.
*
* The event semaphore takes care of ignoring interruptions and it
* allows us to implement service wakeup later.
*/
if (*pfShutdown)
break;
if (fWait)
if (*pfShutdown)
break;
{
break;
}
{
/* Reset event semaphore if it got triggered. */
if (RT_FAILURE(rc2))
}
}
#ifdef RT_OS_WINDOWS
WSACleanup();
#endif
return rc;
}
/** @copydoc VBOXSERVICE::pfnStop */
static DECLCALLBACK(void) VBoxServiceVMInfoStop(void)
{
}
/** @copydoc VBOXSERVICE::pfnTerm */
static DECLCALLBACK(void) VBoxServiceVMInfoTerm(void)
{
if (g_hVMInfoEvent != NIL_RTSEMEVENTMULTI)
{
/** @todo temporary solution: Zap all values which are not valid
* be replaced with "temporary properties" later.
*
* One idea is to introduce a (HGCM-)session guest property
* flag meaning that a guest property is only valid as long
* as the HGCM session isn't closed (e.g. guest application
* terminates). [don't remove till implemented]
*/
/** @todo r=bird: Drop the VbglR3GuestPropDelSet call here and use the cache
* since it remembers what we've written. */
/* Delete the "../Net" branch. */
/* Destroy LA client info. */
/* Destroy property cache. */
/* Disconnect from guest properties service. */
if (RT_FAILURE(rc))
}
}
/**
* The 'vminfo' service description.
*/
{
/* pszName. */
"vminfo",
/* pszDescription. */
"Virtual Machine Information",
/* pszUsage. */
" [--vminfo-interval <ms>] [--vminfo-user-idle-threshold <ms>]"
,
/* pszOptions. */
" --vminfo-interval Specifies the interval at which to retrieve the\n"
" VM information. The default is 10000 ms.\n"
" --vminfo-user-idle-threshold <ms>\n"
" Specifies the user idle threshold (in ms) for\n"
" considering a guest user being as idle. The default\n"
" is 5000 (5 seconds).\n"
,
/* methods */
};