From: Tom Hromatka Date: Mon, 17 May 2021 14:04:37 +0000 (+0000) Subject: cgroup.py: Add support for cgexec X-Git-Tag: v2.0.3~11^2^2~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a93828a600090cd473ab5aac055feb15c2e41aa1;p=thirdparty%2Flibcgroup.git cgroup.py: Add support for cgexec Add support for cgexec to the Cgroup class. Signed-off-by: Tom Hromatka --- diff --git a/ftests/cgroup.py b/ftests/cgroup.py index 31e06bd7..32b9530e 100644 --- a/ftests/cgroup.py +++ b/ftests/cgroup.py @@ -783,3 +783,34 @@ class Cgroup(object): raise re return ret + + # exec is a keyword in python, so let's name this function cgexec + @staticmethod + def cgexec(config, controller, cgname, cmdline, sticky=False, + cghelp=False): + """cgexec equivalent method + """ + cmd = list() + + if not config.args.container: + cmd.append('sudo') + cmd.append(Cgroup.build_cmd_path('cgexec')) + cmd.append('-g') + cmd.append('{}:{}'.format(controller, cgname)) + + if sticky: + cmd.append('--sticky') + + if isinstance(cmdline, str): + cmd.append(cmdline) + elif isinstance(cmdline, list): + for entry in cmdline: + cmd.append(entry) + + if cghelp: + cmd.append('-h') + + if config.args.container: + return config.container.run(cmd, shell_bool=True) + else: + return Run.run(cmd, shell_bool=True)