Date: Sun, 6 Oct 2024 11:07:25 GMT From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= <des@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: eefeb6ca68bf - stable/13 - locate.updatedb: Explicitly exit from trap code. Message-ID: <202410061107.496B7PIv039268@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=eefeb6ca68bf8ef42d4f98fc386288de5b2012c5 commit eefeb6ca68bf8ef42d4f98fc386288de5b2012c5 Author: Dag-Erling Smørgrav <des@FreeBSD.org> AuthorDate: 2024-08-29 15:05:47 +0000 Commit: Dag-Erling Smørgrav <des@FreeBSD.org> CommitDate: 2024-10-06 09:16:34 +0000 locate.updatedb: Explicitly exit from trap code. When a signal is trapped, the script continues after the trap code has run, unless the trap code explicitly exits. In the particular case of locate.updatedb, this is mostly harmless, except that the trap code is executed twice (once for the signal and once when we reach the end of the script), but it's still worth fixing. Furthermore, install the trap as soon as we've created the temporary directory, to minimize the window during which we can fail to clean up after ourselves if interrupted. While here, simplify the empty check at the end and make some minor style tweaks. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D46475 (cherry picked from commit f62c1f3f8e91c78d402e1db4e518e4899a4ba2b9) --- usr.bin/locate/locate/updatedb.sh | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/usr.bin/locate/locate/updatedb.sh b/usr.bin/locate/locate/updatedb.sh index e874700afdb8..846fd6dc0d7b 100644 --- a/usr.bin/locate/locate/updatedb.sh +++ b/usr.bin/locate/locate/updatedb.sh @@ -42,13 +42,14 @@ fi # The directory containing locate subprograms : ${LIBEXECDIR:=/usr/libexec}; export LIBEXECDIR : ${TMPDIR:=/tmp}; export TMPDIR -if ! TMPDIR=`mktemp -d $TMPDIR/locateXXXXXXXXXX`; then +if ! TMPDIR=$(mktemp -d $TMPDIR/locateXXXXXXXXXX); then exit 1 fi +tmp=$TMPDIR/_updatedb$$ +trap 'rc=$?; rm -f $tmp; rmdir $TMPDIR; trap - 0; exit $rc' 0 1 2 3 5 10 15 PATH=$LIBEXECDIR:/bin:/usr/bin:$PATH; export PATH - : ${mklocatedb:=locate.mklocatedb} # make locate database program : ${FCODES:=/var/db/locate.database} # the database : ${SEARCHPATHS="/"} # directories to be put in the database @@ -87,17 +88,13 @@ if [ -n "$PRUNEDIRS" ]; then done fi -tmp=$TMPDIR/_updatedb$$ -trap 'rm -f $tmp; rmdir $TMPDIR' 0 1 2 3 5 10 15 - # search locally if $find -s $SEARCHPATHS $excludes -or -print 2>/dev/null | $mklocatedb -presort > $tmp then - if [ -n "$($find $tmp -size -257c -print)" ]; then + if ! grep -aq / $tmp; then echo "updatedb: locate database $tmp is empty" >&2 exit 1 - else - cat $tmp > $FCODES # should be cp? fi + install $tmp $FCODES fi
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202410061107.496B7PIv039268>