Public bug reported:

cpuset package in focal has a bug in the "set" subcommand.

The bug
------------------

Docker file used to reproduce:
-----
FROM ubuntu:focal

RUN apt update && apt install -y cpuset python3-future
-----


Reproducing the bug

-----

$ docker run --privileged --rm -it csettest bash

root@7a6d182dc51d:/# cset set -c 0 shrtnm
cset: --> created cpuset "shrtnm"
root@7a6d182dc51d:/# cset set -l
cset:
         Name       CPUs-X    MEMs-X Tasks Subs Path
 ------------ ---------- - ------- - ----- ---- ----------
         root        0-3 n       0 n     2    1 /
       shrtnm          0 n       0 n     0    0 /shrtnm
root@7a6d182dc51d:/# cset set -c 0 shortname
cset: --> created cpuset "shortname"
root@7a6d182dc51d:/# cset set -l
cset:
         Name       CPUs-X    MEMs-X Tasks Subs Path
 ------------ ---------- - ------- - ----- ---- ----------
         root        0-3 n       0 n     2    2 /
    shortname          0 n       0 n     0    0 /shortname
       shrtnm          0 n       0 n     0    0 /shrtnm
root@7a6d182dc51d:/# cset set -c 0 looooongname
cset: --> created cpuset "looooongname"
root@7a6d182dc51d:/# cset set -l
cset:
         Name       CPUs-X    MEMs-X Tasks Subs Path
 ------------ ---------- - ------- - ----- ---- ----------
         root        0-3 n       0 n     2    3 /
    shortname          0 n       0 n     0    0 /shortname
 looooongname          0 n       0 n     0    0 /looooongname
       shrtnm          0 n       0 n     0    0 /shrtnm
root@7a6d182dc51d:/# cset set -c 0 looooongnameeeeeeeeeeeeeeee
cset: --> created cpuset "looooongnameeeeeeeeeeeeeeee"
root@7a6d182dc51d:/# cset set -l
Traceback (most recent call last):
  File "/usr/bin/cset", line 47, in <module>
    main()
  File "/usr/lib/python3/dist-packages/cpuset/main.py", line 234, in main
    command.func(parser, options, args)
  File "/usr/lib/python3/dist-packages/cpuset/commands/set.py", line 186, in 
func
    else: list_sets('root', options.recurse, options.usehex)
  File "/usr/lib/python3/dist-packages/cpuset/commands/set.py", line 243, in 
list_sets
    pl.append(set_details(s,' ', 78, usehex))
  File "/usr/lib/python3/dist-packages/cpuset/commands/set.py", line 487, in 
set_details
    pathb = set.path[len(set.path//2):]
TypeError: unsupported operand type(s) for //: 'str' and 'int'

-----

Seems like the issue surfaces once the cpuset name get long enough.


Possible fix
------------------

This patch seems to resolve the issue
-----
 commands/set.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/commands/set.py b/commands/set.py
index c71f37f..7d0d382 100644
--- a/commands/set.py
+++ b/commands/set.py
@@ -484,7 +484,7 @@ def set_details(name, indent=None, width=None, 
usehex=False):
     if width != 0 and len(tst) > width:
         target = width - len(out)
         patha = set.path[:len(set.path)//2-3]
-        pathb = set.path[len(set.path//2):]
+        pathb = set.path[len(set.path)//2:]
         patha = patha[:target//2-3]
         pathb = pathb[-target//2:]
         out += patha + '...' + pathb
--
2.25.1
-----

After applying the patch:
-----
$ cset set -l

cset:
         Name       CPUs-X    MEMs-X Tasks Subs Path
 ------------ ---------- - ------- - ----- ---- ----------
         root        0-3 n       0 n     2    4 /
    shortname          0 n       0 n     0    0 /shortname
 looooongnameeeeeeeeeeeeeeee          0 n       0 n     0    0 /looo...eeeeeeee
 looooongname          0 n       0 n     0    0 /looooongname
       shrtnm          0 n       0 n     0    0 /shrtnm
-----
------------------

** Affects: cpuset (Ubuntu)
     Importance: Undecided
         Status: New


** Tags: focal

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1907891

Title:
  python TypeError when listing long cgroup names

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/cpuset/+bug/1907891/+subscriptions

-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to