psutil: RHEL 5.3 net_if_stats OSError

I am referring to the Google Groups post here: https://groups.google.com/forum/#!topic/psutil/Ld4Z00y1-DE

I have tested with psutil 3.1.1 and 3.4.2. The trace below is with psutil 3.1.1.

As requested, I inserted some printf()'s in the code, here’s the result:

$ sudo /usr/local/bin/python
Python 2.7.9 (default, Aug 10 2015, 20:17:05) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import psutil
>>> psutil.net_if_stats()
DEBUG0
DEBUG0.1
DEBUG1
DEBUG2
DEBUG3
DEBUG4
DEBUG5
DEBUG5.2.1
DEBUG5.3.1
DEBUG8
DEBUG9
DEBUG10
DEBUG11
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/psutil/__init__.py", line 1798, in net_if_stats
    return _psplatform.net_if_stats()
  File "/usr/local/lib/python2.7/site-packages/psutil/_pslinux.py", line 609, in net_if_stats
    isup, duplex, speed, mtu = cext.net_if_stats(name)
OSError: [Errno 22] Invalid argument
>>> quit()
$ cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 5.3 (Tikanga)

So execution goes into psutil_net_if_stats, goes inside:

    // duplex and speed
    memset(&ethcmd, 0, sizeof ethcmd);
    ethcmd.cmd = ETHTOOL_GSET;
    ifr.ifr_data = (caddr_t)&ethcmd;
    ret = ioctl(sock, SIOCETHTOOL, &ifr);

    printf("DEBUG5\n");

    if (ret != -1) {
        printf("DEBUG5.1.1\n");
        duplex = ethcmd.duplex;
        speed = ethcmd.speed;
        printf("DEBUG5.1.2\n");
    }
    else {
        printf("DEBUG5.2.1\n");
        if (errno == EOPNOTSUPP) {
            printf("DEBUG5.2.2\n");
            // we typically get here in case of wi-fi cards
            duplex = DUPLEX_UNKNOWN;
            speed = 0;
            printf("DEBUG5.2.3\n");
        }
        else {
            printf("DEBUG5.3.1\n");
            goto error;
        }
    }

Goes to error:

error:
    printf("DEBUG8\n");
    Py_XDECREF(py_is_up);
    printf("DEBUG9\n");
    if (sock != 0)
        close(sock);
    printf("DEBUG10\n");
    PyErr_SetFromErrno(PyExc_OSError);
    printf("DEBUG11\n");
    return NULL;
}

Returns NULL to _pslinux.py at isup, duplex, speed, mtu = cext.net_if_stats(name)

def net_if_stats():
    """Get NIC stats (isup, duplex, speed, mtu)."""
    duplex_map = {cext.DUPLEX_FULL: NIC_DUPLEX_FULL,
                  cext.DUPLEX_HALF: NIC_DUPLEX_HALF,
                  cext.DUPLEX_UNKNOWN: NIC_DUPLEX_UNKNOWN}
    names = net_io_counters().keys()
    ret = {}
    print "DEBUG0"
    for name in names:
        print "DEBUG0.1"
        isup, duplex, speed, mtu = cext.net_if_stats(name)
        print "DEBUG0.2"
        duplex = duplex_map[duplex]
        ret[name] = _common.snicstats(isup, duplex, speed, mtu)
    return ret

Please let me know if you would like me to try something else. Thanks!

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 19 (9 by maintainers)

Most upvoted comments

I see. Sorry. I can open a new issue if that would be preferable.

Yes please. I will think about whether it’s the case to turn that OSError into AccessDenied. With a ticket it’ll be more likely I won’t forget about it.