VirtualBox

Ignore:
Timestamp:
Oct 17, 2012 12:24:13 PM (12 years ago)
Author:
vboxsync
Message:

Main/Metrics: Fix for file descriptor leak in getInterfaceInfo()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/linux/NetIf-linux.cpp

    r43538 r43668  
    150150        }
    151151        /*
    152          * I wish I could do simple ioctl here, but older kernels require root
    153          * privileges for any ethtool commands.
     152         * Don't even try to get speed for non-Ethernet interfaces, it only
     153         * produces errors.
    154154         */
    155         char szBuf[256];
    156         /* First, we try to retrieve the speed via sysfs. */
    157         RTStrPrintf(szBuf, sizeof(szBuf), "/sys/class/net/%s/speed", pszName);
    158         fp = fopen(szBuf, "r");
    159         if (fp && fscanf(fp, "%u", &pInfo->uSpeedMbits) == 1)
    160             fclose(fp);
    161         else
    162         {
    163             /* Failed to get speed via sysfs, go to plan B. */
    164             int rc = NetIfAdpCtlOut(pszName, "speed", szBuf, sizeof(szBuf));
    165             if (RT_SUCCESS(rc))
    166                 pInfo->uSpeedMbits = RTStrToUInt32(szBuf);
    167             else
    168                 pInfo->uSpeedMbits = 0;
     155        pInfo->uSpeedMbits = 0;
     156        if (pInfo->enmMediumType == NETIF_T_ETHERNET)
     157        {
     158            /*
     159             * I wish I could do simple ioctl here, but older kernels require root
     160             * privileges for any ethtool commands.
     161             */
     162            char szBuf[256];
     163            /* First, we try to retrieve the speed via sysfs. */
     164            RTStrPrintf(szBuf, sizeof(szBuf), "/sys/class/net/%s/speed", pszName);
     165            fp = fopen(szBuf, "r");
     166            if (fp)
     167            {
     168                if (fscanf(fp, "%u", &pInfo->uSpeedMbits) != 1)
     169                    pInfo->uSpeedMbits = 0;
     170                fclose(fp);
     171            }
     172            if (pInfo->uSpeedMbits == 0)
     173            {
     174                /* Failed to get speed via sysfs, go to plan B. */
     175                int rc = NetIfAdpCtlOut(pszName, "speed", szBuf, sizeof(szBuf));
     176                if (RT_SUCCESS(rc))
     177                    pInfo->uSpeedMbits = RTStrToUInt32(szBuf);
     178            }
    169179        }
    170180    }
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