fix(cc): raise oom_score_adj to 500 inside the session (BLK-044)
sshd's systemd override (OOMScoreAdjust=-1000) is inherited by tmux, dtach and every claude started via cc, so the OOM killer never picks a runaway claude; systemd-run --scope rejects the property. The inner bash raises /proc/self/oom_score_adj to 500 (raise-only) before exec claude. T7-oom asserts it through the stubbed chain.
This commit is contained in:
1 parent
387ae8675d
commit
6c10d3a220
2 files changed
+10
-2
No files matched your search
@@ -16,6 +16,8 @@
|
||||
# flag overrides; to change packs, start another `cc <name> <profile>`.
|
||||
# Without a profile: manifest defaults + local settings, as before.
|
||||
# TMPDIR goes to ~/.cache/claude-tmp either way (BLK-021).
|
||||
# oom_score_adj is raised to 500 inside the session (BLK-044: sshd's -1000
|
||||
# is inherited), raise-only.
|
||||
# ============================================================
|
||||
|
||||
_cc_name_ok() { [[ "$1" =~ ^[a-z0-9][a-z0-9-]*$ ]]; }
|
||||
@@ -45,6 +47,8 @@ cc() {
|
||||
dtach -c "$HOME/.dtach/${name}" -e '^\' \
|
||||
bash -c 'set -a; [ -f "$HOME/.claude/.env" ] && . "$HOME/.claude/.env"
|
||||
set +a
|
||||
[ "$(cat /proc/self/oom_score_adj 2>/dev/null)" -lt 500 ] \
|
||||
2>/dev/null && echo 500 2>/dev/null > /proc/self/oom_score_adj
|
||||
if [ -n "$CLAUDE_PROFILE_SETTINGS" ]; then
|
||||
exec claude --settings "$CLAUDE_PROFILE_SETTINGS"
|
||||
fi
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
# list + rc 2, no session; a profile → claude --settings <fragment> with
|
||||
# CLAUDE_PROFILE / CLAUDE_PROFILE_SETTINGS / TMPDIR exported through
|
||||
# systemd-run + dtach; no profile → plain claude, TMPDIR still set; .env
|
||||
# sourced. Hermetic: PATH shims, HOME in a fixture holding .claude/lib.
|
||||
# sourced; oom_score_adj raised to 500 (raise-only).
|
||||
# Hermetic: PATH shims, HOME in a fixture holding .claude/lib.
|
||||
set -u
|
||||
unset CLAUDE_PROFILE CLAUDE_PROFILE_SETTINGS
|
||||
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
|
||||
@@ -31,7 +32,8 @@ cat > "$FX/bin/claude" <<'EOT'
|
||||
#!/usr/bin/env bash
|
||||
{ echo "claude argv: $*"; echo "CLAUDE_PROFILE=${CLAUDE_PROFILE-unset}"
|
||||
echo "CLAUDE_PROFILE_SETTINGS=${CLAUDE_PROFILE_SETTINGS-unset}"
|
||||
echo "TMPDIR=${TMPDIR-unset}"; echo "canary=${CC_ENV_CANARY-unset}"; } >> "$CC_LOG"
|
||||
echo "TMPDIR=${TMPDIR-unset}"; echo "canary=${CC_ENV_CANARY-unset}"
|
||||
echo "oom=$(cat /proc/self/oom_score_adj 2>/dev/null)"; } >> "$CC_LOG"
|
||||
EOT
|
||||
chmod +x "$FX/bin/"*
|
||||
# shellcheck source=lib/tests/claude-stub.sh
|
||||
@@ -72,5 +74,7 @@ done
|
||||
|
||||
printf 'CC_ENV_CANARY=1\n' > "$FX/home/.claude/.env"
|
||||
: > "$CC_LOG"; cc s4 webx; check_has T4-env "$(cat "$CC_LOG")" "canary=1"
|
||||
want=$(cat /proc/self/oom_score_adj); [ "$want" -lt 500 ] && want=500
|
||||
check_has T7-oom "$(cat "$CC_LOG")" "oom=$want"
|
||||
check T5-shellcheck "$(shellcheck "$ROOT/lib/cc.sh" >/dev/null 2>&1 && echo ok)" ok
|
||||
printf 'PASS=%s FAIL=%s\n' "$pass" "$fail"; [ "$fail" -eq 0 ]
|
||||
Reference in new issue
Block a user