es-que / cpuset

Automatically exported from code.google.com/p/cpuset
GNU General Public License v2.0
0 stars 0 forks source link

-verbose unable to parse PIDs with space-separated names #14

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. cset shield --unshield -v
2. IndexError: list index out of range

What is the expected output? What do you see instead?
Expected output is the verbose listing of the --shield/--unshield results. The 
following results appear instead:
-bash-4.2# ./cset shield --unshield -v
Traceback (most recent call last):
  File "./cset", line 47, in <module>
    main()
  File "/root/cpuset-1.5.6/cpuset/main.py", line 228, in main
    command.func(parser, options, args)
  File "/root/cpuset-1.5.6/cpuset/commands/shield.py", line 291, in func
    print_stats()
  File "/root/cpuset-1.5.6/cpuset/commands/shield.py", line 315, in print_sys_stats
    proc.log_detailed_task_table(cset.unique_set(SYS_SET), '   ', 76)
  File "/root/cpuset-1.5.6/cpuset/commands/proc.py", line 790, in log_detailed_task_table
    l.extend(task_detail_table(set.tasks, indent, width))
  File "/root/cpuset-1.5.6/cpuset/commands/proc.py", line 779, in task_detail_table
    if width: l.append(istr + task_detail(task, width))
  File "/root/cpuset-1.5.6/cpuset/commands/proc.py", line 733, in task_detail
    out2.append(policy[int(stat[statdef['rtpolicy']])])
IndexError: list index out of range

What version of the product are you using? On what operating system?
-bash-4.2# ./cset --version
cset: Cpuset (cset) 1.5.6

-bash-4.2# uname -a
Linux x86p3 2.6.33-ts-i686 #3 SMP PREEMPT RT Wed Mar 7 16:14:53 PST 2012 i686 
GNU/Linux

Please provide any additional information below.
The reason this fails is because the /proc/<pid>/stat parsing logic doesn't 
take into account that the "comm" field (2nd element) may contain spaces. This 
field is enclosed in parethensis (e.g., "(task 1)") and when PID names contain 
spaces the proc.py::task_detail statdef array becomes mis-aligned (i.e., "(task 
1)" becomes "(task" "1)" in the stat array).

Original issue reported on code.google.com by david.a....@gmail.com on 23 May 2012 at 7:18

GoogleCodeExporter commented 8 years ago
This also happens when using cset proc <set name>.

# cset proc user
Traceback (most recent call last):
  File "/usr/bin/cset", line 47, in <module>
    main()
  File "/usr/lib/python2.7/site-packages/cpuset/main.py", line 228, in main
    command.func(parser, options, args)
  File "/usr/lib/python2.7/site-packages/cpuset/commands/proc.py", line 317, in func
    list_sets(args)
  File "/usr/lib/python2.7/site-packages/cpuset/commands/proc.py", line 347, in list_sets
    log_detailed_task_table(s, ' ', 78)
  File "/usr/lib/python2.7/site-packages/cpuset/commands/proc.py", line 787, in log_detailed_task_table
    l.extend(task_detail_table(set.tasks, indent, width))
  File "/usr/lib/python2.7/site-packages/cpuset/commands/proc.py", line 776, in task_detail_table
    if width: l.append(istr + task_detail(task, width))
  File "/usr/lib/python2.7/site-packages/cpuset/commands/proc.py", line 730, in task_detail
    out2.append(policy[int(stat[statdef['rtpolicy']])])
IndexError: list index out of range

Original comment by possu...@gmail.com on 13 Aug 2013 at 6:43