VirtualBox

Ignore:
Timestamp:
May 4, 2010 2:18:27 PM (15 years ago)
Author:
vboxsync
Message:

VBoxServiceVMInfo/PropCache: r=bird: todos in the code. Fixed two odd semaphore exit bugs.

Location:
trunk/src/VBox/Additions/common/VBoxService
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxService/Makefile.kmk

    r29011 r29026  
    5555        VBoxServiceTimeSync.cpp \
    5656        VBoxServiceUtils.cpp \
    57         VBoxServiceStats.cpp \
    58         VBoxServicePropCache.cpp
     57        VBoxServiceStats.cpp
    5958ifdef VBOX_WITH_GUEST_CONTROL
    6059 VBoxService_SOURCES    += \
    61         VBoxServiceControl.cpp \
    62         VBoxServiceControlExec.cpp
     60        VBoxServiceControl.cpp \
     61        VBoxServiceControlExec.cpp
    6362endif
    6463ifdef VBOX_WITH_MEMBALLOON
    6564 VBoxService_SOURCES    += \
    66         VBoxServiceBalloon.cpp
     65        VBoxServiceBalloon.cpp
    6766endif
    6867ifdef VBOX_WITH_PAGE_SHARING
    6968 VBoxService_SOURCES    += \
    70         VBoxServicePageSharing.cpp
     69        VBoxServicePageSharing.cpp
    7170endif
    7271ifdef VBOX_WITH_GUEST_PROPS
     
    7473        VBoxServiceVMInfo-win.cpp
    7574 VBoxService_SOURCES     += \
    76         VBoxServiceVMInfo.cpp
     75        VBoxServiceVMInfo.cpp \
     76        VBoxServicePropCache.cpp
    7777 if1of ($(KBUILD_TARGET), win)
    7878  VBoxService_SOURCES    += \
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceInternal.h

    r28983 r29026  
    9393
    9494#ifdef RT_OS_WINDOWS
     95
    9596/** The service name (needed for mutex creation on Windows). */
    9697# define VBOXSERVICE_NAME           "VBoxService"
     
    122123/** Function prototypes for dynamic loading. */
    123124typedef DWORD (WINAPI *PFNWTSGETACTIVECONSOLESESSIONID)(void);
     125
    124126#endif /* RT_OS_WINDOWS */
    125 
    126127#ifdef VBOX_WITH_GUEST_CONTROL
     128
    127129enum VBOXSERVICECTRLTHREADDATATYPE
    128130{
     
    194196 * For buffering process input supplied by the client.
    195197 */
    196 typedef struct
     198typedef struct VBOXSERVICECTRLSTDINBUF
    197199{
    198200    /** The mount of buffered data. */
     
    211213/** Pointer to a standard input buffer. */
    212214typedef VBOXSERVICECTRLSTDINBUF *PVBOXSERVICECTRLSTDINBUF;
     215
    213216#endif /* VBOX_WITH_GUEST_CONTROL */
    214 
    215217#ifdef VBOX_WITH_GUEST_PROPS
     218
    216219/**
    217220 * A guest property cache.
    218221 */
    219 typedef struct
    220 {   
     222typedef struct VBOXSERVICEVEPROPCACHE
     223{
    221224    /** The client ID for HGCM communication. */
    222     uint32_t   uClientID;
    223     RTLISTNODE Node;
    224     RTSEMMUTEX Mutex;
     225    uint32_t    uClientID;
     226    /** List of VBOXSERVICEVEPROPCACHEENTRY nodes.
     227     * @todo r=bird: Node -> ListSomething, please.  "Node" is very nondescript and
     228     *       makes the list-head vs. list-node confusion greater. */
     229    RTLISTNODE  Node;
     230    /** @todo Use a RTCRITSECT. RTSEMMUTEXes are deprecated in ring-3. */
     231    RTSEMMUTEX  Mutex;
    225232} VBOXSERVICEVEPROPCACHE;
    226233/** Pointer to a guest property cache. */
     
    228235
    229236/**
    230  * Handling guest properties used by the VM information service.
    231  */
    232 typedef struct
    233 {   
     237 * An entry in the property cache (VBOXSERVICEVEPROPCACHE).
     238 */
     239typedef struct VBOXSERVICEVEPROPCACHEENTRY
     240{
    234241    /** Node. */
    235     RTLISTNODE Node;
     242    RTLISTNODE  Node;
    236243    /** Name (and full path) of guest property. */
    237     char    *pszName;
     244    char       *pszName;
    238245    /** The last value stored (for reference). */
    239     char    *pszValue;
    240     /** Reset value to write if property is temporary. */
    241     char    *pszValueReset;
     246    char       *pszValue;
     247    /** Reset value to write if property is temporary.  If NULL, it will be
     248     *  deleted. */
     249    char       *pszValueReset;
    242250    /** Flags. */
    243     uint32_t uFlags;
     251    uint32_t    fFlags;
    244252} VBOXSERVICEVEPROPCACHEENTRY;
    245253/** Pointer to a cached guest property. */
    246254typedef VBOXSERVICEVEPROPCACHEENTRY *PVBOXSERVICEVEPROPCACHEENTRY;
     255
    247256#endif /* VBOX_WITH_GUEST_PROPS */
    248257
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServicePropCache.cpp

    r28983 r29026  
    3030#include "VBoxServicePropCache.h"
    3131
    32 #ifdef VBOX_WITH_GUEST_PROPS
    33 
    34 /** @todo Docs */
    35 int VBoxServicePropCacheInit(PVBOXSERVICEVEPROPCACHE pCache, uint32_t u32ClientId)
    36 {
    37     AssertPtr(pCache);
    38     /** @todo Prevent init the cache twice! */
     32
     33/**
     34 * Initializes the property cache.
     35 *
     36 * @returns IPRT status code.
     37 * @param   pCache          Pointer to the cache.
     38 * @param   uClientId       The HGCM handle of to the guest property service.
     39 */
     40int VBoxServicePropCacheInit(PVBOXSERVICEVEPROPCACHE pCache, uint32_t uClientId)
     41{
     42    AssertPtr(pCache);
     43    /** @todo Prevent init the cache twice!
     44     *  r=bird: Use a magic, or/and abstract the whole cache by rename this function
     45     *  VBoxServicePropCacheCreate(). */
    3946    RTListInit(&pCache->Node);
    40     pCache->uClientID = u32ClientId;
     47    pCache->uClientID = uClientId;
    4148    return RTSemMutexCreate(&pCache->Mutex);
    4249}
    4350
    4451
    45 /** @todo Docs */
     52/** @todo Docs
     53 * @todo this looks internal to me, nobody should need to access the
     54 *       structures directly here. */
    4655PVBOXSERVICEVEPROPCACHEENTRY VBoxServicePropCacheFind(PVBOXSERVICEVEPROPCACHE pCache, const char *pszName, uint32_t uFlags)
    4756{
    4857    AssertPtr(pCache);
    4958    AssertPtr(pszName);
    50     /* This is a O(n) lookup, maybe improve this later to O(1) using a map. */
     59    /** @todo This is a O(n) lookup, maybe improve this later to O(1) using a
     60     *        map.
     61     *  r=bird: Use a string space (RTstrSpace*). That is O(log n) in its current
     62     *        implementation (AVL tree). However, this is not important at the
     63     *        moment. */
    5164    PVBOXSERVICEVEPROPCACHEENTRY pNodeIt, pNode = NULL;
    5265    if (RT_SUCCESS(RTSemMutexRequest(pCache->Mutex, RT_INDEFINITE_WAIT)))
    53     {   
     66    {
    5467        RTListForEach(&pCache->Node, pNodeIt, VBOXSERVICEVEPROPCACHEENTRY, Node)
    5568        {
     
    6780
    6881/** @todo Docs */
    69 int VBoxServicePropCacheUpdateEntry(PVBOXSERVICEVEPROPCACHE pCache, 
    70                                     const char *pszName, uint32_t u32Flags, const char *pszValueReset)
     82int VBoxServicePropCacheUpdateEntry(PVBOXSERVICEVEPROPCACHE pCache,
     83                                    const char *pszName, uint32_t fFlags, const char *pszValueReset)
    7184{
    7285    AssertPtr(pCache);
     
    7992        if (RT_SUCCESS(rc))
    8093        {
    81             pNode->uFlags = u32Flags;
     94            pNode->fFlags = fFlags;
    8295            if (pszValueReset)
    8396            {
     
    100113 * @returns VBox status code. Errors will be logged.
    101114 *
    102  * @param   u32ClientId     The HGCM client ID for the guest property session.
     115 * @param   pCache          The property cache.
    103116 * @param   pszName         The property name.
    104117 * @param   pszValueFormat  The property format string.  If this is NULL then
     
    129142 * @returns VBox status code. Errors will be logged.
    130143 *
    131  * @param   u32ClientId     The HGCM client ID for the guest property session.
     144 * @param   pCache          The property cache.
    132145 * @param   pszName         The property name.
    133146 * @param   pszValueFormat  The property format string.  If this is NULL then
     
    135148 * @param   ...             Format arguments.
    136149 */
    137 int VBoxServicePropCacheUpdateEx(PVBOXSERVICEVEPROPCACHE pCache, const char *pszName, uint32_t u32Flags, const char *pszValueReset, const char *pszValueFormat, ...)
     150int VBoxServicePropCacheUpdateEx(PVBOXSERVICEVEPROPCACHE pCache, const char *pszName, uint32_t fFlags,
     151                                 const char *pszValueReset, const char *pszValueFormat, ...)
    138152{
    139153    AssertPtr(pCache);
     
    141155    AssertPtr(pszName);
    142156
     157    /*
     158     * Format the value first.
     159     */
    143160    char *pszValue = NULL;
    144161    if (pszValueFormat)
     
    148165        RTStrAPrintfV(&pszValue, pszValueFormat, va);
    149166        va_end(va);
     167        if (!pszValue)
     168            return VERR_NO_STR_MEMORY;
    150169    }
    151170
     
    156175    if (RT_SUCCESS(rc))
    157176    {
    158    
     177
    159178        if (pNode == NULL)
    160         {         
     179        {
    161180            pNode = (PVBOXSERVICEVEPROPCACHEENTRY)RTMemAlloc(sizeof(VBOXSERVICEVEPROPCACHEENTRY));
    162             AssertPtrReturn(pNode, VERR_NO_MEMORY);
    163    
     181            if (RT_UNLIKELY(!pNode))
     182            {
     183                RTSemMutexRelease(pCache->Mutex);
     184                return VERR_NO_MEMORY;
     185            }
     186
    164187            pNode->pszName = RTStrDup(pszName);
    165             pNode->pszValue = NULL; 
    166             pNode->uFlags = 0;
     188            pNode->pszValue = NULL;
     189            pNode->fFlags = 0;
    167190            pNode->pszValueReset = NULL;
    168    
     191
    169192            /*rc =*/ RTListAppend(&pCache->Node, &pNode->Node);
    170193        }
    171    
     194
    172195        AssertPtr(pNode);
    173196        if (pszValue) /* Do we have a value to check for? */
     
    175198            bool fUpdate = false;
    176199            /* Always update this property, no matter what? */
    177             if (pNode->uFlags & VBOXSERVICEPROPCACHEFLAG_ALWAYS_UPDATE)
     200            if (pNode->fFlags & VBOXSERVICEPROPCACHEFLAG_ALWAYS_UPDATE)
    178201                fUpdate = true;
    179202            /* Did the value change so we have to update? */
     
    181204                fUpdate = true;
    182205            /* No value stored at the moment but we have a value now? */
    183             else if (pNode->pszValue == NULL) 
     206            else if (pNode->pszValue == NULL)
    184207                fUpdate = true;
    185    
     208
    186209            if (fUpdate)
    187210            {
    188211                /* Write the update. */
    189212                rc = VBoxServiceWritePropF(pCache->uClientID, pNode->pszName, pszValue);
    190                 if (pNode->pszValue)
    191                     RTStrFree(pNode->pszValue);
     213                RTStrFree(pNode->pszValue);
    192214                pNode->pszValue = RTStrDup(pszValue);
    193215            }
    194216            else
     217                /** @todo r=bird: Add a VINF_NO_CHANGE status code to iprt/err.h and use it. */
    195218                rc = VINF_ALREADY_INITIALIZED; /* No update needed. */
    196219        }
    197         else 
     220        else
    198221        {
    199222            /* No value specified. Deletion (or no action required). */
     
    201224            {
    202225                /* Delete property (but do not remove from cache) if not deleted yet. */
    203                 rc = VBoxServiceWritePropF(pCache->uClientID, pNode->pszName, NULL);
    204226                RTStrFree(pNode->pszValue);
    205227                pNode->pszValue = NULL;
     228                rc = VBoxServiceWritePropF(pCache->uClientID, pNode->pszName, NULL);
    206229            }
    207230            else
     231                /** @todo r=bird: Use VINF_NO_CHANGE. */
    208232                rc = VINF_ALREADY_INITIALIZED; /* No update needed. */
    209233        }
    210    
     234
    211235        /* Update rest of the fields. */
    212236        if (pszValueReset)
     
    216240            pNode->pszValueReset = RTStrDup(pszValueReset);
    217241        }
    218         if (u32Flags)
    219             pNode->uFlags = u32Flags;
    220      
    221         /* Delete temp stuff. */
    222         if (pszValue)
    223             RTStrFree(pszValue);   
    224    
     242        if (fFlags)
     243            pNode->fFlags = fFlags;
     244
    225245        /* Release cache. */
    226246        int rc2 = RTSemMutexRelease(pCache->Mutex);
     
    228248            rc2 = rc;
    229249    }
     250
     251    /* Delete temp stuff. */
     252    RTStrFree(pszValue);
     253
    230254    return rc;
    231255}
    232256
    233257
    234 /** @todo Docs */
     258/**
     259 * Reset all temporary properties and destroy the cache.
     260 *
     261 * @param   pCache          The property cache.
     262 */
    235263void VBoxServicePropCacheDestroy(PVBOXSERVICEVEPROPCACHE pCache)
    236264{
     
    240268    RTListForEach(&pCache->Node, pNode, VBOXSERVICEVEPROPCACHEENTRY, Node)
    241269    {
    242         if ((pNode->uFlags & VBOXSERVICEPROPCACHEFLAG_TEMPORARY) == 0)
    243         {
    244             if (pNode->pszValueReset) /* Write reset value? */
    245             {
    246                 /* rc = */VBoxServiceWritePropF(pCache->uClientID, pNode->pszName, pNode->pszValueReset);
    247             }
    248             else /* Delete value. */
    249                 /* rc = */VBoxServiceWritePropF(pCache->uClientID, pNode->pszName, NULL);
    250         }
     270        if ((pNode->fFlags & VBOXSERVICEPROPCACHEFLAG_TEMPORARY) == 0)
     271            VBoxServiceWritePropF(pCache->uClientID, pNode->pszName, pNode->pszValueReset);
    251272
    252273        AssertPtr(pNode->pszName);
    253274        RTStrFree(pNode->pszName);
    254         if (pNode->pszValue)
    255             RTStrFree(pNode->pszValue);
    256         if (pNode->pszValueReset)
    257             RTStrFree(pNode->pszValueReset);
    258         pNode->uFlags = 0;
     275        RTStrFree(pNode->pszValue);
     276        RTStrFree(pNode->pszValueReset);
     277        pNode->fFlags = 0;
    259278    }
    260279
     
    264283        PVBOXSERVICEVEPROPCACHEENTRY pNext = RTListNodeGetNext(&pNode->Node, VBOXSERVICEVEPROPCACHEENTRY, Node);
    265284        RTListNodeRemove(&pNode->Node);
     285        /** @todo r=bird: hrm. missing RTMemFree(pNode)? Why don't you just combine the
     286         *        two loops? */
     287
    266288        if (pNext && RTListNodeIsLast(&pCache->Node, &pNext->Node))
    267289            break;
    268290        pNode = pNext;
    269291    }
     292
    270293    /* Destroy mutex. */
    271294    RTSemMutexDestroy(pCache->Mutex);
    272295}
    273 #endif /* VBOX_WITH_GUEST_PROPS */
     296
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServicePropCache.h

    r28967 r29026  
    2626#define VBOXSERVICEPROPCACHEFLAG_ALWAYS_UPDATE      RT_BIT(2)
    2727
    28 int VBoxServicePropCacheInit(PVBOXSERVICEVEPROPCACHE pCache, uint32_t u32ClientId);
     28int VBoxServicePropCacheInit(PVBOXSERVICEVEPROPCACHE pCache, uint32_t uClientId);
    2929PVBOXSERVICEVEPROPCACHEENTRY VBoxServicePropCacheFind(PVBOXSERVICEVEPROPCACHE pCache, const char *pszName, uint32_t uFlags);
    30 int VBoxServicePropCacheUpdateEntry(PVBOXSERVICEVEPROPCACHE pCache, const char *pszName, uint32_t uFlags, const char *pszValueReset);
     30int VBoxServicePropCacheUpdateEntry(PVBOXSERVICEVEPROPCACHE pCache, const char *pszName, uint32_t fFlags, const char *pszValueReset);
    3131int VBoxServicePropCacheUpdate(PVBOXSERVICEVEPROPCACHE pCache, const char *pszName, const char *pszValueFormat, ...);
    32 int VBoxServicePropCacheUpdateEx(PVBOXSERVICEVEPROPCACHE pCache, const char *pszName, uint32_t u32Flags, const char *pszValueReset, const char *pszValueFormat, ...);
     32int VBoxServicePropCacheUpdateEx(PVBOXSERVICEVEPROPCACHE pCache, const char *pszName, uint32_t fFlags, const char *pszValueReset, const char *pszValueFormat, ...);
    3333void VBoxServicePropCacheDestroy(PVBOXSERVICEVEPROPCACHE pCache);
    3434#endif
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo.cpp

    r28978 r29026  
    6161*******************************************************************************/
    6262/** The vminfo interval (millseconds). */
    63 uint32_t                        g_VMInfoInterval = 0;
     63static uint32_t                 g_cMsVMInfoInterval = 0;
    6464/** The semaphore we're blocking on. */
    65 static RTSEMEVENTMULTI          g_VMInfoEvent = NIL_RTSEMEVENTMULTI;
     65static RTSEMEVENTMULTI          g_hVMInfoEvent = NIL_RTSEMEVENTMULTI;
    6666/** The guest property service client ID. */
    67 static uint32_t                 g_VMInfoGuestPropSvcClientID = 0;
     67static uint32_t                 g_uVMInfoGuestPropSvcClientID = 0;
    6868/** Number of logged in users in OS. */
    6969static uint32_t                 g_cVMInfoLoggedInUsers = UINT32_MAX;
     
    8787    else if (!strcmp(argv[*pi], "--vminfo-interval"))
    8888        rc = VBoxServiceArgUInt32(argc, argv, "", pi,
    89                                   &g_VMInfoInterval, 1, UINT32_MAX - 1);
     89                                  &g_cMsVMInfoInterval, 1, UINT32_MAX - 1);
    9090    return rc;
    9191}
     
    9999     * Then create the event sem to block on.
    100100     */
    101     if (!g_VMInfoInterval)
    102         g_VMInfoInterval = g_DefaultInterval * 1000;
    103     if (!g_VMInfoInterval)
    104         g_VMInfoInterval = 10 * 1000;
    105 
    106     int rc = RTSemEventMultiCreate(&g_VMInfoEvent);
     101    if (!g_cMsVMInfoInterval)
     102        g_cMsVMInfoInterval = g_DefaultInterval * 1000;
     103    if (!g_cMsVMInfoInterval)
     104        g_cMsVMInfoInterval = 10 * 1000;
     105
     106    int rc = RTSemEventMultiCreate(&g_hVMInfoEvent);
    107107    AssertRCReturn(rc, rc);
    108108
     
    117117#endif
    118118
    119     rc = VbglR3GuestPropConnect(&g_VMInfoGuestPropSvcClientID);
     119    rc = VbglR3GuestPropConnect(&g_uVMInfoGuestPropSvcClientID);
    120120    if (RT_SUCCESS(rc))
    121         VBoxServiceVerbose(3, "Property Service Client ID: %#x\n", g_VMInfoGuestPropSvcClientID);
     121        VBoxServiceVerbose(3, "Property Service Client ID: %#x\n", g_uVMInfoGuestPropSvcClientID);
    122122    else
    123123    {
    124124        VBoxServiceError("Failed to connect to the guest property service! Error: %Rrc\n", rc);
    125         RTSemEventMultiDestroy(g_VMInfoEvent);
    126         g_VMInfoEvent = NIL_RTSEMEVENTMULTI;
     125        RTSemEventMultiDestroy(g_hVMInfoEvent);
     126        g_hVMInfoEvent = NIL_RTSEMEVENTMULTI;
    127127    }
    128128
    129129    if (RT_SUCCESS(rc))
    130130    {
    131         VBoxServicePropCacheInit(&g_VMInfoPropCache, g_VMInfoGuestPropSvcClientID);
     131        VBoxServicePropCacheInit(&g_VMInfoPropCache, g_uVMInfoGuestPropSvcClientID);
     132
     133        /** @todo r=bird: Setting Net/Count to 0 here is wrong and will confuse users.
     134         *        Besides, because it is the beacon updating it implies that all the
     135         *        other values are up to date too, but they aren't
     136         *        (VBoxServiceVMInfoWriteFixedProperties hasn't been called yet for
     137         *        instance).  I would suggest changing these statements to
     138         *        "declarations" or moving them. */
    132139
    133140        /*
     
    135142         * Passing NULL as an actual value does not write the properties yet.
    136143         */
    137         VBoxServicePropCacheUpdateEx(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/OS/LoggedInUsersList", 
     144        VBoxServicePropCacheUpdateEx(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/OS/LoggedInUsersList",
    138145                                     VBOXSERVICEPROPCACHEFLAG_TEMPORARY, NULL /* Delete on exit */, NULL);
    139         VBoxServicePropCacheUpdateEx(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/OS/LoggedInUsers", 
     146        VBoxServicePropCacheUpdateEx(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/OS/LoggedInUsers",
    140147                                     VBOXSERVICEPROPCACHEFLAG_TEMPORARY, "0", NULL);
    141         VBoxServicePropCacheUpdateEx(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/OS/NoLoggedInUsers", 
     148        VBoxServicePropCacheUpdateEx(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/OS/NoLoggedInUsers",
    142149                                     VBOXSERVICEPROPCACHEFLAG_TEMPORARY, "true", NULL);
    143150        /*
     
    146153         * properties are no longer valid.
    147154         */
    148         VBoxServicePropCacheUpdateEx(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/Net/Count", 
     155        VBoxServicePropCacheUpdateEx(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/Net/Count",
    149156                                     VBOXSERVICEPROPCACHEFLAG_TEMPORARY | VBOXSERVICEPROPCACHEFLAG_ALWAYS_UPDATE, "0", NULL);
    150157    }
     
    165172    char szInfo[256];
    166173    int rc = RTSystemQueryOSInfo(RTSYSOSINFO_PRODUCT, szInfo, sizeof(szInfo));
    167     VBoxServiceWritePropF(g_VMInfoGuestPropSvcClientID, "/VirtualBox/GuestInfo/OS/Product",
     174    VBoxServiceWritePropF(g_uVMInfoGuestPropSvcClientID, "/VirtualBox/GuestInfo/OS/Product",
    168175                          "%s", RT_FAILURE(rc) ? "" : szInfo);
    169176
    170177    rc = RTSystemQueryOSInfo(RTSYSOSINFO_RELEASE, szInfo, sizeof(szInfo));
    171     VBoxServiceWritePropF(g_VMInfoGuestPropSvcClientID, "/VirtualBox/GuestInfo/OS/Release",
     178    VBoxServiceWritePropF(g_uVMInfoGuestPropSvcClientID, "/VirtualBox/GuestInfo/OS/Release",
    172179                          "%s", RT_FAILURE(rc) ? "" : szInfo);
    173180
    174181    rc = RTSystemQueryOSInfo(RTSYSOSINFO_VERSION, szInfo, sizeof(szInfo));
    175     VBoxServiceWritePropF(g_VMInfoGuestPropSvcClientID, "/VirtualBox/GuestInfo/OS/Version",
     182    VBoxServiceWritePropF(g_uVMInfoGuestPropSvcClientID, "/VirtualBox/GuestInfo/OS/Version",
    176183                          "%s", RT_FAILURE(rc) ? "" : szInfo);
    177184
    178185    rc = RTSystemQueryOSInfo(RTSYSOSINFO_SERVICE_PACK, szInfo, sizeof(szInfo));
    179     VBoxServiceWritePropF(g_VMInfoGuestPropSvcClientID, "/VirtualBox/GuestInfo/OS/ServicePack",
     186    VBoxServiceWritePropF(g_uVMInfoGuestPropSvcClientID, "/VirtualBox/GuestInfo/OS/ServicePack",
    180187                          "%s", RT_FAILURE(rc) ? "" : szInfo);
    181188
     
    186193    char *pszAddRev;
    187194    rc = VbglR3GetAdditionsVersion(&pszAddVer, &pszAddRev);
    188     VBoxServiceWritePropF(g_VMInfoGuestPropSvcClientID, "/VirtualBox/GuestAdd/Version",
     195    VBoxServiceWritePropF(g_uVMInfoGuestPropSvcClientID, "/VirtualBox/GuestAdd/Version",
    189196                          "%s", RT_FAILURE(rc) ? "" : pszAddVer);
    190     VBoxServiceWritePropF(g_VMInfoGuestPropSvcClientID, "/VirtualBox/GuestAdd/Revision",
     197    VBoxServiceWritePropF(g_uVMInfoGuestPropSvcClientID, "/VirtualBox/GuestAdd/Revision",
    191198                          "%s", RT_FAILURE(rc) ? "" : pszAddRev);
    192199    if (RT_SUCCESS(rc))
     
    202209    char *pszInstDir;
    203210    rc = VbglR3GetAdditionsInstallationPath(&pszInstDir);
    204     VBoxServiceWritePropF(g_VMInfoGuestPropSvcClientID, "/VirtualBox/GuestAdd/InstallDir",
     211    VBoxServiceWritePropF(g_uVMInfoGuestPropSvcClientID, "/VirtualBox/GuestAdd/InstallDir",
    205212                          "%s", RT_FAILURE(rc) ? "" :  pszInstDir);
    206213    if (RT_SUCCESS(rc))
    207214        RTStrFree(pszInstDir);
    208215
    209     VBoxServiceWinGetComponentVersions(g_VMInfoGuestPropSvcClientID);
     216    VBoxServiceWinGetComponentVersions(g_uVMInfoGuestPropSvcClientID);
    210217#endif
    211218}
     
    338345            || g_cVMInfoLoggedInUsers == UINT32_MAX)
    339346        {
    340             /* 
     347            /*
    341348             * Update this property ONLY if there is a real change from no users to
    342349             * users or vice versa. The only exception is that the initialization
    343350             * forces an update, but only once. This ensures consistent property
    344              * settings even if the VM aborted previously. 
     351             * settings even if the VM aborted previously.
    345352             */
    346353            if (cUsersInList == 0)
     
    355362         */
    356363        /** @todo Throw this code into a separate function/module? */
    357        int nNumInterfaces = 0;
     364       int cInterfaces = 0;
    358365#ifdef RT_OS_WINDOWS
    359366        SOCKET sd = WSASocket(AF_INET, SOCK_DGRAM, 0, 0, 0, 0);
     
    379386            return -1;
    380387        }
    381         nNumInterfaces = nBytesReturned / sizeof(INTERFACE_INFO);
     388        cInterfaces = nBytesReturned / sizeof(INTERFACE_INFO);
    382389#else
    383390        int sd = socket(AF_INET, SOCK_DGRAM, 0);
     
    400407        ifreq* ifrequest = ifcfg.ifc_req;
    401408        ifreq *ifreqitem = NULL;
    402         nNumInterfaces = ifcfg.ifc_len / sizeof(ifreq);
     409        cInterfaces = ifcfg.ifc_len / sizeof(ifreq);
    403410#endif
    404411        char szPropPath [FILENAME_MAX];
    405412        int iCurIface = 0;
    406413
     414        /** @todo r=bird: As mentioned in the defect, this must be written after ALL
     415         *        the other values since it indicates that they are up-to-date by its
     416         *        timestamp. */
    407417        VBoxServicePropCacheUpdate(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/Net/Count", "%d",
    408                                    nNumInterfaces > 1 ? nNumInterfaces-1 : 0);
     418                                   cInterfaces > 1 ? cInterfaces-1 : 0);
    409419
    410420        /** @todo Use GetAdaptersInfo() and GetAdapterAddresses (IPv4 + IPv6) for more information. */
    411         for (int i = 0; i < nNumInterfaces; ++i)
     421        for (int i = 0; i < cInterfaces; ++i)
    412422        {
    413423            sockaddr_in *pAddress;
     
    475485            close(sd);
    476486#endif
     487        /** @todo r=bird: if cInterfaces decreased compared to the previous run, zap
     488         *        the stale data. */
     489
    477490
    478491        /*
     
    484497        if (*pfShutdown)
    485498            break;
    486         int rc2 = RTSemEventMultiWait(g_VMInfoEvent, g_VMInfoInterval);
     499        int rc2 = RTSemEventMultiWait(g_hVMInfoEvent, g_cMsVMInfoInterval);
    487500        if (*pfShutdown)
    488501            break;
     
    506519static DECLCALLBACK(void) VBoxServiceVMInfoStop(void)
    507520{
    508     RTSemEventMultiSignal(g_VMInfoEvent);
     521    RTSemEventMultiSignal(g_hVMInfoEvent);
    509522}
    510523
     
    515528    int rc;
    516529
    517     if (g_VMInfoEvent != NIL_RTSEMEVENTMULTI)
     530    if (g_hVMInfoEvent != NIL_RTSEMEVENTMULTI)
    518531    {
     532        /** @todo temporary solution: Zap all values which are not valid
     533         *        anymore when VM goes down (reboot/shutdown ). Needs to
     534         *        be replaced with "temporary properties" later.
     535         *
     536         *        One idea is to introduce a (HGCM-)session guest property
     537         *        flag meaning that a guest property is only valid as long
     538         *        as the HGCM session isn't closed (e.g. guest application
     539         *        terminates). [don't remove till implemented]
     540         */
     541        /** @todo r=bird: Drop the VbglR3GuestPropDelSet call here and make the cache
     542         *        remember what we've written. */
    519543        /* Delete the "../Net" branch. */
    520544        const char *apszPat[1] = { "/VirtualBox/GuestInfo/Net/*" };
    521         rc = VbglR3GuestPropDelSet(g_VMInfoGuestPropSvcClientID, &apszPat[0], RT_ELEMENTS(apszPat));
     545        rc = VbglR3GuestPropDelSet(g_uVMInfoGuestPropSvcClientID, &apszPat[0], RT_ELEMENTS(apszPat));
    522546
    523547        /* Destroy property cache. */
     
    525549
    526550        /* Disconnect from guest properties service. */
    527         rc = VbglR3GuestPropDisconnect(g_VMInfoGuestPropSvcClientID);
     551        rc = VbglR3GuestPropDisconnect(g_uVMInfoGuestPropSvcClientID);
    528552        if (RT_FAILURE(rc))
    529553            VBoxServiceError("Failed to disconnect from guest property service! Error: %Rrc\n", rc);
    530         g_VMInfoGuestPropSvcClientID = 0;
    531 
    532         RTSemEventMultiDestroy(g_VMInfoEvent);
    533         g_VMInfoEvent = NIL_RTSEMEVENTMULTI;
     554        g_uVMInfoGuestPropSvcClientID = 0;
     555
     556        RTSemEventMultiDestroy(g_hVMInfoEvent);
     557        g_hVMInfoEvent = NIL_RTSEMEVENTMULTI;
    534558    }
    535559}
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette