python-linux-procfs: - Fix traceback with non-utf8 chars

Fix traceback with non-utf8 chars

Resolves: rhbz#2022530
Signed-off-by: John Kacur <jkacur@redhat.com>
This commit is contained in:
John Kacur 2021-11-22 12:46:55 -05:00
parent e6dac818f5
commit 0ebf821b7e
2 changed files with 41 additions and 6 deletions

View File

@ -0,0 +1,33 @@
From 7570fc0d6082cb476c32233c2904214dd57737a8 Mon Sep 17 00:00:00 2001
From: John Kacur <jkacur@redhat.com>
Date: Fri, 19 Nov 2021 16:03:22 -0500
Subject: [PATCH] python-linux-procfs: Fix traceback with non-utf8 chars in the
/proc/PID/cmdline
Fix traceback if there are non-utf8 characters in the /proc/PID/cmdline
Signed-off-by: John Kacur <jkacur@redhat.com>
---
procfs/procfs.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/procfs/procfs.py b/procfs/procfs.py
index 3b7474cccb01..408b2bcd0a31 100755
--- a/procfs/procfs.py
+++ b/procfs/procfs.py
@@ -357,9 +357,9 @@ class process:
return hasattr(self, attr)
def load_cmdline(self):
- f = open("/proc/%d/cmdline" % self.pid)
- self.cmdline = f.readline().strip().split('\0')[:-1]
- f.close()
+ with open("/proc/%d/cmdline" % self.pid, mode='rb') as f:
+ cmdline = f.readline().decode(encoding='unicode_escape')
+ self.cmdline = cmdline.strip().split('\0')[:-1]
def load_threads(self):
self.threads = pidstats("/proc/%d/task/" % self.pid)
--
2.31.1

View File

@ -1,11 +1,6 @@
%if 0%{?fedora}
%else
%global without_python3 1
%endif
Name: python-linux-procfs
Version: 0.6.3
Release: 2%{?dist}
Release: 3%{?dist}
License: GPLv2
Summary: Linux /proc abstraction classes
URL: https://git.kernel.org/pub/scm/libs/python/%{name}/%{name}.git
@ -17,6 +12,9 @@ BuildRequires: python3-setuptools
%global _description\
Abstractions to extract information from the Linux kernel /proc files.
# PATCHES
Patch1: python-linux-procfs-Fix-traceback-with-non-utf8-char.patch
%description %_description
%package -n python3-linux-procfs
@ -46,6 +44,10 @@ rm -rf %{buildroot}
%license COPYING
%changelog
* Mon Nov 22 2021 John Kacur <jkacur@redhat.com> - 0.6.3-3
- Fix traceback with non-utf8 chars
Resolves: rhbz#2022530
* Tue Aug 10 2021 Mohan Boddu <mboddu@redhat.com> - 0.6.3-2
- Rebuilt for IMA sigs, glibc 2.34, aarch64 flags
Related: rhbz#1991688