Blame SOURCES/python-linux-procfs-pflags-Handle-pids-that-complete.patch

21ad0d
From eb984b30e325bbf27844bf9c1f90767504468db5 Mon Sep 17 00:00:00 2001
21ad0d
From: John Kacur <jkacur@redhat.com>
21ad0d
Date: Tue, 23 Nov 2021 13:01:05 -0500
21ad0d
Subject: [PATCH 2/3] python-linux-procfs: pflags: Handle pids that completed
21ad0d
21ad0d
Sometimes pids disappear when they are completed.
21ad0d
21ad0d
Programs such as pflags that use procfs must account for that.
21ad0d
The solution is to simply recognize this situation, and to continue.
21ad0d
21ad0d
Signed-off-by: John Kacur <jkacur@redhat.com>
21ad0d
---
21ad0d
 pflags | 15 +++++++++++++--
21ad0d
 1 file changed, 13 insertions(+), 2 deletions(-)
21ad0d
21ad0d
diff --git a/pflags b/pflags
21ad0d
index 3407b6f51c96..46d396c87c2b 100755
21ad0d
--- a/pflags
21ad0d
+++ b/pflags
21ad0d
@@ -50,14 +50,25 @@ def main(argv):
21ad0d
         pids = list(ps.processes.keys())
21ad0d
 
21ad0d
     pids.sort()
21ad0d
-    len_comms = [len(ps[pid]["stat"]["comm"]) for pid in pids if pid in ps]
21ad0d
+    len_comms = []
21ad0d
+    for pid in pids:
21ad0d
+        if pid in ps:
21ad0d
+            try:
21ad0d
+                len(ps[pid]["stat"]["comm"])
21ad0d
+            except (TypeError, FileNotFoundError):
21ad0d
+                continue
21ad0d
+            len_comms.append(len(ps[pid]["stat"]["comm"]))
21ad0d
+
21ad0d
     max_comm_len = max(len_comms, default=0)
21ad0d
     del len_comms
21ad0d
 
21ad0d
     for pid in pids:
21ad0d
         if pid not in ps:
21ad0d
             continue
21ad0d
-        flags = ps[pid].stat.process_flags()
21ad0d
+        try:
21ad0d
+            flags = ps[pid].stat.process_flags()
21ad0d
+        except AttributeError:
21ad0d
+            continue
21ad0d
         # Remove flags that were superseeded
21ad0d
         if "PF_THREAD_BOUND" in flags and "PF_NO_SETAFFINITY" in flags:
21ad0d
             flags.remove("PF_THREAD_BOUND")
21ad0d
-- 
21ad0d
2.31.1
21ad0d