VBoxServiceVMInfo.cpp revision 4fe198d6f302c883b3edf100a6990b2ee4923494
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsync * VBoxService - Virtual Machine Information for the Host.
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsync * Copyright (C) 2009-2010 Oracle Corporation
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsync * available from http://www.virtualbox.org. This file is free software;
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsync * you can redistribute it and/or modify it under the terms of the GNU
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsync * General Public License (GPL) as published by the Free Software
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsync/*******************************************************************************
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsync* Header Files *
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsync*******************************************************************************/
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsync# ifndef RT_OS_FREEBSD /* The header does not exist anymore since FreeBSD 9-current */
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsync/*******************************************************************************
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsync* Global Variables *
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsync*******************************************************************************/
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsync/** The vminfo interval (millseconds). */
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsync/** The semaphore we're blocking on. */
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsyncstatic RTSEMEVENTMULTI g_hVMInfoEvent = NIL_RTSEMEVENTMULTI;
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsync/** The guest property service client ID. */
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsync/** Number of logged in users in OS. */
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsyncstatic uint32_t g_cVMInfoLoggedInUsers = UINT32_MAX;
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsync/** The guest property cache. */
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsync/** @copydoc VBOXSERVICE::pfnPreInit */
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsyncstatic DECLCALLBACK(int) VBoxServiceVMInfoPreInit(void)
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsync/** @copydoc VBOXSERVICE::pfnOption */
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsyncstatic DECLCALLBACK(int) VBoxServiceVMInfoOption(const char **ppszShort, int argc, char **argv, int *pi)
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsync /* no short options */;
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsync/** @copydoc VBOXSERVICE::pfnInit */
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsyncstatic DECLCALLBACK(int) VBoxServiceVMInfoInit(void)
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsync * If not specified, find the right interval default.
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsync * Then create the event sem to block on.
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsync rc = VbglR3GuestPropConnect(&g_uVMInfoGuestPropSvcClientID);
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsync VBoxServiceVerbose(3, "VMInfo: Property Service Client ID: %#x\n", g_uVMInfoGuestPropSvcClientID);
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsync /* If the service was not found, we disable this service without
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsync causing VBoxService to fail. */
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsync if (rc == VERR_HGCM_SERVICE_NOT_FOUND) /* Host service is not available. */
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsync VBoxServiceVerbose(0, "VMInfo: Guest property service is not available, disabling the service\n");
9a24efbe4defba67d7fd702128f4afd13efd7b8bvboxsync VBoxServiceError("VMInfo: Failed to connect to the guest property service! Error: %Rrc\n", rc);
VBOXSERVICEPROPCACHEFLAG_TEMPORARY | VBOXSERVICEPROPCACHEFLAG_ALWAYS_UPDATE, NULL /* Delete on exit */);
return rc;
static void vboxserviceVMInfoWriteFixedProperties(void)
char *pszAddVer;
char *pszAddRev;
#ifdef RT_OS_WINDOWS
char *pszInstDir;
static int vboxserviceVMInfoWriteUsers(void)
int rc;
#ifdef RT_OS_WINDOWS
# ifndef TARGET_NT4
# ifdef RT_OS_SOLARIS
if (rc != 0)
setutent();
cUtmpEntries++;
if (aUsers)
bool fFound = false;
if (!fFound)
cUsersInList = 0;
VBoxServicePropCacheUpdate(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/OS/LoggedInUsersList", "%s", pszUserList);
VBoxServicePropCacheUpdate(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/OS/LoggedInUsers", "%u", cUsersInList);
return VINF_SUCCESS;
static int vboxserviceVMInfoWriteNetwork(void)
int cIfacesReport = 0;
#ifdef RT_OS_WINDOWS
# ifndef TARGET_NT4
if (!pAdpInfo)
return VERR_NO_MEMORY;
if (pAdpInfoNew)
if (pAdpInfo)
if (pAdpInfo)
unsigned long nBytesReturned = 0;
sizeof(InterfaceList),
0) == SOCKET_ERROR)
if (pAdpInfo)
for (int i = 0; i < cIfacesSystem; ++i)
RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%d/V4/Broadcast", cIfacesReport);
RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%d/V4/Netmask", cIfacesReport);
# ifndef TARGET_NT4
if (pAdp)
if (pAdpInfo)
if (sd >= 0)
int rc = 0;
if (rc < 0)
RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%d/V4/Broadcast", cIfacesReport);
RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%d/V4/Netmask", cIfacesReport);
VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, pIfCurr->ifa_flags & IFF_UP ? "Up" : "Down");
if (sd < 0)
for (int i = 0; i < cIfacesSystem; ++i)
RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%d/V4/Broadcast", cIfacesReport);
RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%d/V4/Netmask", cIfacesReport);
# if defined(RT_OS_SOLARIS)
# if defined(RT_OS_SOLARIS)
return VINF_SUCCESS;
int rc;
#ifdef RT_OS_WINDOWS
VBoxServiceError("VMInfo/Network: WSAStartup failed! Error: %Rrc\n", RTErrConvertFromWin32(WSAGetLastError()));
if (*pfShutdown)
if (*pfShutdown)
#ifdef RT_OS_WINDOWS
WSACleanup();
return rc;
int rc;