1
Description: make lxc-ps work with separate mtab
2
cgroup-bin mounts cgroupfs with '-n', so if mtab is not linked to
3
/proc/self/mounts, 'mount -t cgroup' won't show these mounts. But
4
lxc-ps is depending on them. Instead, search /proc/self/mounts.
5
Note - this does not support the host init being in different cgroups
6
for different subsystems.
7
This was sent upstream on July 28, 2011, but not yet applied.
8
Origin: http://www.mail-archive.com/lxc-users@lists.sourceforge.net/msg02363.html
11
Index: lxc-0.7.5/src/lxc/lxc-ps.in
12
===================================================================
13
--- lxc-0.7.5.orig/src/lxc/lxc-ps.in 2011-08-11 15:54:57.000000000 +0000
14
+++ lxc-0.7.5/src/lxc/lxc-ps.in 2012-01-10 14:50:48.808494856 +0000
18
$mount_string=`mount -t cgroup |grep -E -e '^lxc '`;
19
- unless ($mount_string) {
20
- $mount_string=`mount |grep -m1 'type cgroup'`;
22
- chomp($mount_string);
24
+ # use the one 'lxc' cgroup mount if it exists
25
+ chomp($mount_string);
26
$$ref_cgroup=`echo "$mount_string" |cut -d' ' -f3`;
29
- die "unable to find mounted cgroup" unless $$ref_cgroup;
30
+ # Otherwise (i.e. cgroup-bin) use the first cgroup mount
31
+ $mount_string=`grep -m1 -E '^[^ \t]+[ \t]+[^ \t]+[ \t]+cgroup' /proc/self/mounts`;
32
+ unless ($mount_string) {
33
+ die "unable to find mounted cgroup" unless $$ref_cgroup;
35
+ chomp($mount_string);
36
+ $$ref_cgroup=`echo "$mount_string" |cut -d' ' -f2`;
37
+ chomp($$ref_cgroup);
41
sub get_pids_in_containers {
42
my $ref_names = shift;
43
my $ref_cgroup = shift;
45
+ my $init_cgroup = shift;
49
- my $task_file = "$$ref_cgroup/$_/tasks";
50
+ my $task_file = "$$ref_cgroup/$init_cgroup/lxc/$_/tasks";
53
open(tasks, "cat $task_file 2>/dev/null |") or next;
58
+sub get_init_cgroup {
59
+ my $filename = "/proc/1/cgroup";
60
+ open(LXC, "$filename");
64
+ foreach ( @cgroup ) {
66
+ # find the container name after :/
74
my $filename = "/proc/$pid/cgroup";
78
# find the container name after :/
82
+ # chop off everything up to 'lxc/'
92
+my $init_cgroup = '/';
94
GetOptions('help' => \$arg_help,
95
'usage' => \$arg_usage,
100
+ $init_cgroup = get_init_cgroup();
102
- get_pids_in_containers(\@arg_name, \$cgroup, \$pid_list);
103
+ get_pids_in_containers(\@arg_name, \$cgroup, \$pid_list, $init_cgroup);
105
@ARGV = ("-p $pid_list",@ARGV);