mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-13 14:59:34 +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:
+18
-1
@@ -108,11 +108,28 @@ xbmk_set_env()
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# parent instance of xbmk, so continue.
|
# parent instance of xbmk, so continue.
|
||||||
# first, set up a unified temporary directory:
|
|
||||||
export TMPDIR="/tmp"
|
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
|
export TMPDIR="`mktemp -d -t xbmk_XXXXXXXX || err`" || err
|
||||||
xbtmp="$TMPDIR"
|
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?"
|
[ -f "$xbmklock" ] && err "'$xbmklock' exists. Is a build running?"
|
||||||
printf "%s\n" "$xbtmp" > "$xbmklock" || \
|
printf "%s\n" "$xbtmp" > "$xbmklock" || \
|
||||||
err "cannot create '$xbmklock'"; :
|
err "cannot create '$xbmklock'"; :
|
||||||
|
|||||||
Reference in New Issue
Block a user