mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-03-25 21:39:03 +02:00
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>
This commit is contained in:
@@ -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'"; :
|
||||
|
||||
Reference in New Issue
Block a user