From patchwork Sat Mar 25 16:33:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Shumaker X-Patchwork-Id: 69 Return-Path: Delivered-To: patchwork@archlinux.org Received: from nymeria.archlinux.org by nymeria.archlinux.org (Dovecot) with LMTP id 8vhrHe6b1lj1MQAAtiB/HQ for ; Sat, 25 Mar 2017 17:33:50 +0100 Received: from nymeria.archlinux.org (localhost.localdomain [127.0.0.1]) by nymeria.archlinux.org (Postfix) with ESMTP id B2BBC40484; Sat, 25 Mar 2017 17:33:47 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on nymeria.archlinux.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.5 tests=BAYES_00,RCVD_IN_DNSWL_MED shortcircuit=no autolearn=ham autolearn_force=no version=3.4.1 Received: from luna.archlinux.org (luna.archlinux.org [5.9.250.164]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by nymeria.archlinux.org (Postfix) with ESMTPS; Sat, 25 Mar 2017 17:33:47 +0100 (CET) Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 66B4F213C3; Sat, 25 Mar 2017 16:33:47 +0000 (UTC) Authentication-Results: luna.archlinux.org; dkim=none Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id B539020958 for ; Sat, 25 Mar 2017 16:33:44 +0000 (UTC) Received: from mav.lukeshu.com (mav.lukeshu.com [104.207.138.63]) by luna.archlinux.org (Postfix) with ESMTPS for ; Sat, 25 Mar 2017 16:33:44 +0000 (UTC) Received: from build64-par (unknown [IPv6:2601:803:202:9275:21f:e2ff:fe4d:191b]) by mav.lukeshu.com (Postfix) with ESMTPSA id 59D0183EAC; Sat, 25 Mar 2017 12:33:41 -0400 (EDT) From: Luke Shumaker To: arch-projects@lists.archlinux.org Date: Sat, 25 Mar 2017 12:33:36 -0400 Message-Id: <20170325163339.24259-1-lukeshu@parabola.nu> X-Mailer: git-send-email 2.12.0 Subject: [arch-projects] [devtools] [PATCH 1/4] lib/common.sh: add 'lock_close'; use it as appropriate. X-BeenThere: arch-projects@archlinux.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Arch Linux projects development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Arch Linux projects development discussion Cc: Luke Shumaker Errors-To: arch-projects-bounces@archlinux.org Sender: "arch-projects" X-UID: 196 Status: X-Keywords: Content-Length: 1547 `lock_close FD` is easier to remember than 'exec FD>&-`; and is especially easier if FD is a variable (though that isn't actually taken advantage of here). This uses Bash 4.1+ `exec {var}>&-`, rather than the clunkier `eval exec "$var>&-"` that was necessary in older versions of Bash. Thanks to Dave Reisner for pointing this new bit of syntax out to me the last time I submitted this (back in 2014, 4.1 had just come out). --- archbuild.in | 2 +- lib/common.sh | 8 ++++++++ makechrootpkg.in | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/archbuild.in b/archbuild.in index a78353c..4d1b351 100644 --- a/archbuild.in +++ b/archbuild.in @@ -55,7 +55,7 @@ if ${clean_first} || [[ ! -d "${chroots}/${repo}-${arch}" ]]; then subvolume_delete_recursive "${copy}" rm -rf --one-file-system "${copy}" done - exec 9>&- + lock_close 9 rm -rf --one-file-system "${chroots}/${repo}-${arch}" mkdir -p "${chroots}/${repo}-${arch}" diff --git a/lib/common.sh b/lib/common.sh index 599be54..689772f 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -159,6 +159,14 @@ slock() { } ## +# usage : lock_close( $fd ) +## +lock_close() { + local fd=$1 + exec {fd}>&- +} + +## # usage: pkgver_equal( $pkgver1, $pkgver2 ) ## pkgver_equal() { diff --git a/makechrootpkg.in b/makechrootpkg.in index dc598f7..ad99334 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -108,7 +108,7 @@ create_chroot() { stat_done # Drop the read lock again - exec 8>&- + lock_close 8 fi # Update mtime