Commit d909df8b
d909df8b5931Merged
Ryan Seys <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
fix(spinel): avoid BSD mktemp tail-template collision on macOS
BSD mktemp (macOS) only substitutes the trailing run of X's in the
template, so mktemp /tmp/spinel_out.XXXXXX.c collapses to the literal
name /tmp/spinel_out.XXXXXX.c instead of producing a unique path.
Concurrent spinel foo.rb invocations then race on the same file,
truncating each other's emitted C and crashing the codegen pipeline.
Mint a unique 0700 temp directory via mktemp -d and place the .c
file inside it under a known name. Compared to the obvious mktemp ...).c
trick:
- No leaked sibling: the bare-name file
mktempcreates without-dis never written to once the shell appends.cto the variable; here the directory holds the only.cand the trap removes it. - Explicit error path:
|| exit 1fires ifmktemp -dfails (e.g. /tmp not writable); previously$C_TMPwould silently become.cand downstreamrmwould target the wrong path. - Permissions: the 0700 directory hides the
.cfilename from other local users, where> fileunder the default umask would have created a 0644 file.
Cleanup trap rewritten to do rm -rf "$C_TMP_DIR" guarded by a
non-empty check so an early-exit before the dir is minted is a no-op.
The C_FILE/C_TMP plumbing on the rest of the pipeline is
unchanged — only the path source moves from a flat temp name to a
file inside a temp dir.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- d909df8b5931
- Parent
- 1d5291554707
spinelmodifiedView file
CC_CMD="cc"EXTRA_FLAGS=""C_TMP=""C_TMP_DIR=""EVAL_SCRIPT=""EVAL_USED=0EVAL_TMP=""fiAST_TMP="$(mktemp /tmp/spinel_ast.XXXXXX)"IR_TMP="$(mktemp /tmp/spinel_ir.XXXXXX)"trap 'rm -f "$AST_TMP" "$IR_TMP" "$C_TMP" "$EVAL_TMP"' EXITtrap 'rm -f "$AST_TMP" "$IR_TMP" "$EVAL_TMP"; [ -n "$C_TMP_DIR" ] && rm -rf "$C_TMP_DIR"' EXIT# Step 1: Parse. spinel_parse is C-only; build it via `make parse`# (or `make all`) before invoking spinel.if [ $C_ONLY -eq 1 ]; then C_FILE="${OUTPUT:-$BASENAME.c}"else C_TMP="$(mktemp /tmp/spinel_out.XXXXXX.c)" C_TMP_DIR="$(mktemp -d /tmp/spinel_out.XXXXXX)" || { echo "spinel: mktemp -d failed" >&2; exit 1; } C_TMP="$C_TMP_DIR/out.c" C_FILE="$C_TMP"fi