forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiBd22dd39Tahinli3 months ago1391 commits

memguard-runner.sh21 lines, 826 bytesHistoryRawDownload
1#!/usr/bin/env bash
2# Wraps a test/bin invocation in a transient user cgroup scope so a runaway
3# allocation dies inside its own cgroup instead of triggering a machine-wide
4# OOM kill. Used as the cargo target runner (see .cargo/config.toml) so every
5# `cargo test`/`cargo run` invocation of this workspace is capped, from any
6# checkout (main repo or worktree).
7set -euo pipefail
8
9if [ "${EC_NOMEMGUARD:-0}" = "1" ]; then
10 echo "memguard-runner: EC_NOMEMGUARD=1, running without memory cap" >&2
11 exec "$@"
12fi
13
14if ! systemd-run --user --scope --quiet -p MemoryMax=10G true >/dev/null 2>&1; then
15 echo "memguard-runner: systemd-run --user --scope unavailable, running without memory cap" >&2
16 exec "$@"
17fi
18
19exec systemd-run --user --scope --quiet --same-dir \
20 -p MemoryMax=10G -p MemorySwapMax=2G \
21 -- "$@"