remove xbmk_parent, handle forking in lib.sh

I was using a complicated method of knowing whether
the current instance was parent or a child, to know
whether the lock file and TMPDIR needed to be purged.

It was quite error-prone too. Instead, I'm now handling
it directly from within the if statement that previously
initialised xbmk_parent=y, forking ./mk from there.

The forked instance would not trigger that if clause
again, since then TMPDIR is created, thus avoiding
recursion.

This is an improvement because it doesn't rely on how
the parent handles exit statuses, and it ensures that
the lock/tmp files are never accidentally deleted.

Even if a given program/script that cbmk runs would
export TMPDIR, it doesn't matter because cbmk doesn't,
so it would be unaffected.

Signed-off-by: Leah Rowe <leah@libreboot.org>
25.04_branch
Leah Rowe 2025-04-12 19:57:40 +01:00
parent f3c757c2d2
commit ca6a3c8958
3 changed files with 9 additions and 23 deletions

View File

@ -21,7 +21,7 @@ fail_inject()
rm -Rf "$tmpromdel" || : rm -Rf "$tmpromdel" || :
printf "\n\n%s\n\n" "$dontflash" 1>&2 printf "\n\n%s\n\n" "$dontflash" 1>&2
printf "WARNING: File '%s' was NOT modified.\n\n" "$archive" 1>&2 printf "WARNING: File '%s' was NOT modified.\n\n" "$archive" 1>&2
fail "$1" $err "$1"
} }
xbmk_inject() xbmk_inject()

View File

@ -50,7 +50,7 @@ chkvars()
} }
eval "`setvars "" _nogit board reinstall versiondate aur_notice configdir \ eval "`setvars "" _nogit board reinstall versiondate aur_notice configdir \
datadir version relname xbmk_parent`" datadir version relname`"
for fv in version versiondate; do for fv in version versiondate; do
eval "[ ! -f \".$fv\" ] || read -r $fv < \".$fv\" || :" eval "[ ! -f \".$fv\" ] || read -r $fv < \".$fv\" || :"
@ -140,7 +140,12 @@ if [ -z "${TMPDIR+x}" ]; then
cd "$XBMK_CACHE/xbmkpath" || $err "can't cd $XBMK_CACHE/xbmkpath" cd "$XBMK_CACHE/xbmkpath" || $err "can't cd $XBMK_CACHE/xbmkpath"
x_ ln -s "`command -v "$python"`" python x_ ln -s "`command -v "$python"`" python
) || $err "Can't set up python symlink in $XBMK_CACHE/xbmkpath" ) || $err "Can't set up python symlink in $XBMK_CACHE/xbmkpath"
xbmk_parent="y"
xbmk_rval=0
./mk "$@" || xbmk_rval=1
rm -Rf "$TMPDIR" || xbmk_rval=1
rm -f lock || xbmk_rval=1
exit $xbmk_rval
fi fi
# if "y": a coreboot target won't be built if target.cfg says release="n" # if "y": a coreboot target won't be built if target.cfg says release="n"

21
mk
View File

@ -16,7 +16,6 @@ fi
. "include/inject.sh" . "include/inject.sh"
eval "`setvars "" vdir src_dirname srcdir mode xp ser`" eval "`setvars "" vdir src_dirname srcdir mode xp ser`"
err="fail"
main() main()
{ {
@ -115,23 +114,7 @@ build_release()
rm -Rf "$srcdir" || $err "!rm -Rf $srcdir" rm -Rf "$srcdir" || $err "!rm -Rf $srcdir"
} }
fail() main "$@" && exit 0
{
tmp_cleanup || printf "WARNING: can't rm tmpfiles: %s\n" "$TMPDIR" 1>&2
err_ "${1}"
}
tmp_cleanup()
{
[ "$xbmk_parent" = "y" ] || return 0
[ "$TMPDIR" = "/tmp" ] || rm -Rf "$TMPDIR" || return 1
rm -f lock || return 1
}
if main "$@"; then
tmp_cleanup || err_ "can't rm TMPDIR upon non-zero exit: $TMPDIR"
exit 0
fi
# what follows was formerly script/trees, whose main() is now trees() # what follows was formerly script/trees, whose main() is now trees()
@ -521,5 +504,3 @@ if trees "$@"; then
. "$mkhelpercfg" . "$mkhelpercfg"
$cmd $cmd
fi fi
tmp_cleanup || err_ "can't rm TMPDIR upon non-zero exit: $TMPDIR"