Skip to content

Commit b88f4d8

Browse files
committed
fix #2138 (critical): re-define ethtool_cmd_speed
1 parent a3eca35 commit b88f4d8

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

HISTORY.rst

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ XXXX-XX-XX
99

1010
- 2135_, [macOS]: `Process.environ()`_ may contain garbage data. Fix
1111
out-of-bounds read around ``sysctl_procargs``. (patch by Bernhard Urban-Forster)
12+
- 2138_, [Linux], **[critical]**: can't compile psutil on Android due to
13+
undefined ``ethtool_cmd_speed`` symbol.
1214
- 2142_, [POSIX]: `net_if_stats()`_ 's ``flags`` on Python 2 returned unicode
1315
instead of str. (patch by Matthieu Darbois)
1416

psutil/_psutil_linux.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ ioprio_set(int which, int who, int ioprio) {
7373
return syscall(__NR_ioprio_set, which, who, ioprio);
7474
}
7575

76+
// defined in linux/ethtool.h but not always available (e.g. Android)
77+
static inline uint32_t
78+
psutil_ethtool_cmd_speed(const struct ethtool_cmd *ecmd) {
79+
return (ecmd->speed_hi << 16) | ecmd->speed;
80+
}
81+
7682
#define IOPRIO_CLASS_SHIFT 13
7783
#define IOPRIO_PRIO_MASK ((1UL << IOPRIO_CLASS_SHIFT) - 1)
7884

@@ -441,7 +447,7 @@ psutil_net_if_duplex_speed(PyObject* self, PyObject* args) {
441447
duplex = ethcmd.duplex;
442448
// speed is returned from ethtool as a __u32 ranging from 0 to INT_MAX
443449
// or SPEED_UNKNOWN (-1)
444-
uint_speed = ethtool_cmd_speed(&ethcmd);
450+
uint_speed = psutil_ethtool_cmd_speed(&ethcmd);
445451
if (uint_speed == (__u32)SPEED_UNKNOWN || uint_speed > INT_MAX) {
446452
speed = 0;
447453
}

0 commit comments

Comments
 (0)