From bced0f521341831f5b889232d2f0d14ddca809dc Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Mon, 20 Jan 2014 10:58:57 +0100 Subject: [PATCH] when locating namespaces in /proc//ns do not use the result of virsh domid to determine as this would point at the lxc driver we need to use its - expected single - child process, that instead corresponds to the VM init/systemd instance --- lxcsu | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lxcsu b/lxcsu index a9ff3d6..cc7ce12 100755 --- a/lxcsu +++ b/lxcsu @@ -103,12 +103,15 @@ def main (): 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) @@ -184,17 +187,19 @@ def main (): print 'WARNING - setns(%s)=>%s (ignored)'%(path,retcod) return retcod - chcontext('/proc/%s/ns/uts'%pid) - chcontext('/proc/%s/ns/ipc'%pid) + # 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): - chcontext('/proc/%s/ns/pid'%pid) + chcontext(ref_ns+'pid') if (not args.netns): - chcontext('/proc/%s/ns/net'%pid) + chcontext(ref_ns+'net') if (not args.mntns): - chcontext('/proc/%s/ns/mnt'%pid) + chcontext(ref_ns+'mnt') proc_mounted = False if (not os.access('/proc/self',0)): -- 2.43.0