[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
108/182: guix: Add file-locking with no wait.
From: |
guix-commits |
Subject: |
108/182: guix: Add file-locking with no wait. |
Date: |
Fri, 15 Nov 2019 00:01:49 -0500 (EST) |
kkebreau pushed a commit to branch wip-gnome-updates
in repository guix.
commit 9453497c54141a8b514c71f93765e1c57380c578
Author: Julien Lepiller <address@hidden>
Date: Thu Nov 7 21:50:54 2019 +0100
guix: Add file-locking with no wait.
* guix/build/syscalls.scm (with-file-lock/no-wait): New procedure.
(lock-file): Take a #:wait? key.
---
guix/build/syscalls.scm | 35 +++++++++++++++++++++++++++++++++--
1 file changed, 33 insertions(+), 2 deletions(-)
diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm
index bbf2531..a5a9c92 100644
--- a/guix/build/syscalls.scm
+++ b/guix/build/syscalls.scm
@@ -80,6 +80,7 @@
lock-file
unlock-file
with-file-lock
+ with-file-lock/no-wait
set-thread-name
thread-name
@@ -1087,10 +1088,10 @@ exception if it's already taken."
;; Presumably we got EAGAIN or so.
(throw 'flock-error err))))))
-(define (lock-file file)
+(define* (lock-file file #:key (wait? #t))
"Wait and acquire an exclusive lock on FILE. Return an open port."
(let ((port (open-file file "w0")))
- (fcntl-flock port 'write-lock)
+ (fcntl-flock port 'write-lock #:wait? wait?)
port))
(define (unlock-file port)
@@ -1119,10 +1120,40 @@ exception if it's already taken."
(when port
(unlock-file port))))))
+(define (call-with-file-lock/no-wait file thunk handler)
+ (let ((port (catch #t
+ (lambda ()
+ (lock-file file #:wait? #f))
+ (lambda (key . args)
+ (match key
+ ('flock-error
+ (handler args))
+ ('system-error
+ ;; When using the statically-linked Guile in the initrd,
+ ;; 'fcntl-flock' returns ENOSYS unconditionally. Ignore
+ ;; that error since we're typically the only process
running
+ ;; at this point.
+ (if (= ENOSYS (system-error-errno (cons key args)))
+ #f
+ (apply throw args)))
+ (_ (apply throw key args)))))))
+ (dynamic-wind
+ (lambda ()
+ #t)
+ thunk
+ (lambda ()
+ (when port
+ (unlock-file port))))))
+
(define-syntax-rule (with-file-lock file exp ...)
"Wait to acquire a lock on FILE and evaluate EXP in that context."
(call-with-file-lock file (lambda () exp ...)))
+(define-syntax-rule (with-file-lock/no-wait file handler exp ...)
+ "Try to acquire a lock on FILE and evaluate EXP in that context. Execute
+handler if the lock is already held by another process."
+ (call-with-file-lock/no-wait file (lambda () exp ...) handler))
+
;;;
;;; Miscellaneous, aka. 'prctl'.
- 116/182: gnu: perl-danga-socket: Update to 1.62., (continued)
- 116/182: gnu: perl-danga-socket: Update to 1.62., guix-commits, 2019/11/15
- 83/182: services: Make it possible to include dynamic modules in nginx., guix-commits, 2019/11/15
- 91/182: gnu: libssh: Update to 0.9.2., guix-commits, 2019/11/15
- 93/182: gnu: polybar: Update to 3.4.1., guix-commits, 2019/11/15
- 101/182: gnu: r-hmisc: Update to 4.3-0., guix-commits, 2019/11/15
- 109/182: guix: package: lock profiles when processing them., guix-commits, 2019/11/15
- 107/182: services: mpd: Connect to the user's PulseAudio socket., guix-commits, 2019/11/15
- 113/182: gnu: Add gnome-shell-extension-noannoyance., guix-commits, 2019/11/15
- 119/182: gnu: python-latexcodec: Update to 1.0.7., guix-commits, 2019/11/15
- 92/182: gnu: Fix deprecation of monolithic Qt 5.x package., guix-commits, 2019/11/15
- 108/182: guix: Add file-locking with no wait.,
guix-commits <=
- 112/182: gnu: Add gnome-shell-extension-dash-to-dock., guix-commits, 2019/11/15
- 121/182: ui: Produce hyperlinks for the 'location' field of search results., guix-commits, 2019/11/15
- 125/182: gnu: Add homebank., guix-commits, 2019/11/15
- 137/182: gnu: perl-file-configdir: Update to 0.021., guix-commits, 2019/11/15
- 120/182: gnu: botan: Update to 2.12.1., guix-commits, 2019/11/15
- 130/182: gnu: botan: Use getentropy()., guix-commits, 2019/11/15
- 123/182: news: Add Spanish translation., guix-commits, 2019/11/15
- 129/182: gnu: botan: Optimise., guix-commits, 2019/11/15
- 128/182: gnu: miniupnpc: Don't use NAME in source URI., guix-commits, 2019/11/15
- 133/182: gnu: fribidi: Fix CVE-2019-18397., guix-commits, 2019/11/15