~serge-hallyn/ubuntu/quantal/lxc/lxc-aa-custom-profile

« back to all changes in this revision

Viewing changes to src/lxc/lxc-netstat.in

  • Committer: Bazaar Package Importer
  • Author(s): Guido Trotter
  • Date: 2010-01-10 10:40:21 UTC
  • mto: (1.1.2 upstream) (3.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20100110104021-ff3ukvpu7yzc36hm
ImportĀ upstreamĀ versionĀ 0.6.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/bin/bash
2
2
# set -ex
3
3
 
4
 
lxcpath=@LXCPATH@
5
4
exec=""
6
5
 
7
 
if [ ! -r $lxcpath ]; then
8
 
    exit 0
9
 
fi
10
 
 
11
6
if [ $# -eq  0 ]; then
12
7
    echo "usage: $0 -n <name>"
13
8
    exit 1
15
10
 
16
11
for i in $*; do
17
12
    case $i in
18
 
        -n)
19
 
            name=$2; shift 2;;
20
 
        --exec)
21
 
            exec="exec"; shift;;
 
13
        -n)
 
14
            name=$2; shift 2;;
 
15
        --exec)
 
16
            exec="exec"; shift;;
22
17
    esac
23
18
done
24
19
 
25
20
if [ -z "$exec" ]; then
26
 
    exec @BINDIR@/lxc-unshare -s MOUNT -- @BINDIR@/lxc-netstat -n $name --exec $*
 
21
    exec @BINDIR@/lxc-unshare -s MOUNT -- $0 -n $name --exec $*
27
22
fi
28
23
 
29
24
if [ -z "$name" ]; then
31
26
    exit 1
32
27
fi
33
28
 
34
 
if [ ! -d $lxcpath/$name ]; then
35
 
    echo "'$name' does not exists"
36
 
    exit 1
37
 
fi
38
 
 
39
 
if [ ! -r $lxcpath/$name ]; then
40
 
    echo "Can not access '$name': permission denied"
41
 
    exit 1
42
 
fi
43
 
 
44
 
if [ ! -f $lxcpath/$name/init ]; then
45
 
    exit 0
46
 
fi
47
 
 
48
 
initpid=$(cat $lxcpath/$name/init) && \
49
 
    mount --bind /proc/$initpid/net /proc/$$/net && \
 
29
cgroups=$(mount -l -t cgroup)
 
30
cgroup_path=""
 
31
 
 
32
for i in "$cgroups"; do
 
33
 
 
34
    cgroup_name=$(echo $i | awk ' { print $1 } ')
 
35
    cgroup_path=$(echo $i | awk ' { print $3 } ')
 
36
 
 
37
    if [ "$cgroup_name" == "lxc" ]; then
 
38
        break;
 
39
    fi
 
40
 
 
41
done
 
42
 
 
43
if [ -z "$cgroup_path" ]; then
 
44
    echo "no cgroup mount point found"
 
45
    exit 1
 
46
fi
 
47
 
 
48
pid=$(head -1 $cgroup_path/$name/tasks)
 
49
 
 
50
if [ -z "$pid" ]; then
 
51
    echo "no process found for '$name'"
 
52
    exit 1
 
53
fi
 
54
 
 
55
mount --bind /proc/$pid/net /proc/$$/net && \
50
56
    exec netstat $*