Github messages for voidlinux
 help / color / mirror / Atom feed
* [PR PATCH] xbps-src: fixed dangling binpkg lock on error
@ 2020-08-10  6:01 Noah-Huppert
  2020-08-10  6:03 ` [PR PATCH] [Updated] " Noah-Huppert
                   ` (16 more replies)
  0 siblings, 17 replies; 18+ messages in thread
From: Noah-Huppert @ 2020-08-10  6:01 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 4163 bytes --]

There is a new pull request by Noah-Huppert against master on the void-packages repository

https://github.com/Noah-Huppert/void-packages binpkgs-lock-fix
https://github.com/void-linux/void-packages/pull/24191

xbps-src: fixed dangling binpkg lock on error
Fixes #21020. 

Previously if a binpkg failed to be created due to [`xbps-create` falling over in `common/hooks/do-pkg/00-gen-pkg.sh`](https://github.com/void-linux/void-packages/blob/master/common/hooks/do-pkg/00-gen-pkg.sh#L63) it would leave a `hostdir/binpkgs/*.lock` file around.

This fix traps `ERR` right after the lock file is created. If an error occurs it deletes the lock file. Right before the lock file is deleted it untraps `ERR`.

There was a[ `xbps-create` return value check in the source](https://github.com/void-linux/void-packages/blob/master/common/hooks/do-pkg/00-gen-pkg.sh#L88-L95). However I think the script is running with `set -e` which results in the failure of `xbps-create` exiting the process. Trapping `ERR` prevents the process from exiting.

**Before**  
Before these changes when a binpkg build failed due to `xbps-create` falling over it would look like so:

```
=> kernel-libc-headers-4.19.0_2: running do-pkg hook: 00-gen-pkg ...
=> Creating kernel-libc-headers-4.19.0_2.x86_64.xbps for repository /home/noah/documents/void-packages/hostdir/binpkgs ...
xbps-create: ERROR: Failed to open .xbps-pkg-XXX7c01am fd for writing: No such file or directory
[noah@ip-172-31-47-23 void-packages]$ => ERROR: kernel-libc-headers-4.19.0_2: do-pkg_00-gen-pkg: 'xbps-create ${_provides:+--provides "${_provides}"} ${_conflicts:+--conflicts "${_conflicts}"} ${_replaces:+--replaces "${_replaces}"} ${_reverts:+--reverts "${_reverts}"} ${_mutable_files:+--mutable-files "${_mutable_files}"} ${_deps:+--dependencies "${_deps}"} ${_conf_files:+--config-files "${_conf_files}"} ${PKG_BUILD_OPTIONS:+--build-options "${PKG_BUILD_OPTIONS}"} ${_gitrevs:+--source-revisions "${_gitrevs}"} ${_shprovides:+--shlib-provides "${_shprovides}"} ${_shrequires:+--shlib-requires "${_shrequires}"} ${_alternatives:+--alternatives "${_alternatives}"} ${_preserve:+--preserve} ${tags:+--tags "${tags}"} ${_changelog:+--changelog "${_changelog}"} ${XBPS_PKG_COMPTYPE:+--compression $XBPS_PKG_COMPTYPE} --architecture ${arch} --homepage "${homepage}" --license "${license}" --maintainer "${maintainer}" --desc "${desc}" --pkgver "${pkgver}" --quiet ${PKGDESTDIR}' exited with 1
=> ERROR:   in genpkg() at common/hooks/do-pkg/00-gen-pkg.sh:64
=> ERROR:   in hook() at common/hooks/do-pkg/00-gen-pkg.sh:121
=> ERROR:   in run_func() at common/xbps-src/shutils/common.sh:21
=> ERROR:   in run_pkg_hooks() at common/xbps-src/shutils/common.sh:232
=> ERROR:   in main() at common/xbps-src/libexec/xbps-src-dopkg.sh:44
```

When you tried to re-build any package which previously had a failed binpkg it would hang forever like so:

```
./xbps-src pkg kernel-libc-headers
=> kernel-libc-headers-4.19.0_2: running do-pkg hook: 00-gen-pkg ...
=> WARNING: kernel-libc-headers-4.19.0_2: binpkg is being created, waiting for 1s...
=> WARNING: kernel-libc-headers-4.19.0_2: binpkg is being created, waiting for 1s...
=> WARNING: kernel-libc-headers-4.19.0_2: binpkg is being created, waiting for 1s...
=> WARNING: kernel-libc-headers-4.19.0_2: binpkg is being created, waiting for 1s...
...
```

**After**  

With the changes a binpkg build failing due to xbps-create appears as:

```
=> Creating kernel-libc-headers-4.19.0_2.x86_64.xbps for repository /home/noah/documents/void-packages/hostdir/binpkgs ...
xbps-create: ERROR: Failed to open .xbps-pkg-XXX316nSv fd for writing: No such file or directory
=> Unlocking kernel-libc-headers-4.19.0_2.x86_64.xbps.lock because an error occurred during kernel-libc-headers-4.19.0_2.x86_64.xbps creationrval="1"
=> ERROR: Failed to created binary package: kernel-libc-headers-4.19.0_2.x86_64.xbps!
```

When you try to re-build any package with a previously failed binpkg the lock file does not exist. So the build will run normally. 

A patch file from https://github.com/void-linux/void-packages/pull/24191.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-binpkgs-lock-fix-24191.patch --]
[-- Type: text/x-diff, Size: 1018 bytes --]

From 755e76c2da90a3d95e95774ab7be031e8898da66 Mon Sep 17 00:00:00 2001
From: Noah Huppert <contact@noahh.io>
Date: Mon, 10 Aug 2020 01:54:35 -0400
Subject: [PATCH] xbps-src: fixed dangling binpkg lock on error

---
 common/hooks/do-pkg/00-gen-pkg.sh | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/common/hooks/do-pkg/00-gen-pkg.sh b/common/hooks/do-pkg/00-gen-pkg.sh
index e6285b6e4ff..505883f4a74 100644
--- a/common/hooks/do-pkg/00-gen-pkg.sh
+++ b/common/hooks/do-pkg/00-gen-pkg.sh
@@ -23,7 +23,14 @@ genpkg() {
 		return 0
 	fi
 
+	# Lock binpkg
+	unlock_binpkg() {
+	    msg_normal "Unlocking ${binpkg}.lock because an error occurred during $binpkg creation"
+	    rm -f $pkgdir/${binpkg}.lock
+	}
+
 	touch -f $pkgdir/${binpkg}.lock
+	trap unlock_binpkg ERR
 
 	if [ ! -d $pkgdir ]; then
 		mkdir -p $pkgdir
@@ -86,7 +93,10 @@ genpkg() {
 		--quiet \
 		${PKGDESTDIR}
 	rval=$?
+	echo "rval=\"$rval\""
 
+	# Unlock binpkg
+	trap - ERR
 	rm -f $pkgdir/${binpkg}.lock
 
 	if [ $rval -ne 0 ]; then

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2020-08-19 20:33 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-10  6:01 [PR PATCH] xbps-src: fixed dangling binpkg lock on error Noah-Huppert
2020-08-10  6:03 ` [PR PATCH] [Updated] " Noah-Huppert
2020-08-10  6:04 ` Noah-Huppert
2020-08-10  6:20 ` [PR REVIEW] " Noah-Huppert
2020-08-10  6:29 ` [PR PATCH] [Updated] " Noah-Huppert
2020-08-10  6:30 ` Noah-Huppert
2020-08-10  6:33 ` Noah-Huppert
2020-08-10  6:34 ` [PR REVIEW] " Noah-Huppert
2020-08-10 15:28 ` Noah-Huppert
2020-08-10 15:33 ` ahesford
2020-08-10 15:35 ` [PR PATCH] [Updated] " Noah-Huppert
2020-08-10 15:37 ` [PR REVIEW] " Noah-Huppert
2020-08-10 15:51 ` ahesford
2020-08-10 16:47 ` [PR PATCH] [Updated] " Noah-Huppert
2020-08-10 16:47 ` Noah-Huppert
2020-08-17 13:42 ` [PR PATCH] [Closed]: " ahesford
2020-08-17 13:45 ` ahesford
2020-08-19 20:33 ` Noah-Huppert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).