try:
cmd = '/usr/bin/virsh --connect lxc:/// domid %s'%slice_name
pidnum = int(os.popen(cmd).read().rstrip())
+ # locate the pid for the - expected - single child, that would be the init for that VM
+ child_pid = open("/proc/%s/task/%s/children"%(pidnum,pidnum)).read().strip()
+
except:
print "Domain %s not found"%slice_name
exit(1)
pid = '%s'%pidnum
- if debug: print "Found pidnum",pidnum
+ if debug: print "Found pidnum",pidnum,'child_pid=',child_pid
cmdline = open('/proc/%s/cmdline'%pidnum).read().rstrip('\n\x00')
arch = getarch('/proc/%s/exe'%pid)
exit(1)
- setns.chcontext('/proc/%s/ns/uts'%pid)
- setns.chcontext('/proc/%s/ns/ipc'%pid)
+ def chcontext (path):
+ retcod = setns.chcontext (path)
+ if retcod != 0:
+ print 'WARNING - setns(%s)=>%s (ignored)'%(path,retcod)
+ return retcod
+
+ # Use child_pid and not pid to locate reference namespaces
+ ref_ns = "/proc/%s/ns/"%child_pid
+ chcontext(ref_ns+'uts')
+ chcontext(ref_ns+'ipc')
if (not args.pidns):
- setns.chcontext('/proc/%s/ns/pid'%pid)
+ chcontext(ref_ns+'pid')
if (not args.netns):
- setns.chcontext('/proc/%s/ns/net'%pid)
+ chcontext(ref_ns+'net')
if (not args.mntns):
- setns.chcontext('/proc/%s/ns/mnt'%pid)
+ chcontext(ref_ns+'mnt')
proc_mounted = False
if (not os.access('/proc/self',0)):
for subsystem in ['cpuset','cpu,cpuacct','memory','devices','freezer','net_cls','blkio','perf_event','systemd']:
fs_path = '/sys/fs/cgroup/%s'%subsystem
if (not umount(fs_path,'-l')):
+ print 'WARNING - umount failed (ignored) with path=',fs_path
pass
# Leaving these comments for historical reference
#print "Error disabling cgroup access"