Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
  • Loading branch information...
commit d8521cc3754a740a547b12aa81990d117b5d99ee 1 parent f2924f7
@stgraber stgraber authored
Showing with 10 additions and 30 deletions.
  1. +10 −30 src/python-lxc/lxc/__init__.py.in
View
40 src/python-lxc/lxc/__init__.py.in
@@ -172,37 +172,17 @@ class Container(_lxc.Container):
path_stat = os.stat(path)
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
- with open("%s/devices.allow" % cgroup, "a") as fd:
- if stat.S_ISBLK(path_stat.st_mode):
- fd.write("b %s:%s rwm" % (int(path_stat.st_rdev / 256),
- int(path_stat.st_rdev % 256)))
- elif stat.S_ISCHR(path_stat.st_mode):
- fd.write("c %s:%s rwm" % (int(path_stat.st_rdev / 256),
- int(path_stat.st_rdev % 256)))
+ if stat.S_ISBLK(path_stat.st_mode):
+ self.set_cgroup_item("devices.allow",
+ "b %s:%s rwm" %
+ (int(path_stat.st_rdev / 256),
+ int(path_stat.st_rdev % 256)))
+ elif stat.S_ISCHR(path_stat.st_mode):
+ 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
rootfs = "/proc/%s/root/" % self.init_pid
Please sign in to comment.
Something went wrong with that request. Please try again.