From nobody Thu Aug 29 15:06:24 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 4Wvl3h4zLTz5PbHV; Thu, 29 Aug 2024 15:06:24 +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 4Wvl3h4VVNz4nyB; Thu, 29 Aug 2024 15:06:24 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1724943984; 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=/b0oZ7rOspwOwoU7ywgFTzueHh7zYJIxVyefSDFz5hk=; b=dCDE+K/MGzAMnZYNh3oW/E7zRcZUbhQIepCMzE4olBYJt0//UV7+bKXC2uE5SUysQnJ5db cCc9EAnhjHsNjBMPBAoT4dKUL9lr8Cp31vsJomkMNq1vTgv4RhkDdPpExW+HyKdfHi1R2z NOsLou031zlevNC2FK1K2XRMHJjEfkfnPErr+t9HCYpeGcqD4cwXg7uoPmM28K0LJB5F9e m6bdQh7KzKFLj9J5rDojGWNXJTi845cfaXxttRnvZBILcjJx89gqJJRIA4EdRtAuCrDv76 EGaqdMxa3Db4vMVGhmKmrhBBhteM2T5NbhdRu86lzJB6CvXTMPY8zgbUY1EpSA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1724943984; a=rsa-sha256; cv=none; b=X6sU55+4N5PVnqPPU87Ssl5pJWfxhNp5RPviswOABQ/ZARF1Igdu3JxIkXvx+qkXSF9FpH njXq/5owJk9Nikta/Njwj/hTccORlQXbjAPveb8XAH8tQi9CeYm74M/pCOLuvdz+BBwysN UP6qUdVzQSocVna8hd4cMpGc5dIN0x/+LfgYwIQdAQ0+2MPVmZX7c2xea2zXPoARYgPix2 FU2iBkXmTWPwP/SVXq+qYlaxCynXAca6lCEnbPJ0XYjyuj7iwF5B0iSRQKu9LlEbGihxvR WUtXFPmZfccaCEVd5sEfwN8hkpdolKsMDRuDQwcUrS117zKHldsME3Q9f1wDSw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1724943984; 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=/b0oZ7rOspwOwoU7ywgFTzueHh7zYJIxVyefSDFz5hk=; b=BhHrILkaobRsgqX/F4959nv4SBkqPL5E9tSCRIPpiz7pRHEMRb3ez1dQ7PAl3gmsN7Enns 8YCiWCoyJNLMwluAx/ouKwPxdXcNi1u18ZZcRa+ZAudJuUBWLTw4kPjlYbbQBMe66x5m+c V5bPuXbbeQXuEsmxqm/ss9y3Z8b8mFBBDPBAIzGp3RuZdHH0ETlPQsZx4jIDeJcCAr9zSJ GDCg8OY2RPy30ZQs4hfEh+DEgrumZ74HPDWbGUnDmoiRXvI5gxC8gkLUSItUKrHWflIl+X dSCh5TZM9W0WtzZn+1XBQcLhki68hOlZOpXuUveijVZZWTWTeoaMQYCTxsRqiw== 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 4Wvl3h45r0zM9g; Thu, 29 Aug 2024 15:06:24 +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 47TF6ONQ079043; Thu, 29 Aug 2024 15:06:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 47TF6ODx079040; Thu, 29 Aug 2024 15:06:24 GMT (envelope-from git) Date: Thu, 29 Aug 2024 15:06:24 GMT Message-Id: <202408291506.47TF6ODx079040@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: f62c1f3f8e91 - main - 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/main X-Git-Reftype: branch X-Git-Commit: f62c1f3f8e91c78d402e1db4e518e4899a4ba2b9 Auto-Submitted: auto-generated The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=f62c1f3f8e91c78d402e1db4e518e4899a4ba2b9 commit f62c1f3f8e91c78d402e1db4e518e4899a4ba2b9 Author: Dag-Erling Smørgrav AuthorDate: 2024-08-29 15:05:47 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2024-08-29 15:05:47 +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 --- 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..ca1a79116a91 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