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 commitf62c1f3f8e) locate.updatedb: Revert to using cat to copy the db. This script is usually run unprivileged, so install fails to create a temporary file while copying the finished database. Revert to using cat, which can overwrite the existing file as it is usually owned by the same user which is running the script. Fixes:f62c1f3f8eMFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D46872 (cherry picked from commit26bd374e72)
This commit is contained in:
parent
013d817b53
commit
8d65747f7c
1 changed files with 5 additions and 8 deletions
|
|
@ -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
|
||||
cat $tmp >$FCODES
|
||||
fi
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue