Hide Forgot
+++ This bug was initially created as a clone of Bug #1035793 +++ Description of problem: when after scheduler is not specified priority 'tuna -t $PID -p OTHER' (it doesn't matter if RR or FIFO or OTHER), tuna ends with traceback. Version-Release number of selected component (if applicable): every How reproducible: alway Steps to Reproduce: 1. install tuna 2. run tuna -t PID_OF_SOME_PROCESS -p OTHER 3. check output Actual results: [root@localhost ~]# tuna -t 3199 -p OTHER Traceback (most recent call last): File "/usr/bin/tuna", line 598, in <module> main() File "/usr/bin/tuna", line 482, in main tuna.threads_set_priority(thread_list, a, affect_children) File "/usr/lib/python2.6/site-packages/tuna/tuna.py", line 479, in threads_set_priority rtprio = int(parms[0]) ValueError: invalid literal for int() with base 10: 'OTHER' Expected results: instead of traceback some warning and/or used some default value. Additional info:
Created attachment 831472 [details] Fix
Fixed in 0.10.4-5
What do you guys think about this patch? Is this what we want for parameter verification? diff --git a/tuna/tuna.py b/tuna/tuna.py index 507269a..6fdeb9e 100755 --- a/tuna/tuna.py +++ b/tuna/tuna.py @@ -471,15 +471,18 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning = None, def threads_set_priority(tids, parm, affect_children = False): parms = parm.split(":") + rtprio = -1 policy = None - if len(parms) != 1: + if parms[0].upper() in ["OTHER", "BATCH", "IDLE", "FIFO", "RR", "IDLE", "RESET_ON_FORK"]: policy = schedutils.schedfromstr("SCHED_%s" % parms[0].upper()) - rtprio = int(parms[1]) - elif parms[0].isdigit(): - rtprio = int(parms[0]) - else: - print "tuna: " + _("\"%s\" is unsupported priority value!") % parms[0] - return + if len(parms) > 1: + if parms[1].isdigit(): + rtprio = int(parms[1]) + else: + print "tuna: " + _("\"%s\" is unsupported priority value!") % parms[1] + return + else: + rtprio = 0 for tid in tids: try:
Here's an updated patch that uses a try/except (to be a bit more python-ish): diff --git a/tuna/tuna.py b/tuna/tuna.py index 507269a..7e71348 100755 --- a/tuna/tuna.py +++ b/tuna/tuna.py @@ -471,15 +471,16 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning = None, def threads_set_priority(tids, parm, affect_children = False): parms = parm.split(":") + rtprio = 0 policy = None - if len(parms) != 1: - policy = schedutils.schedfromstr("SCHED_%s" % parms[0].upper()) - rtprio = int(parms[1]) - elif parms[0].isdigit(): - rtprio = int(parms[0]) - else: - print "tuna: " + _("\"%s\" is unsupported priority value!") % parms[0] - return + if parms[0].upper() in ["OTHER", "BATCH", "IDLE", "FIFO", "RR", "IDLE", "RESET_ON_FORK"]: + policy = schedutils.schedfromstr("SCHED_%s" % parms[0].upper()) + if len(parms) > 1: + try: + rtprio = int(parms[1]) + except ValueError, e: + print "tuna: " + _("\"%s\" is unsupported priority value!") % parms[1] + raise e for tid in tids: try:
In addition to the fix here which I provided in tuna-0.10.4-7 we need to upgrade procfs to python-linux-procfs-0.4.6-1 Then you get the following result which I believe is acceptable tuna -t $$ -p FIFO tuna: [Errno 22] Invalid argument I created https://bugzilla.redhat.com/show_bug.cgi?id=1035795 to handle this
Since the problem described in this bug report should be resolved in a recent advisory, it has been closed with a resolution of ERRATA. For information on the advisory, and where to find the updated files, follow the link below. If the solution does not work for you, open a new bug report. http://rhn.redhat.com/errata/RHBA-2014-1404.html