Commit c011782c by Joerg Gollnick Committed by Daniel Lezcano

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: 's avatarDaniel Lezcano <dlezcano@fr.ibm.com>
parent bcbd102c
...@@ -37,7 +37,7 @@ our %LXC_NAMES; # Specified container names (if any) ...@@ -37,7 +37,7 @@ our %LXC_NAMES; # Specified container names (if any)
sub get_container_names { sub get_container_names {
my $ref_names = shift; my $ref_names = shift;
my $lxcpath='@LXCPATH@'; my $lxcpath = '@LXCPATH@';
open(active, "netstat -xa | grep $lxcpath |") or return; open(active, "netstat -xa | grep $lxcpath |") or return;
while(<active>) { while(<active>) {
...@@ -112,13 +112,18 @@ sub get_container { ...@@ -112,13 +112,18 @@ sub get_container {
my $pid = shift; my $pid = shift;
my $filename = "/proc/$pid/cgroup"; my $filename = "/proc/$pid/cgroup";
open(LXC, "$filename"); open(LXC, "$filename");
my $container = <LXC>; # read all lines at once
my @cgroup = <LXC>;
close LXC; close LXC;
chomp($container); my $container = '';
if ($container =~ m/[:,]ns[:,]/o) { foreach ( @cgroup ) {
$container =~ s/.*:\///o; chomp;
} else { # find the container name
$container =''; if (m/[:,]ns[:,]/o) {
# container name after :/
s/.*:\///o;
$container = $_;
}
} }
return $container; return $container;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment