Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions scripts/thunderstorm-collector.sh
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ cleanup_tmp_files() {
for f in "${TMP_FILES_ARR[@]}"; do
[ -n "$f" ] && [ -f "$f" ] && rm -f "$f"
done
# Remove fallback temp directory if it exists (created by mktemp_portable)
local _fallback_dir="${TMPDIR:-/tmp}/thunderstorm.$$"
[ -d "$_fallback_dir" ] && rm -rf "$_fallback_dir"
}

INTERRUPTED=0
Expand Down Expand Up @@ -363,9 +366,14 @@ mktemp_portable() {
echo "$t"
return 0
fi
# Fallback: RANDOM may be empty in non-bash shells
t="${TMPDIR:-/tmp}/thunderstorm.$$.${RANDOM:-0}.$(date +%N 2>/dev/null || echo 0)"
( umask 077 && : > "$t" ) 2>/dev/null || return 1
# Fallback: create a private directory first (mkdir is atomic), then a file inside it.
# This avoids the TOCTOU race of creating a predictable file in a shared /tmp.
local _dir="${TMPDIR:-/tmp}/thunderstorm.$$"
if [ ! -d "$_dir" ]; then
( umask 077 && mkdir "$_dir" ) 2>/dev/null || return 1
fi
t="$_dir/${RANDOM:-0}.$(date +%N 2>/dev/null || echo 0)"
: > "$t" 2>/dev/null || return 1
echo "$t"
}

Expand Down
Loading