From nobody Sun Oct 06 11:07:22 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4XLzyL6KHyz5XgLc; Sun, 06 Oct 2024 11:07:22 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XLzyL5nkGz4sFk; Sun, 6 Oct 2024 11:07:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728212842; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=nt7aWhBdPRwBwaOmaRwKPcEjRqQcVRLaeUb9JiWWmC8=; b=ITHx8azr+m7nu7OPScztlk6cW31kjI21kx7lQEtY14+58RlUexcWO0CXA/il30zPdE3z+F MwgYIGu0NsTch4KBL27HNtTKNwAKK2nwH9m1Q/pYio7r169TNLi5pFEBwer8AkLwPejhEX Tk4wOLXZ73ZXEXr+5FriXH8olqYhB75ehqw3ySYYQqXLSfHUcNRYfO1CWA8jk4t/dp3pa5 bd2VMrT3Vpo5CsskqFxNttpGyxgrS7kGPdoJwqY0rBlKI3xFtZyDe45nY2XnKgdUamSSGI MbReR+9e4LC68n7e8g5BvO47hs1Nt0+n2t4rQqAx8jKnzdxJYDqln7nVX5oHSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728212842; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=nt7aWhBdPRwBwaOmaRwKPcEjRqQcVRLaeUb9JiWWmC8=; b=kC+dNfbD46wMnAzUjoLZ3/DNC6EzLiTHBmmiL4U3r0B65R/5hmr+pUs8TOS4gZUZ5f+QyR tU1Kr9dNvjHzn7KdFWY0fbUvacg9+NNMYD1+IQY0pnYoBAjubGgc/6DdJyh4IHvX0PVlkR iaGyP2zkiWK3+inQ44j/ORjI2hIE/5FcmeoEPOMl04IDdp6g1PXFdqbENcLRlvMhvjKJ8/ KmkjI4C21WFJnabiyrQeMy9+8DTLlAKRbg8FFiITfAfAP7aPfejq2Mv8KGyFSV+bliVW5b oyEsxQy1J8E3ErN7giSODiD2JRjwIF+ZGS7uXm0FB0XnZpqWGO2WUAkh1+xMlg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1728212842; a=rsa-sha256; cv=none; b=sDbeM6W0J2pANAga4BHCPR+e43D1dZdoYvx+i06PKC/eEo5nfAdklDtVsg+RhqP5waTku8 S081DGFxnUcYwHq1GUU6QmNOmprQ4qIzeGm9VpHASZ+mlDN9Gu/xfQIvp5KYvRbCjd3wEF +TdLIbJrIPJ5xrVwwit9lJ1eNMUE58tvZtQMcd3QE+YxWCooWTtXWSq1MiWrI1bdbBwvyU roHDtq6U9Y5bsGrKFAda8r3K+hQ+2WXe+xxd1+PA+/Ypvtz/8iBUnEc9HPDPG5iXDJs6aI FpP41DlKvwkfocZJ8w73JIx4/hbRqOB2WVM33poIddyXHbHz73KleL3TchKyqQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4XLzyL5KlSz101R; Sun, 6 Oct 2024 11:07:22 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 496B7MuC039054; Sun, 6 Oct 2024 11:07:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 496B7MKC039051; Sun, 6 Oct 2024 11:07:22 GMT (envelope-from git) Date: Sun, 6 Oct 2024 11:07:22 GMT Message-Id: <202410061107.496B7MKC039051@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: 8d65747f7c6f - stable/14 - locate.updatedb: Explicitly exit from trap code. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 8d65747f7c6f61a0ee9304aaffcfdee9f885b9d5 Auto-Submitted: auto-generated The branch stable/14 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=8d65747f7c6f61a0ee9304aaffcfdee9f885b9d5 commit 8d65747f7c6f61a0ee9304aaffcfdee9f885b9d5 Author: Dag-Erling Smørgrav AuthorDate: 2024-08-29 15:05:47 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2024-10-06 09:11:56 +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) 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: f62c1f3f8e91 MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D46872 (cherry picked from commit 26bd374e72681860af4bf9d639308ad245949460) --- 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 ff7ec7f6c18e..7d42cbb2260d 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 + cat $tmp >$FCODES fi