Created
May 14, 2025 21:29
-
-
Save fzakaria/6361efe206bcf525e3e6a860c8996049 to your computer and use it in GitHub Desktop.
Genrule to check Linux sandbox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
genrule( | |
name = "check_cgroup", | |
outs = ["cgroup_output.txt"], | |
cmd = """ | |
set -euo pipefail | |
echo "==== /proc/self/cgroup ====" > $@ | |
cat /proc/self/cgroup >> $@ | |
echo "" >> $@ | |
echo "==== /proc/1/cgroup (init) ====" >> $@ | |
cat /proc/1/cgroup >> $@ | |
echo "" >> $@ | |
echo "==== /proc/self/mountinfo (filtered for cgroup) ====" >> $@ | |
grep cgroup /proc/self/mountinfo >> $@ || echo "(no cgroup mounts)" >> $@ | |
echo "" >> $@ | |
echo "==== Current PID ====" >> $@ | |
echo $$ >> $@ | |
echo "" >> $@ | |
echo "==== Kernel version ====" >> $@ | |
uname -a >> $@ | |
echo "" >> $@ | |
echo "==== Cgroup memory.max (current cgroup) ====" >> $@ | |
if [ -f /sys/fs/cgroup/memory.max ]; then | |
cat /sys/fs/cgroup/memory.max >> $@ | |
else | |
echo "/sys/fs/cgroup/memory.max not available" >> $@ | |
fi | |
echo "" >> $@ | |
echo "==== Cgroup memory.max (/sys/fs/cgroup/example) ====" >> $@ | |
if [ -f /sys/fs/cgroup/example/memory.max ]; then | |
cat /sys/fs/cgroup/example/memory.max >> $@ | |
else | |
echo "/sys/fs/cgroup/example/memory.max not available" >> $@ | |
fi | |
echo "" >> $@ | |
echo "==== Cgroup memory.max (/sys/fs/cgroup/example/child) ====" >> $@ | |
if [ -f /sys/fs/cgroup/example/child/memory.max ]; then | |
cat /sys/fs/cgroup/example/child/memory.max >> $@ | |
else | |
echo "/sys/fs/cgroup/example/child/memory.max not available" >> $@ | |
fi | |
echo "" >> $@ | |
echo "==== Cgroup memory.max for each cgroup in /proc/self/cgroup ====" >> $@ | |
while IFS= read -r line; do | |
IFS=: read -r _ _ cgroup_path <<< "$$line" | |
if [ -f "/sys/fs/cgroup$${cgroup_path}/memory.max" ]; then | |
echo "$${cgroup_path}: $$(cat /sys/fs/cgroup$${cgroup_path}/memory.max)" >> $@ | |
else | |
echo "$${cgroup_path}: memory.max not available" >> $@ | |
fi | |
done < /proc/self/cgroup | |
echo "" >> $@ | |
""", | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment