Blame SOURCES/tuna-Fix-show_threads-cgroups-run-without-a-term.patch

f312f6
From 4ccef8c2996e59e7031e77d7f8e2b42b73036210 Mon Sep 17 00:00:00 2001
f312f6
From: Leah Leshchinsky <lleshchi@redhat.com>
f312f6
Date: Wed, 23 Nov 2022 14:14:36 -0500
f312f6
Subject: [PATCH] tuna: Fix show_threads --cgroups run without a term
f312f6
f312f6
When tuna show_threads --cgroups is run without a term,
f312f6
provide a default column size of 80 to fix a traceback
f312f6
that occurred when querying the terminal size.
f312f6
f312f6
Signed-off-by: Leah Leshchinsky <lleshchi@redhat.com>
f312f6
- Edited the commit title
f312f6
- Edited the description
f312f6
Signed-off-by: John Kacur <jkacur@redhat.com>
f312f6
f312f6
diff --git a/tuna-cmd.py b/tuna-cmd.py
f312f6
index 630c8bc..4e809dd 100755
f312f6
--- a/tuna-cmd.py
f312f6
+++ b/tuna-cmd.py
f312f6
@@ -31,6 +31,7 @@ import procfs
f312f6
 from tuna import tuna, sysfs
f312f6
 import logging
f312f6
 import time
f312f6
+import shutil
f312f6
 
f312f6
 def get_loglevel(level):
f312f6
     if level.isdigit() and int(level) in range(0,5):
f312f6
@@ -440,9 +441,10 @@ def ps_show(ps, affect_children, thread_list, cpu_list,
f312f6
 
f312f6
 
f312f6
     # Width of terminal in columns
f312f6
-    columns = None
f312f6
+    columns = 80
f312f6
     if cgroups:
f312f6
-        _, columns = os.popen('stty size', 'r').read().split()
f312f6
+        if os.isatty(sys.stdout.fileno()):
f312f6
+            columns = shutil.get_terminal_size().columns
f312f6
 
f312f6
     for pid in ps_list:
f312f6
         ps_show_thread(pid, affect_children, ps, has_ctxt_switch_info,
f312f6
-- 
f312f6
2.38.1
f312f6