From 4fdff3db03d99c6c986d41cb1f662ab7a61f3733 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Fri, 10 Jan 2014 11:05:02 +0100 Subject: [PATCH] =?utf8?q?Simplify=20lxcsu=20by=20querying=20libvirt=20for?= =?utf8?q?=20pid=20=E2=80=94=20this=20is=20a=20manual=20re-injection=20of?= =?utf8?q?=20Sapan=E2=80=99s=20change=20it=20was=20a=20big=20mistake=20to?= =?utf8?q?=20reindent=20automatically=20as=20this=20broke=20the=20logic=20?= =?utf8?q?entirely?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- lxcsu | 38 ++++++-------------------------------- 1 file changed, 6 insertions(+), 32 deletions(-) diff --git a/lxcsu b/lxcsu index 090cea1..eb3c5ce 100755 --- a/lxcsu +++ b/lxcsu @@ -84,43 +84,17 @@ def main (): debug=True try: - cmd = 'grep %s /proc/*/cgroup | grep freezer'%slice_name - output = os.popen(cmd).readlines() + cmd = '/usr/bin/virsh domid %s'%slice_name + pidnum = int(os.popen(cmd).read().rstrip()) except: print "Error finding slice %s"%slice_name exit(1) - slice_spec = None + pid = '%s'%pidnum + cmdline = open('/proc/%s/cmdline'%pidnum).read().rstrip('\n\x00') + arch = getarch('/proc/%s/exe'%pid) - # provide a default as this is not always properly computed - arch = None - - for e in output: - try: - l = e.rstrip() - path = l.split(':')[0] - comp = l.rsplit(':')[-1] - slice_name_check = comp.rsplit('/')[-1] - if debug: print "dealing with >%s<"%slice_name_check - - if (slice_name_check == slice_name): - if debug: print "found %s"%slice_name - slice_path = path - pid = slice_path.split('/')[2] - cmdline = open('/proc/%s/cmdline'%pid).read().rstrip('\n\x00') - if (cmdline == '/sbin/init') or (cmdline.startswith("init [")): - slice_spec = slice_path - arch = getarch('/proc/%s/exe'%pid) - break - except Exception,e: - if debug: - import traceback - print "BEG lxcsu - ignoring exception" - traceback.print_exc() - print "END lxcsu - ignoring exception" - pass - - if (not slice_spec or not pid): + if (not pid): print "Not started: %s"%slice_name exit(1) -- 2.43.0