]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
fix lxc-ps to work with systemd
authorJoerg Gollnick <code4lxc+list@wurzelbenutzer.de>
Sun, 24 Jul 2011 22:22:50 +0000 (00:22 +0200)
committerDaniel Lezcano <dlezcano@fr.ibm.com>
Sun, 24 Jul 2011 22:22:50 +0000 (00:22 +0200)
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 <dlezcano@fr.ibm.com>
src/lxc/lxc-ps.in

index 249b104399000e552bd83b0fcab9582eaaa3f77a..7b3c8ab36fbcecd5d7200384a611363d54889eb0 100755 (executable)
@@ -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(<active>) {
@@ -112,13 +112,18 @@ sub get_container {
     my $pid = shift;
     my $filename = "/proc/$pid/cgroup";
     open(LXC, "$filename");
-    my $container = <LXC>;
+    # read all lines at once
+    my @cgroup = <LXC>;
     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;
 }