mirror of
git://github.com/lxc/lxc
synced 2025-09-01 13:31:38 +00:00
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>
This commit is contained in:
committed by
Daniel Lezcano
parent
3fb0a9bb6e
commit
07ede90408
@@ -1,7 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# set -ex
|
# set -ex
|
||||||
|
|
||||||
lxcpath=@LXCPATH@
|
lxcpath=/var/lib/lxc
|
||||||
exec=""
|
exec=""
|
||||||
|
|
||||||
if [ ! -r $lxcpath ]; then
|
if [ ! -r $lxcpath ]; then
|
||||||
@@ -15,15 +15,15 @@ fi
|
|||||||
|
|
||||||
for i in $*; do
|
for i in $*; do
|
||||||
case $i in
|
case $i in
|
||||||
-n)
|
-n)
|
||||||
name=$2; shift 2;;
|
name=$2; shift 2;;
|
||||||
--exec)
|
--exec)
|
||||||
exec="exec"; shift;;
|
exec="exec"; shift;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ -z "$exec" ]; then
|
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
|
fi
|
||||||
|
|
||||||
if [ -z "$name" ]; then
|
if [ -z "$name" ]; then
|
||||||
@@ -31,20 +31,31 @@ if [ -z "$name" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -d $lxcpath/$name ]; then
|
cgroups=$(mount -l -t cgroup)
|
||||||
echo "'$name' does not exists"
|
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
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -z "$cgroup_path" ]; then
|
||||||
|
echo "no cgroup mount point found"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -r $lxcpath/$name ]; then
|
pid=$(head -1 $cgroup_path/$name/tasks)
|
||||||
echo "Can not access '$name': permission denied"
|
|
||||||
|
if [ -z "$pid" ]; then
|
||||||
|
echo "no process found for '$name'"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -f $lxcpath/$name/init ]; then
|
mount --bind /proc/$pid/net /proc/$$/net && \
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
initpid=$(cat $lxcpath/$name/init) && \
|
|
||||||
mount --bind /proc/$initpid/net /proc/$$/net && \
|
|
||||||
exec netstat $*
|
exec netstat $*
|
||||||
|
Reference in New Issue
Block a user