-open('/proc/lxcsu','w').write(pid)
-open('/proc/pidsu','w').write(pid)
+if (not options.netns):
+ setns.chcontext('/proc/%s/ns/net'%pid)
+
+if (not options.mntns):
+ open('/proc/lxcsu','w').write(pid)
+
+if (not options.pidns):
+ open('/proc/pidsu','w').write(pid)
+
+# cgroups is not yet LXC-safe, so we need to use the course grained access control
+# strategy of unmounting the filesystem
+
+umount_result = True
+for subsystem in ['cpuset','cpu,cpuacct','memory','devices','freezer','net_cls','blkio','perf_event']:
+ fs_path = '/sys/fs/cgroup/%s'%subsystem
+ if (not umount(fs_path)):
+ print "Error disabling cgroup access"
+ exit(1)
+
+if (not umount('/sys/fs/cgroup')):
+ print "Error disabling cgroup access"
+ exit(1)