1
0
mirror of https://github.com/ARM-software/devlib.git synced 2025-01-31 10:10:46 +00:00

module/cgroups: Execute command as root when launching cmd in cgroup

On some devices root is required to configure cgroups therefore run the
command as root if available unless otherwise specified.
This commit is contained in:
Marc Bonnici 2018-12-05 16:02:55 +00:00 committed by setrofim
parent 22a5945460
commit f1b7fd184a

View File

@ -432,16 +432,20 @@ class CgroupsModule(Module):
.format(self.cgroup_root, self.target.shutils, .format(self.cgroup_root, self.target.shutils,
cgroup, cmdline) cgroup, cmdline)
def run_into(self, cgroup, cmdline): def run_into(self, cgroup, cmdline, as_root=None):
""" """
Run the specified command into the specified CGroup Run the specified command into the specified CGroup
:param cmdline: Command to be run into cgroup :param cmdline: Command to be run into cgroup
:param cgroup: Name of cgroup to run command into :param cgroup: Name of cgroup to run command into
:param as_root: Specify whether to run the command as root, if not
specified will default to whether the target is rooted.
:returns: Output of command. :returns: Output of command.
""" """
if as_root is None:
as_root = self.target.is_rooted
cmd = self.run_into_cmd(cgroup, cmdline) cmd = self.run_into_cmd(cgroup, cmdline)
raw_output = self.target.execute(cmd) raw_output = self.target.execute(cmd, as_root=as_root)
# First line of output comes from shutils; strip it out. # First line of output comes from shutils; strip it out.
return raw_output.split('\n', 1)[1] return raw_output.split('\n', 1)[1]