summaryrefslogtreecommitdiff
path: root/psutil
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2022-07-26 20:58:47 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2022-07-26 20:58:47 +0200
commit63dec1015f6c28000f4cfe54d473ec2cc4c9e52e (patch)
treeec1c662c667142b7df9459500ebc92995f7a4c71 /psutil
parentc13017f04a721188f4da7822b503d9fad002805d (diff)
parent04e7aa604155736cce0abcc15c9b7b63d941b0e9 (diff)
downloadpsutil-63dec1015f6c28000f4cfe54d473ec2cc4c9e52e.tar.gz
Merge branch 'master' of github.com:giampaolo/psutil
Diffstat (limited to 'psutil')
-rw-r--r--psutil/_psutil_linux.c11
-rw-r--r--psutil/tests/__init__.py2
2 files changed, 11 insertions, 2 deletions
diff --git a/psutil/_psutil_linux.c b/psutil/_psutil_linux.c
index 70cf5d1b..c59050cb 100644
--- a/psutil/_psutil_linux.c
+++ b/psutil/_psutil_linux.c
@@ -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;
@@ -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)) {
diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py
index 16477129..6b40fdc6 100644
--- a/psutil/tests/__init__.py
+++ b/psutil/tests/__init__.py
@@ -1003,7 +1003,7 @@ class TestMemoryLeak(PsutilTestCase):
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()