Skip to content

Commit cbadb70

Browse files
committed
Fix fallthrough logic for cgroup version detection
Only one of cgroup V1 or V2 can be enabled at a time, so it doesn't make sense to have fallthrough behaviour from V2 to V1. Instead of adding an `exit 0` at the end of the V2 case, add an `else` so that it is clearer that these are two mutually exclusive cases. Fixes a0728be
1 parent 564ceb7 commit cbadb70

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

judge/create_cgroups.in

+17-16
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ cgroup_error_and_usage () {
1818
exit 1
1919
}
2020

21-
# Check whether cgroup v2 is available.
21+
# Check whether cgroup v2 is enabled.
2222
fs_type=$(awk '$2 == "/sys/fs/cgroup" {print $3}' /proc/mounts)
2323
if [ "$fs_type" = "cgroup2" ]; then
2424
kernel_version=$(uname -r)
@@ -34,25 +34,26 @@ You can try using cgroup V1 by adding systemd.unified_cgroup_hierarchy=0 to the
3434
if ! echo "+cpuset" >> /sys/fs/cgroup/cgroup.subtree_control; then
3535
cgroup_error_and_usage "Error: Cannot add +cpuset to cgroup.subtree_control; check kernel params. Unable to continue."
3636
fi
37-
fi
3837

39-
# Trying cgroup V1:
38+
else # Trying cgroup V1:
4039

41-
for i in cpuset memory; do
42-
mkdir -p $CGROUPBASE/$i
43-
if [ ! -d $CGROUPBASE/$i/ ]; then
44-
if ! mount -t cgroup -o$i $i $CGROUPBASE/$i/; then
45-
cgroup_error_and_usage "Error: Can not mount $i cgroup. Probably cgroup support is missing from running kernel. Unable to continue."
40+
for i in cpuset memory; do
41+
mkdir -p $CGROUPBASE/$i
42+
if [ ! -d $CGROUPBASE/$i/ ]; then
43+
if ! mount -t cgroup -o$i $i $CGROUPBASE/$i/; then
44+
cgroup_error_and_usage "Error: Can not mount $i cgroup. Probably cgroup support is missing from running kernel. Unable to continue."
45+
fi
4646
fi
47+
mkdir -p $CGROUPBASE/$i/domjudge
48+
done
49+
50+
if [ ! -f $CGROUPBASE/memory/memory.limit_in_bytes ] || [ ! -f $CGROUPBASE/memory/memory.memsw.limit_in_bytes ]; then
51+
cgroup_error_and_usage "Error: cgroup support missing memory features in running kernel. Unable to continue."
4752
fi
48-
mkdir -p $CGROUPBASE/$i/domjudge
49-
done
5053

51-
if [ ! -f $CGROUPBASE/memory/memory.limit_in_bytes ] || [ ! -f $CGROUPBASE/memory/memory.memsw.limit_in_bytes ]; then
52-
cgroup_error_and_usage "Error: cgroup support missing memory features in running kernel. Unable to continue."
53-
fi
54+
chown -R $JUDGEHOSTUSER $CGROUPBASE/*/domjudge
5455

55-
chown -R $JUDGEHOSTUSER $CGROUPBASE/*/domjudge
56+
cat $CGROUPBASE/cpuset/cpuset.cpus > $CGROUPBASE/cpuset/domjudge/cpuset.cpus
57+
cat $CGROUPBASE/cpuset/cpuset.mems > $CGROUPBASE/cpuset/domjudge/cpuset.mems
5658

57-
cat $CGROUPBASE/cpuset/cpuset.cpus > $CGROUPBASE/cpuset/domjudge/cpuset.cpus
58-
cat $CGROUPBASE/cpuset/cpuset.mems > $CGROUPBASE/cpuset/domjudge/cpuset.mems
59+
fi # cgroup V1

0 commit comments

Comments
 (0)