Blame SOURCES/tuna-Use-errno-codes-instead-of-numbers.patch

59a996
From 876beba81c6b213e0fe4755409142cddb78e344d Mon Sep 17 00:00:00 2001
59a996
From: John Kacur <jkacur@redhat.com>
59a996
Date: Tue, 12 Sep 2017 23:35:39 +0100
59a996
Subject: [PATCH 1/2] tuna: Use errno codes instead of numbers
59a996
59a996
Use errno codes instead of numbers since they
59a996
are self documenting.
59a996
59a996
Simplify the comments as a result
59a996
59a996
Signed-off-by: John Kacur <jkacur@redhat.com>
59a996
---
59a996
 tuna-cmd.py  | 12 +++++-----
59a996
 tuna/tuna.py | 78 ++++++++++++++++++++++++++++++------------------------------
59a996
 2 files changed, 45 insertions(+), 45 deletions(-)
59a996
59a996
diff --git a/tuna-cmd.py b/tuna-cmd.py
59a996
index 39666c7c77f1..f0c5c0662ebd 100755
59a996
--- a/tuna-cmd.py
59a996
+++ b/tuna-cmd.py
59a996
@@ -14,7 +14,7 @@
59a996
 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
59a996
 #   General Public License for more details.
59a996
 
59a996
-import getopt, ethtool, fnmatch, os, procfs, re, schedutils, sys
59a996
+import getopt, ethtool, fnmatch, errno, os, procfs, re, schedutils, sys
59a996
 from tuna import tuna, sysfs
59a996
 
59a996
 import gettext
59a996
@@ -180,8 +180,8 @@ def ps_show_thread(pid, affect_children, ps,
59a996
 	global irqs
59a996
 	try:
59a996
 		affinity = format_affinity(schedutils.get_affinity(pid))
59a996
-	except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
59a996
-		if e[0] == 3:
59a996
+	except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
59a996
+		if e[0] == errno.ESRCH:
59a996
 			return
59a996
 		raise e
59a996
 
59a996
@@ -262,8 +262,8 @@ def ps_show(ps, affect_children, thread_list, cpu_list,
59a996
 			continue
59a996
 		try:
59a996
 			affinity = schedutils.get_affinity(pid)
59a996
-		except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
59a996
-			if e[0] == 3:
59a996
+		except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
59a996
+			if e[0] == errno.ESRCH:
59a996
 				continue
59a996
 			raise e
59a996
 		if cpu_list and not set(cpu_list).intersection(set(affinity)):
59a996
@@ -558,7 +558,7 @@ def main():
59a996
 			else:
59a996
 				try:
59a996
 					tuna.threads_set_priority(thread_list, a, affect_children)
59a996
-				except (SystemError, OSError) as err: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
59a996
+				except (SystemError, OSError) as err: # old python-schedutils incorrectly raised SystemError
59a996
 					print "tuna: %s" % err
59a996
 					sys.exit(2)
59a996
 		elif o in ("-P", "--show_threads"):
59a996
diff --git a/tuna/tuna.py b/tuna/tuna.py
59a996
index 9aab16a409d2..562c7fcf92d9 100755
59a996
--- a/tuna/tuna.py
59a996
+++ b/tuna/tuna.py
59a996
@@ -1,7 +1,7 @@
59a996
 # -*- python -*-
59a996
 # -*- coding: utf-8 -*-
59a996
 
59a996
-import copy, ethtool, os, procfs, re, schedutils, sys, shlex
59a996
+import copy, ethtool, errno, os, procfs, re, schedutils, sys, shlex
59a996
 import help, fnmatch
59a996
 from procfs import utilist
59a996
 
59a996
@@ -209,8 +209,8 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning = None,
59a996
 		try:
59a996
 			try:
59a996
 				curr_affinity = schedutils.get_affinity(pid)
59a996
-			except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
59a996
-				if e[0] == 3: # 'No such process'
59a996
+			except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
59a996
+				if e[0] == errno.ESRCH:
59a996
 					continue
59a996
 				curr_affinity = None
59a996
 				raise e
59a996
@@ -218,8 +218,8 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning = None,
59a996
 				try:
59a996
 					schedutils.set_affinity(pid, new_affinity)
59a996
 					curr_affinity = schedutils.get_affinity(pid)
59a996
-				except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
59a996
-					if e[0] == 3: # 'No such process'
59a996
+				except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
59a996
+					if e[0] == errno.ESRCH:
59a996
 						continue
59a996
 					curr_affinity == None
59a996
 					raise e
59a996
@@ -247,16 +247,16 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning = None,
59a996
 			for tid in threads.keys():
59a996
 				try:
59a996
 					curr_affinity = schedutils.get_affinity(tid)
59a996
-				except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
59a996
-					if e[0] == 3:
59a996
+				except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
59a996
+					if e[0] == errno.ESRCH:
59a996
 						continue
59a996
 					raise e
59a996
 				if set(curr_affinity) != set(new_affinity):
59a996
 					try:
59a996
 						schedutils.set_affinity(tid, new_affinity)
59a996
 						curr_affinity = schedutils.get_affinity(tid)
59a996
-					except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
59a996
-						if e[0] == 3:
59a996
+					except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
59a996
+						if e[0] == errno.ESRCH:
59a996
 							continue
59a996
 						raise e
59a996
 					if set(curr_affinity) == set(new_affinity):
59a996
@@ -267,12 +267,12 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning = None,
59a996
 						print "move_threads_to_cpu: %s " % \
59a996
 						      (_("could not change %(pid)d affinity to %(new_affinity)s") % \
59a996
 						       {'pid':pid, 'new_affinity':new_affinity})
59a996
-		except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
59a996
-			if e[0] == 3:
59a996
+		except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
59a996
+			if e[0] == errno.ESRCH:
59a996
 				# process died
59a996
 				continue
59a996
-			elif e[0] == 22: # (22, EINVAL - unmovable thread)
59a996
-				print "thread %(pid)d cannot be moved as requested" %{'pid':pid}
59a996
+                        elif e[0] == errno.EINVAL: # unmovable thread)
59a996
+				print >> stderr, "thread %(pid)d cannot be moved as requested" %{'pid':pid}
59a996
 				continue
59a996
 			raise e
59a996
 	return changed
59a996
@@ -317,8 +317,8 @@ def move_irqs_to_cpu(cpus, irq_list, spread = False):
59a996
 			pid = int(pid[0])
59a996
 			try:
59a996
 				schedutils.set_affinity(pid, new_affinity)
59a996
-			except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
59a996
-				if e[0] == 3:
59a996
+			except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
59a996
+				if e[0] == errno.ESRCH:
59a996
 					unprocessed.append(i)
59a996
 					changed -= 1
59a996
 					continue
59a996
@@ -351,8 +351,8 @@ def isolate_cpus(cpus, nr_cpus):
59a996
 			continue
59a996
 		try:
59a996
 			affinity = schedutils.get_affinity(pid)
59a996
-		except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
59a996
-			if e[0] == 3:
59a996
+		except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
59a996
+			if e[0] == errno.ESRCH:
59a996
 				continue
59a996
 			raise e
59a996
 		if set(affinity).intersection(set(cpus)):
59a996
@@ -360,8 +360,8 @@ def isolate_cpus(cpus, nr_cpus):
59a996
 			affinity = affinity_remove_cpus(affinity, cpus, nr_cpus)
59a996
 			try:
59a996
 				schedutils.set_affinity(pid, affinity)
59a996
-			except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
59a996
-				if e[0] == 3:
59a996
+			except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
59a996
+				if e[0] == errno.ESRCH:
59a996
 					continue
59a996
 				raise e
59a996
 
59a996
@@ -373,8 +373,8 @@ def isolate_cpus(cpus, nr_cpus):
59a996
 				continue
59a996
 			try:
59a996
 				affinity = schedutils.get_affinity(tid)
59a996
-			except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
59a996
-				if e[0] == 3:
59a996
+			except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
59a996
+				if e[0] == errno.ESRCH:
59a996
 					continue
59a996
 				raise e
59a996
 			if set(affinity).intersection(set(cpus)):
59a996
@@ -382,8 +382,8 @@ def isolate_cpus(cpus, nr_cpus):
59a996
 				affinity = affinity_remove_cpus(affinity, cpus, nr_cpus)
59a996
 				try:
59a996
 					schedutils.set_affinity(tid, affinity)
59a996
-				except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
59a996
-					if e[0] == 3:
59a996
+				except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
59a996
+					if e[0] == errno.ESRCH:
59a996
 						continue
59a996
 					raise e
59a996
 
59a996
@@ -419,8 +419,8 @@ def include_cpus(cpus, nr_cpus):
59a996
 			continue
59a996
 		try:
59a996
 			affinity = schedutils.get_affinity(pid)
59a996
-		except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
59a996
-			if e[0] == 3:
59a996
+		except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
59a996
+			if e[0] == errno.ESRCH:
59a996
 				continue
59a996
 			raise e
59a996
 		if set(affinity).intersection(set(cpus)) != set(cpus):
59a996
@@ -428,8 +428,8 @@ def include_cpus(cpus, nr_cpus):
59a996
 			affinity = list(set(affinity + cpus))
59a996
 			try:
59a996
 				schedutils.set_affinity(pid, affinity)
59a996
-			except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
59a996
-				if e[0] == 3:
59a996
+			except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
59a996
+				if e[0] == errno.ESRCH:
59a996
 					continue
59a996
 				raise e
59a996
 
59a996
@@ -441,8 +441,8 @@ def include_cpus(cpus, nr_cpus):
59a996
 				continue
59a996
 			try:
59a996
 				affinity = schedutils.get_affinity(tid)
59a996
-			except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
59a996
-				if e[0] == 3:
59a996
+			except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
59a996
+				if e[0] == errno.ESRCH:
59a996
 					continue
59a996
 				raise e
59a996
 			if set(affinity).intersection(set(cpus)) != set(cpus):
59a996
@@ -450,8 +450,8 @@ def include_cpus(cpus, nr_cpus):
59a996
 				affinity = list(set(affinity + cpus))
59a996
 				try:
59a996
 					schedutils.set_affinity(tid, affinity)
59a996
-				except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
59a996
-					if e[0] == 3:
59a996
+				except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
59a996
+					if e[0] == errno.ESRCH:
59a996
 						continue
59a996
 					raise e
59a996
 
59a996
@@ -518,8 +518,8 @@ def thread_filtered(tid, cpus_filtered, show_kthreads, show_uthreads):
59a996
 	if cpus_filtered:
59a996
 		try:
59a996
 			affinity = schedutils.get_affinity(tid)
59a996
-		except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
59a996
-			if e[0] == 3:
59a996
+		except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
59a996
+			if e[0] == errno.ESRCH:
59a996
 				return False
59a996
 			raise e
59a996
 
59a996
@@ -557,8 +557,8 @@ def threads_set_priority(tids, parm, affect_children = False):
59a996
 	for tid in tids:
59a996
 		try:
59a996
 			thread_set_priority(tid, policy, rtprio)
59a996
-		except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
59a996
-			if e[0] == 3:
59a996
+		except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
59a996
+			if e[0] == errno.ESRCH:
59a996
 				continue
59a996
 			raise e
59a996
 		if affect_children:
59a996
@@ -566,8 +566,8 @@ def threads_set_priority(tids, parm, affect_children = False):
59a996
 				if child != tid:
59a996
 					try:
59a996
 						thread_set_priority(child, policy, rtprio)
59a996
-					except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
59a996
-						if e[0] == 3:
59a996
+					except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
59a996
+						if e[0] == errno.ESRCH:
59a996
 							continue
59a996
 						raise e
59a996
 
59a996
@@ -597,8 +597,8 @@ def get_kthread_sched_tunings(proc = None):
59a996
 			try:
59a996
 				policy = schedutils.get_scheduler(pid)
59a996
 				affinity = schedutils.get_affinity(pid)
59a996
-			except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
59a996
-				if e[0] == 3:
59a996
+			except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
59a996
+				if e[0] == errno.ESRCH:
59a996
 					continue
59a996
 				raise e
59a996
 			percpu = iskthread(pid) and \
59a996
-- 
59a996
2.9.5
59a996