aboutsummaryrefslogtreecommitdiff
blob: 792ea0efec7c85b424f9008adae7ca5270531e97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash

localstatedir=@LOCALSTATEDIR@
lxcpath=@LXCPATH@

if [ ! -r $lxcpath ]; then
    exit 0
fi

function get_cgroup()
{
	local mount_string
	mount_string=$(mount -t cgroup |grep -E -e '^lxc ')
	if test -n "$mount_string"; then
		mount_point=$(echo $mount_string |cut -d' ' -f3)
		return
	fi
	mount_string=`grep -m1 -E '^[^ \t]+[ \t]+[^ \t]+[ \t]+cgroup' /proc/self/mounts`;
	if test -z "$mount_string"; then
		echo "failed to find mounted cgroup"
		exit 1
	fi
	mount_point=`echo "$mount_string" |cut -d' ' -f2`;
}

ls "$@" $lxcpath

active=$(netstat -xl | grep $lxcpath | \
	sed -e 's#.*'"$lxcpath/"'\(.*\)/command#\1#');

if test -n "$active"; then
	get_cgroup
	if test -n "$mount_point"; then
		# get cgroup for init
		init_cgroup=`cat /proc/1/cgroup | awk -F: '{ print $3 }' | head -1`
		cd $mount_point/$init_cgroup/lxc
		ls "$@" -d $active
	fi
fi