Commit d8521cc3 by Stéphane Graber

python: Update add_device_node to use the new API

Update add_device_node to use the new set_cgroup_item call instead of having to figure out the cgroup paths and update the entries manually. Signed-off-by: 's avatarStéphane Graber <stgraber@ubuntu.com> Acked-by: 's avatarSerge E. Hallyn <serge.hallyn@ubuntu.com>
parent f2924f78
...@@ -172,37 +172,17 @@ class Container(_lxc.Container): ...@@ -172,37 +172,17 @@ class Container(_lxc.Container):
path_stat = os.stat(path) path_stat = os.stat(path)
mode = stat.S_IMODE(path_stat.st_mode) mode = stat.S_IMODE(path_stat.st_mode)
# Lookup the cgroup
cgroup_path = None
with open("/proc/%s/cgroup" % self.init_pid, "r") as fd:
for line in fd:
if ":devices:" in line:
cgroup_path = line.split(":")[-1].strip()
break
else:
return False
# Lookup the cgroup mount point
cgroup = None
with open("/proc/mounts", "r") as fd:
for line in fd:
mount = line.split()
if (mount[2] == "cgroup" and "devices" in mount[3]
and os.path.exists("%s/%s" % (mount[1], cgroup_path))):
cgroup = "%s/%s" % (mount[1], cgroup_path)
break
if not os.path.exists(cgroup):
return False
# Allow the target # Allow the target
with open("%s/devices.allow" % cgroup, "a") as fd: if stat.S_ISBLK(path_stat.st_mode):
if stat.S_ISBLK(path_stat.st_mode): self.set_cgroup_item("devices.allow",
fd.write("b %s:%s rwm" % (int(path_stat.st_rdev / 256), "b %s:%s rwm" %
int(path_stat.st_rdev % 256))) (int(path_stat.st_rdev / 256),
elif stat.S_ISCHR(path_stat.st_mode): int(path_stat.st_rdev % 256)))
fd.write("c %s:%s rwm" % (int(path_stat.st_rdev / 256), elif stat.S_ISCHR(path_stat.st_mode):
int(path_stat.st_rdev % 256))) self.set_cgroup_item("devices.allow",
"c %s:%s rwm" %
(int(path_stat.st_rdev / 256),
int(path_stat.st_rdev % 256)))
# Create the target # Create the target
rootfs = "/proc/%s/root/" % self.init_pid rootfs = "/proc/%s/root/" % self.init_pid
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment