summaryrefslogtreecommitdiff
path: root/src/lib/stats.source.sh
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-06-14 15:43:12 +0300
committerPaul Buetow <paul@buetow.org>2026-06-14 15:43:12 +0300
commitfe4e83cd5159809a70f24301fcabc08779b51706 (patch)
tree29b71066a22db0630ed37ced8e8710e8175b83f7 /src/lib/stats.source.sh
parent3eeef1e0f68d750e7817748180a2007095e99ef3 (diff)
6m0 clean up BASH_ENV context tempfile via traps on interrupt
source_template_file created its context tempfile with mktemp but only ran rm -f on the success and explicit-failure paths. When a render was interrupted by a signal (terminate_active_generation SIGTERMs the backgrounded render subtree on Ctrl-C/abort) the tempfile leaked. Register cleanup in exactly one place, inline in source_template_file's body: - A RETURN trap covers normal and error returns and clears all of these traps (including itself) so it cannot linger and fire on an enclosing function's return against the out-of-scope context_file local (set -u). The trap must be set in the function body, not a helper: without functrace a RETURN trap is not function-scoped and would fire when a helper returns, deleting the file before the render runs. - INT/TERM/HUP handlers remove the file, clear the traps and re-raise so the process still exits with the signal's default disposition. PIPE is not trapped (the internal context-build pipeline emits legitimate SIGPIPE); SIGKILL is untrappable, leaving only the OS-reaped KILL-escalation case. The redundant rm -f calls are removed. Adds test_template_interrupt_removes_context_file, which runs an in-flight render and SIGTERMs it, asserting the context file is gone. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'src/lib/stats.source.sh')
0 files changed, 0 insertions, 0 deletions