-
Notifications
You must be signed in to change notification settings - Fork 5
/
run_as_cgroupv2.sh
executable file
·62 lines (46 loc) · 1.17 KB
/
run_as_cgroupv2.sh
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
chktool()
{
[[ $(which "$1") == "" ]] && echo "need util $1" && exit 2
}
[[ $UID -ne 0 ]] && echo "need to be root" && exit 2
chktool curl
chktool python
chktool timeout
chktool bpftool
chktool mountpoint
CGRP_MNT=/mnt/cgroup-test-work-dir
BPF_MNT=/sys/fs/bpf
trap 'unload "$BASH_COMMAND"' EXIT
unload()
{
[[ $? -ne 0 ]] && echo "Failed: [$1]"
echo "unloading..."
set +e
if [ -d "$CGRP_MNT" ]; then
mountpoint $CGRP_MNT >/dev/null
[[ $? -eq 0 ]] && umount $CGRP_MNT
[[ -d "$CGRP_MNT" ]] && rm -rf $CGRP_MNT
fi
mountpoint $BPF_MNT >/dev/null
[[ $? -eq 0 ]] && umount $BPF_MNT
}
load()
{
mountpoint $BPF_MNT >/dev/null
[[ $? -ne 0 ]] && mount -t bpf none $BPF_MNT
mkdir -p $CGRP_MNT
mountpoint $CGRP_MNT >/dev/null
[[ $? -ne 0 ]] && mount -t cgroup2 none $CGRP_MNT
}
#load
./bin/local-socket-bypass-user.bin ./run_localsock.sh
### Start of Action
#python -m SimpleHTTPServer 12345 &
#srv_pid=$!
#sleep 1
#curl http://localhost:12345/
#curl http://www.baidu.com
#kill $srv_pid $bypass_pid
### End of Action
#timeout --preserve-status 1s bpftool prog tracelog #show whatever logs were captured