VirtualBox

Changeset 30048 in vbox for trunk/src


Ignore:
Timestamp:
Jun 7, 2010 6:35:37 AM (15 years ago)
Author:
vboxsync
Message:

VBoxServiceVMInfo.cpp: r=bird: Consitent error handling in vboxserviceVMInfoWriteUsers. Don't use constants like FILENAME_MAX (or _MAX_PATH) for sizing up buffers that hasn't got anything to do with the local file system. Use static functions where possible.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo.cpp

    r30013 r30048  
    156156 * Errors are ignored.
    157157 */
    158 static void VBoxServiceVMInfoWriteFixedProperties(void)
     158static void vboxserviceVMInfoWriteFixedProperties(void)
    159159{
    160160    /*
     
    213213 * Provide information about active users.
    214214 */
    215 int VBoxServiceVMInfoWriteUsers()
     215static int vboxserviceVMInfoWriteUsers(void)
    216216{
    217217    int rc;
     
    222222# ifndef TARGET_NT4
    223223    rc = VBoxServiceVMInfoWinWriteUsers(&pszUserList, &cUsersInList);
    224 # endif /* TARGET_NT4 */
     224# else
     225    rc = VERR_NOT_IMPLEMENTED;
     226# endif
    225227#elif defined(RT_OS_FREEBSD)
    226         /** @todo FreeBSD: Port logged on user info retrival. */
     228    /** @todo FreeBSD: Port logged on user info retrival. */
     229    rc = VERR_NOT_IMPLEMENTED;
    227230#elif defined(RT_OS_OS2)
    228         /** @todo OS/2: Port logged on (LAN/local/whatever) user info retrival. */
     231    /** @todo OS/2: Port logged on (LAN/local/whatever) user info retrival. */
     232    rc = VERR_NOT_IMPLEMENTED;
    229233#else
    230234    rc = utmpname(UTMP_FILE);
     
    236240    {
    237241        VBoxServiceError("VMInfo/Users: Could not set UTMP file! Error: %ld\n", errno);
    238     }
     242        rc = VERR_GENERAL_FAILURE;
     243    }
     244    else
     245        rc = VINF_SUCCESS;
    239246    setutent();
    240247    utmp *ut_user;
     
    250257            {
    251258                rc = RTStrAAppend(&pszUserList, ",");
    252                 AssertRCReturn(rc, rc);
     259                AssertRCBreakStmt(rc, RTStrFree(pszUserList));
    253260            }
    254261            rc = RTStrAAppend(&pszUserList, ut_user->ut_user);
    255             AssertRCReturn(rc, rc);
     262            AssertRCBreakStmt(rc, RTStrFree(pszUserList));
    256263            cUsersInList++;
    257264        }
    258265    }
    259266    endutent();
    260 #endif /* !RT_OS_WINDOWS */
     267#endif
     268    Assert(RT_FAILURE(rc) || cUsersInList == 0 || (pszUserList && *pszUserList));
     269    if (RT_FAILURE(rc))
     270        cUsersInList = 0;
    261271
    262272    if (pszUserList && cUsersInList > 0)
     
    267277    if (g_cVMInfoLoggedInUsers != cUsersInList)
    268278    {
    269         VBoxServicePropCacheUpdate(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/OS/NoLoggedInUsers", cUsersInList == 0 ? "true" : "false");
     279        VBoxServicePropCacheUpdate(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/OS/NoLoggedInUsers",
     280                                   cUsersInList == 0 ? "true" : "false");
    270281        g_cVMInfoLoggedInUsers = cUsersInList;
    271282    }
    272     if (pszUserList)
     283    if (RT_SUCCESS(rc) && pszUserList)
    273284        RTStrFree(pszUserList);
    274285    return VINF_SUCCESS;
     
    279290 * Provide information about the guest network.
    280291 */
    281 int VBoxServiceVMInfoWriteNetwork()
    282 {
    283     int cIfacesReport = 0;
    284     char szPropPath [FILENAME_MAX];
     292static int vboxserviceVMInfoWriteNetwork(void)
     293{
     294    int  cIfacesReport = 0;
     295    char szPropPath[256];
    285296
    286297#ifdef RT_OS_WINDOWS
     
    289300# ifndef TARGET_NT4
    290301    ULONG cbAdpInfo = sizeof(*pAdpInfo);
    291     pAdpInfo = (IP_ADAPTER_INFO*)RTMemAlloc(cbAdpInfo);
     302    pAdpInfo = (IP_ADAPTER_INFO *)RTMemAlloc(cbAdpInfo);
    292303    if (!pAdpInfo)
    293304    {
     
    521532            return RTErrConvertFromErrno(errno);
    522533        }
    523  #if defined(RT_OS_OS2) || defined(RT_OS_SOLARIS)
     534# if defined(RT_OS_OS2) || defined(RT_OS_SOLARIS)
    524535        pAddress = (sockaddr_in *)&ifrequest[i].ifr_addr;
    525  #else
     536# else
    526537        pAddress = (sockaddr_in *)&ifrequest[i].ifr_netmask;
    527  #endif
     538# endif
    528539
    529540        RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%d/V4/Netmask", cIfacesReport);
    530541        VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", inet_ntoa(pAddress->sin_addr));
    531542
    532  #if defined(RT_OS_SOLARIS)
     543# if defined(RT_OS_SOLARIS)
    533544        if (ioctl(sd, SIOCGENADDR, &ifrequest[i]) < 0)
    534  #else
     545# else
    535546        if (ioctl(sd, SIOCGIFHWADDR, &ifrequest[i]) < 0)
    536  #endif
     547# endif
    537548        {
    538549            VBoxServiceError("VMInfo/Network: Failed to ioctl(SIOCGIFHWADDR) on socket: Error %d\n", errno);
     
    542553
    543554        char szMac[32];
    544  #if defined(RT_OS_SOLARIS)
     555# if defined(RT_OS_SOLARIS)
    545556        uint8_t *pu8Mac = (uint8_t*)&ifrequest[i].ifr_enaddr[0];
    546  #else
     557# else
    547558        uint8_t *pu8Mac = (uint8_t*)&ifrequest[i].ifr_hwaddr.sa_data[0];
    548  #endif
     559# endif
    549560        RTStrPrintf(szMac, sizeof(szMac), "%02X%02X%02X%02X%02X%02X",
    550561                    pu8Mac[0], pu8Mac[1], pu8Mac[2], pu8Mac[3],  pu8Mac[4], pu8Mac[5]);
     
    591602    WSADATA wsaData;
    592603    if (WSAStartup(MAKEWORD(2, 2), &wsaData))
    593         VBoxServiceError("VMInfo/Users: WSAStartup failed! Error: %Rrc\n", RTErrConvertFromWin32(WSAGetLastError()));
     604        VBoxServiceError("VMInfo/Network: WSAStartup failed! Error: %Rrc\n", RTErrConvertFromWin32(WSAGetLastError()));
    594605#endif /* RT_OS_WINDOWS */
    595606
     
    597608     * Write the fixed properties first.
    598609     */
    599     VBoxServiceVMInfoWriteFixedProperties();
     610    vboxserviceVMInfoWriteFixedProperties();
    600611
    601612    /*
     
    604615    for (;;)
    605616    {
    606         rc = VBoxServiceVMInfoWriteUsers();
     617        rc = vboxserviceVMInfoWriteUsers();
    607618        if (RT_FAILURE(rc))
    608619            break;
    609620
    610         rc = VBoxServiceVMInfoWriteNetwork();
     621        rc = vboxserviceVMInfoWriteNetwork();
    611622        if (RT_FAILURE(rc))
    612623            break;
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