diff options
author | 2009-11-13 11:48:29 +0100 | |
---|---|---|
committer | 2009-11-13 11:48:29 +0100 | |
commit | 07ede9040852d161b84776f9d83be05a0d0b87ec (patch) | |
tree | d5e8fcb6305f43cb9ff9254f1fa3ff07c9d452e7 | |
parent | Q: general lxc architecture (diff) | |
download | lxc-07ede9040852d161b84776f9d83be05a0d0b87ec.tar.gz lxc-07ede9040852d161b84776f9d83be05a0d0b87ec.tar.bz2 lxc-07ede9040852d161b84776f9d83be05a0d0b87ec.zip |
Fix lxc-netstat script
Recent changes around the configuration tree broke the current
implementation of the lxc-netstat.
Instead of retrieving the init_pid in the /var/lxc/<name>/...,
pick one in the cgroup tasks list.
There is still a restriction with this command making impossible
to run it as non-root, any idea is welcome :(
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
-rw-r--r-- | src/lxc/lxc-netstat.in | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/src/lxc/lxc-netstat.in b/src/lxc/lxc-netstat.in index 6f4b163..4ced22d 100644 --- a/src/lxc/lxc-netstat.in +++ b/src/lxc/lxc-netstat.in @@ -1,7 +1,7 @@ #!/bin/bash # set -ex -lxcpath=@LXCPATH@ +lxcpath=/var/lib/lxc exec="" if [ ! -r $lxcpath ]; then @@ -15,15 +15,15 @@ fi for i in $*; do case $i in - -n) - name=$2; shift 2;; - --exec) - exec="exec"; shift;; + -n) + name=$2; shift 2;; + --exec) + exec="exec"; shift;; esac done if [ -z "$exec" ]; then - exec @BINDIR@/lxc-unshare -s MOUNT -- @BINDIR@/lxc-netstat -n $name --exec $* + exec /usr/bin/lxc-unshare -s MOUNT -- /usr/bin/lxc-netstat -n $name --exec $* fi if [ -z "$name" ]; then @@ -31,20 +31,31 @@ if [ -z "$name" ]; then exit 1 fi -if [ ! -d $lxcpath/$name ]; then - echo "'$name' does not exists" - exit 1 -fi +cgroups=$(mount -l -t cgroup) +cgroup_path="" + +for i in "$cgroups"; do + + cgroup_name=$(echo $i | awk ' { print $1 } ') + cgroup_path=$(echo $i | awk ' { print $3 } ') + + if [ "$cgroup_name" == "lxc" ]; then + break; + fi -if [ ! -r $lxcpath/$name ]; then - echo "Can not access '$name': permission denied" +done + +if [ -z "$cgroup_path" ]; then + echo "no cgroup mount point found" exit 1 fi -if [ ! -f $lxcpath/$name/init ]; then - exit 0 +pid=$(head -1 $cgroup_path/$name/tasks) + +if [ -z "$pid" ]; then + echo "no process found for '$name'" + exit 1 fi -initpid=$(cat $lxcpath/$name/init) && \ - mount --bind /proc/$initpid/net /proc/$$/net && \ +mount --bind /proc/$pid/net /proc/$$/net && \ exec netstat $* |