From c011782c8d83ece9ee883fcd9406433c09f220be Mon Sep 17 00:00:00 2001 From: Joerg Gollnick Date: Mon, 25 Jul 2011 00:22:50 +0200 Subject: [PATCH] fix lxc-ps to work with systemd Dear all, while working with systemd I found that lxc-ps -efa does not recognize the container name. Best regards Joerg Signed-off-by: Daniel Lezcano --- src/lxc/lxc-ps.in | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/lxc/lxc-ps.in b/src/lxc/lxc-ps.in index 249b10439..7b3c8ab36 100755 --- a/src/lxc/lxc-ps.in +++ b/src/lxc/lxc-ps.in @@ -37,7 +37,7 @@ our %LXC_NAMES; # Specified container names (if any) sub get_container_names { my $ref_names = shift; - my $lxcpath='@LXCPATH@'; + my $lxcpath = '@LXCPATH@'; open(active, "netstat -xa | grep $lxcpath |") or return; while() { @@ -112,13 +112,18 @@ sub get_container { my $pid = shift; my $filename = "/proc/$pid/cgroup"; open(LXC, "$filename"); - my $container = ; + # read all lines at once + my @cgroup = ; close LXC; - chomp($container); - if ($container =~ m/[:,]ns[:,]/o) { - $container =~ s/.*:\///o; - } else { - $container =''; + my $container = ''; + foreach ( @cgroup ) { + chomp; + # find the container name + if (m/[:,]ns[:,]/o) { + # container name after :/ + s/.*:\///o; + $container = $_; + } } return $container; }