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

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