[Lxc-users] make lxc-ps work with separate mtab

Serge E. Hallyn serge.hallyn at canonical.com
Thu Jul 28 18:19:28 UTC 2011


It breaks with multiple cgroup mounts unless /etc/mtab is linked
to /proc/self/mounts (which it is not in Ubuntu, for instance).

Signed-off-by: Serge Hallyn <serge.hallyn at canonical.com>

Index: lxc/src/lxc/lxc-ps.in
===================================================================
--- lxc.orig/src/lxc/lxc-ps.in	2011-07-28 11:29:35.003183756 -0500
+++ lxc/src/lxc/lxc-ps.in	2011-07-28 11:31:37.973180821 -0500
@@ -53,15 +53,21 @@
 	my $mount_string;
 
 	$mount_string=`mount -t cgroup |grep -E -e '^lxc '`;
-	unless ($mount_string) {
-		$mount_string=`mount |grep -m1 'type cgroup'`;
-	}
-	chomp($mount_string);
 	if ($mount_string) {
+		# use the one 'lxc' cgroup mount if it exists
+		chomp($mount_string);
 		$$ref_cgroup=`echo "$mount_string" |cut -d' ' -f3`;
 		chomp($$ref_cgroup);
 	}
-	die "unable to find mounted cgroup" unless $$ref_cgroup;
+	# Otherwise (i.e. cgroup-bin) use the first cgroup mount
+	$mount_string=`grep -m1 -E '^[^ \t]+[ \t]+[^ \t]+[ \t]+cgroup' /proc/self/mounts`;
+	unless ($mount_string) {
+		die "unable to find mounted cgroup" unless $$ref_cgroup;
+	}
+	chomp($mount_string);
+	$$ref_cgroup=`echo "$mount_string" |cut -d' ' -f2`;
+	chomp($$ref_cgroup);
+	return;
 }
 
 sub get_pids_in_containers {
@@ -115,11 +121,7 @@
     my $container = <LXC>;
     close LXC;
     chomp($container);
-    if ($container =~ m/[:,]ns[:,]/o) {
-    	$container =~ s/.*:\///o;
-    } else {
-	$container ='';
-    }
+    $container =~ s/.*:\///o;
     return $container;
 }
 




More information about the lxc-users mailing list