summaryrefslogtreecommitdiff
path: root/include/init.sh
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2025-08-31 20:39:07 +0100
committerLeah Rowe <leah@libreboot.org>2025-08-31 20:39:07 +0100
commitf96bf2b2cd32f05a0e7b7c4f7bbeaefe5dea246b (patch)
tree67135d5339f43a6e4ec0586a85d42c8bb27a34e8 /include/init.sh
parentbbce74d78af9ef871bff52f44638eda57a26973e (diff)
init.sh: prevent race condition with TMPDIR
it is extremely unlikely to occur, but this patch reduces the likelihood even further. that unlikely occurance is: when creating a TMPDIR, it's possible that it was already created before. this is OK on child instances, where that is the intended behaviour (unified TMPDIR), but not for parent instances. Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'include/init.sh')
-rw-r--r--include/init.sh19
1 files changed, 18 insertions, 1 deletions
diff --git a/include/init.sh b/include/init.sh
index ea18cf69..f268c6e6 100644
--- a/include/init.sh
+++ b/include/init.sh
@@ -108,11 +108,28 @@ xbmk_set_env()
fi
# parent instance of xbmk, so continue.
- # first, set up a unified temporary directory:
+
export TMPDIR="/tmp"
+
+ xbmklist="`mktemp || err "can't make tmplist"`" || err
+ x_ rm -f "$xbmklist"
+ x_ touch "$xbmklist"
+ for xtmpdir in /tmp/xbmk_*; do
+ [ -e "$xtmpdir" ] || continue
+ printf "%s\n" "$xtmpdir" >> "$xbmklist" || \
+ err "can't write '$xtmpdir' to file: '$xbmklist'"; :
+ done
+
+ # set up a unified temporary directory, for common deletion later:
export TMPDIR="`mktemp -d -t xbmk_XXXXXXXX || err`" || err
xbtmp="$TMPDIR"
+ while read -r xtmpdir; do
+ [ "$xtmpdir" = "$xbtmp" ] && err \
+ "'$xbtmp' existed previously (possible race condition)"; :
+ done < "$xbmklist" || err "Couldn't read xbmklist: '$xbmklist'"
+ x_ rm -f "$xbmklist"
+
[ -f "$xbmklock" ] && err "'$xbmklock' exists. Is a build running?"
printf "%s\n" "$xbtmp" > "$xbmklock" || \
err "cannot create '$xbmklock'"; :