aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerge Hallyn <serge.hallyn@canonical.com>2012-02-02 15:48:17 -0600
committerDaniel Lezcano <daniel.lezcano@free.fr>2012-02-26 10:44:40 +0100
commit581092fc657735b08251e902255453a7d53f3a33 (patch)
treed462d4c8f6aeb9415f2490c8d0dd4940fd1248ad
parentsupport proper container reboot (diff)
downloadlxc-581092fc657735b08251e902255453a7d53f3a33.tar.gz
lxc-581092fc657735b08251e902255453a7d53f3a33.tar.bz2
lxc-581092fc657735b08251e902255453a7d53f3a33.zip
fix lxc-netstat for nested cgroups
Use the correct path for the container's cgroup task file. Also exit out early and cleanly if the container is not running, and bind-mount /proc/$pid/net with '-n' to keep the entry out of mtab, else the mtab entry will never go away. Signed-off-by: Serge Hallyn <serge.hallyn@canonical.com> Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
-rw-r--r--src/lxc/lxc-netstat.in14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/lxc/lxc-netstat.in b/src/lxc/lxc-netstat.in
index d7c68d7..9e7eec3 100644
--- a/src/lxc/lxc-netstat.in
+++ b/src/lxc/lxc-netstat.in
@@ -45,6 +45,12 @@ if [ -z "$name" ]; then
exit 1
fi
+lxc-info -n $name 2>&1 | grep -q 'STOPPED'
+if [ $? -eq 0 ]; then
+ echo "Container $name is not running"
+ exit 1
+fi
+
cgroups=$(mount -l -t cgroup)
cgroup_path=""
@@ -74,12 +80,16 @@ if [ -z "$cgroup_path" ]; then
exit 1
fi
-pid=$(head -1 $cgroup_path/$name/tasks)
+# the container will be in:
+# ${cgroup_path}.${init_cgroup_path}."lxc".$name
+init_cgroup=`cat /proc/1/cgroup | awk -F: '{ print $3 }' | head -1`
+final_cgroup_path=$cgroup_path/$init_cgroup/lxc
+pid=$(head -1 $final_cgroup_path/$name/tasks)
if [ -z "$pid" ]; then
echo "no process found for '$name'"
exit 1
fi
-mount --bind /proc/$pid/net /proc/$$/net && \
+mount -n --bind /proc/$pid/net /proc/$$/net && \
exec netstat "$@"