Skip to content

Commit 4d56679

Browse files
committed
Use sane variables instead of full paths
Signed-off-by: Dhaval Giani <dhaval.giani@gmail.com>
1 parent b9e4b1c commit 4d56679

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

setup-cgroups.sh

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@
33

44
user=$1
55
uid=`id -u`
6+
cgroupdir=/sys/fs/cgroup/memory
7+
testdir=test
68

79
if [ $uid != 0 ]
810
then
911
echo "Need to be root"
1012
exit
1113
fi
1214

13-
if [ ! -d /sys/fs/cgroup/memory ]
15+
if [ ! -d $cgroupdir ]
1416
then
1517
echo "Non-standard cgroup configuration"
1618
exit
1719
fi
1820

19-
mkdir /sys/fs/cgroup/memory/test
20-
echo 1M > /sys/fs/cgroup/memory/test/memory.limit_in_bytes
21+
mkdir $cgroupdir/$testdir
22+
echo 1M > $cgroupdir/$testdir/memory.limit_in_bytes
2123

22-
chown -R $user /sys/fs/cgroup/memory/test
24+
chown -R $user $cgroupdir/$testdir

setup.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
#!/bin/bash
22

3+
cgroupdir=/sys/fs/cgroup/memory
4+
testdir=test
35
curr_user=`id | cut -d "(" -f 2 | cut -d ")" -f 1`
46

57
echo $curr_user
68

79
echo "Now we need root"
810
sudo ./setup-cgroups.sh $curr_user
911

10-
echo $$ > /sys/fs/cgroup/memory/test/tasks
12+
echo $$ > $cgroupdir/$testdir/tasks
1113

1214
echo "Now we are trapped in the correct cgroup"
1315
cat /proc/self/cgroup | grep memory

teardown-cgroup.sh

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
#!/bin/bash
22

33
uid=`id -u`
4+
cgroupdir=/sys/fs/cgroup/memory
5+
testdir=test
46

57
if [ $uid != 0 ]
68
then
79
echo "Need to be root"
810
exit
911
fi
1012

11-
if [ ! -d /sys/fs/cgroup/memory ]
13+
if [ ! -d $cgroupdir ]
1214
then
1315
echo "Non-standard cgroup configuration"
1416
exit
1517
fi
1618

17-
if [ ! -d /sys/fs/cgroup/memory/test ]
19+
if [ ! -d $cgroupdir/$testdir ]
1820
then
1921
echo "Cgroups not setup"
2022
exit
2123
fi
2224

23-
for pid in `cat /sys/fs/cgroup/memory/test/tasks`
25+
for pid in `cat $cgroupdir/$testdir/tasks`
2426
do
25-
echo $pid > /sys/fs/cgroup/memory/tasks
27+
echo $pid > $cgroupdir/tasks
2628
done
2729

28-
rmdir /sys/fs/cgroup/memory/test/
30+
rmdir $cgroupdir/$testdir

0 commit comments

Comments
 (0)