Fix Linuxdisk io counters fails on Linux kernel

Signed-off-by: zhang-liang-pengkun <zhangliangpengkun@xfusion.com>
This commit is contained in:
zhang-liang-pengkun 2023-10-18 17:50:19 +08:00
parent 722208a5a4
commit be3abedfe0
2 changed files with 42 additions and 1 deletions

View File

@ -0,0 +1,37 @@
From 8f99f3782663959062ee868bbfdbc336307a3a4d Mon Sep 17 00:00:00 2001
From: Koen Kooi <koen@dominion.thruhere.net>
Date: Mon, 5 Nov 2018 15:17:16 +0000
Subject: [PATCH] Fix #1354 [Linux] disk_io_counters() fails on Linux kernel
4.18+ (#1360)
Linux kernel 4.18+ added 4 fields, ingore them and parse the rest as
usual.
---
psutil/_pslinux.py | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py
index b57adb3..764c95f 100644
--- a/psutil/_pslinux.py
+++ b/psutil/_pslinux.py
@@ -1051,6 +1051,8 @@ def disk_io_counters():
# ...unless (Linux 2.6) the line refers to a partition instead
# of a disk, in which case the line has less fields (7):
# "3 1 hda1 8 8 8 8"
+ # 4.18+ has 4 fields added:
+ # "3 0 hda 8 8 8 8 8 8 8 8 8 8 8 0 0 0 0"
# See:
# https://www.kernel.org/doc/Documentation/iostats.txt
# https://www.kernel.org/doc/Documentation/ABI/testing/procfs-diskstats
@@ -1062,7 +1064,7 @@ def disk_io_counters():
reads = int(fields[2])
(reads_merged, rbytes, rtime, writes, writes_merged,
wbytes, wtime, _, busy_time, _) = map(int, fields[4:14])
- elif fields_len == 14:
+ elif flen == 14 or flen == 18:
# Linux 2.6+, line referring to a disk
name = fields[2]
(reads, reads_merged, rbytes, rtime, writes, writes_merged,
--
2.39.0.windows.2

View File

@ -1,6 +1,6 @@
Name: python-psutil
Version: 5.4.3
Release: 9
Release: 10
Summary: A library for retrieving information on running processes and system utilization in Python
License: BSD
URL: https://github.com/giampaolo/psutil
@ -8,6 +8,7 @@ Source0: https://github.com/giampaolo/psutil/archive/release-%{version}.t
Patch0001: CVE-2019-18874-1.patch
Patch0002: CVE-2019-18874-2.patch
Patch0003: 0001-Fix-1354-Linux-disk_io_counters-fails-on-Linux-kerne.patch
BuildRequires: gcc python2-devel python3-devel procps-ng python2-mock python3-mock python2-ipaddress
@ -71,6 +72,9 @@ done
%{python3_sitearch}/*.egg-info
%changelog
* Wed Oct 18 2023 zhangliangpengkun<zhangliangpengkun@xfusion.com> - 5.4.3-10
- Fix Linuxdisk io counters fails on Linux kernel
* Wed Oct 20 2021 yaoxin <yaoxin30@huawei.com> - 5.4.3-9
- Fix CVE-2019-18874