From owner-dev-commits-src-all@freebsd.org Wed Jun 9 21:21:07 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 75290653D00; Wed, 9 Jun 2021 21:21:07 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4G0g5G5y4jz3nRm; Wed, 9 Jun 2021 21:21:06 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 A524A235A8; Wed, 9 Jun 2021 21:21:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 159LL6tW051682; Wed, 9 Jun 2021 21:21:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 159LL6Qb051681; Wed, 9 Jun 2021 21:21:06 GMT (envelope-from git) Date: Wed, 9 Jun 2021 21:21:06 GMT Message-Id: <202106092121.159LL6Qb051681@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 29ed8efb3b1e - stable/12 - etcupdate: Gracefully handle SIGINT when building trees. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 29ed8efb3b1e834a5c6f4726fa2516a5af3266a9 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Jun 2021 21:21:07 -0000 The branch stable/12 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=29ed8efb3b1e834a5c6f4726fa2516a5af3266a9 commit 29ed8efb3b1e834a5c6f4726fa2516a5af3266a9 Author: John Baldwin AuthorDate: 2021-04-20 20:22:11 +0000 Commit: John Baldwin CommitDate: 2021-06-09 21:19:19 +0000 etcupdate: Gracefully handle SIGINT when building trees. Run the 'build_tree' function inside of a subshell and trap SIGINT to return an error to the caller. This allows callers to gracefully cleanup a partially created tree. While here, redirect stdout/stderr of the subshell to the log file instead of applying redirections individually to each command executed while building the tree. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D29844 (cherry picked from commit 1f7afa9364805a912270c9d6a70dc4a889d47a4e) --- usr.sbin/etcupdate/etcupdate.sh | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/usr.sbin/etcupdate/etcupdate.sh b/usr.sbin/etcupdate/etcupdate.sh index a84323890828..f64e58e4ecd1 100755 --- a/usr.sbin/etcupdate/etcupdate.sh +++ b/usr.sbin/etcupdate/etcupdate.sh @@ -179,17 +179,21 @@ always_install() return 1 } -# Build a new tree +# Build a new tree. This runs inside a subshell to trap SIGINT. # # $1 - directory to store new tree in build_tree() -{ +( local destdir dir file make make="make $MAKE_OPTIONS -DNO_FILEMON" log "Building tree at $1 with $make" - mkdir -p $1/usr/obj >&3 2>&1 + + exec >&3 2>&1 + trap 'return 1' INT + + mkdir -p $1/usr/obj destdir=`realpath $1` if [ -n "$preworld" ]; then @@ -197,34 +201,33 @@ build_tree() # crucial to installworld. for file in $PREWORLD_FILES; do dir=`dirname /$file` - mkdir -p $1/$dir >&3 2>&1 || return 1 + mkdir -p $1/$dir || return 1 cp -p $SRCDIR/$file $1/$file || return 1 done elif ! [ -n "$nobuild" ]; then (cd $SRCDIR; $make DESTDIR=$destdir distrib-dirs && MAKEOBJDIRPREFIX=$destdir/usr/obj $make _obj SUBDIR_OVERRIDE=etc && MAKEOBJDIRPREFIX=$destdir/usr/obj $make everything SUBDIR_OVERRIDE=etc && - MAKEOBJDIRPREFIX=$destdir/usr/obj $make DESTDIR=$destdir distribution) \ - >&3 2>&1 || return 1 + MAKEOBJDIRPREFIX=$destdir/usr/obj $make DESTDIR=$destdir distribution) || \ + return 1 else (cd $SRCDIR; $make DESTDIR=$destdir distrib-dirs && - $make DESTDIR=$destdir distribution) >&3 2>&1 || return 1 + $make DESTDIR=$destdir distribution) || return 1 fi - chflags -R noschg $1 >&3 2>&1 || return 1 - rm -rf $1/usr/obj >&3 2>&1 || return 1 + chflags -R noschg $1 || return 1 + rm -rf $1/usr/obj || return 1 # Purge auto-generated files. Only the source files need to # be updated after which these files are regenerated. - rm -f $1/etc/*.db $1/etc/passwd $1/var/db/services.db >&3 2>&1 || \ - return 1 + rm -f $1/etc/*.db $1/etc/passwd $1/var/db/services.db || return 1 # Remove empty files. These just clutter the output of 'diff'. - find $1 -type f -size 0 -delete >&3 2>&1 || return 1 + find $1 -type f -size 0 -delete || return 1 # Trim empty directories. - find -d $1 -type d -empty -delete >&3 2>&1 || return 1 + find -d $1 -type d -empty -delete || return 1 return 0 -} +) # Generate a new tree. If tarball is set, then the tree is # extracted from the tarball. Otherwise the tree is built from a