Skip to content

Commit

Permalink
Merge branch 'master' of github.com:giampaolo/psutil
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Jul 26, 2022
2 parents c13017f + 04e7aa6 commit 63dec10
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
``min`` and ``max`` are in MHz.
- 2050_, [Linux]: `virtual_memory()`_ may raise ``ValueError`` if running in a
LCX container.
- 2095_, [Linux]: `net_if_stats()` returns incorrect interface speed for 100GbE
network cards

5.9.0
=====
Expand Down
11 changes: 10 additions & 1 deletion psutil/_psutil_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ psutil_net_if_duplex_speed(PyObject* self, PyObject* args) {
int sock = 0;
int ret;
int duplex;
__u32 uint_speed;
int speed;
struct ifreq ifr;
struct ethtool_cmd ethcmd;
Expand All @@ -438,7 +439,15 @@ psutil_net_if_duplex_speed(PyObject* self, PyObject* args) {

if (ret != -1) {
duplex = ethcmd.duplex;
speed = ethcmd.speed;
// speed is returned from ethtool as a __u32 ranging from 0 to INT_MAX
// or SPEED_UNKNOWN (-1)
uint_speed = ethtool_cmd_speed(&ethcmd);
if (uint_speed == (__u32)SPEED_UNKNOWN || uint_speed > INT_MAX) {
speed = 0;
}
else {
speed = (int)uint_speed;
}
}
else {
if ((errno == EOPNOTSUPP) || (errno == EINVAL)) {
Expand Down
2 changes: 1 addition & 1 deletion psutil/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ def _check_fds(self, fun):

def _call_ntimes(self, fun, times):
"""Get 2 distinct memory samples, before and after having
called fun repeadetly, and return the memory difference.
called fun repeatedly, and return the memory difference.
"""
gc.collect(generation=1)
mem1 = self._get_mem()
Expand Down

0 comments on commit 63dec10

Please sign in to comment.