me
/
guix
Archived
1
0
Fork 0

syscalls: 'with-file-lock' re-grabs lock when reentering its dynamic extent.

* guix/build/syscalls.scm (call-with-file-lock)
(call-with-file-lock/no-wait): Initialize PORT in the 'dynamic-wind'
"in" handler.  This allows us to re-enter a captured continuation and
have the lock grabbed anew.
master
Ludovic Courtès 2020-03-19 11:14:29 +01:00
parent 1550db6fd4
commit 9a067fe7ee
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
1 changed files with 33 additions and 31 deletions

View File

@ -1104,47 +1104,49 @@ exception if it's already taken."
#t) #t)
(define (call-with-file-lock file thunk) (define (call-with-file-lock file thunk)
(let ((port (catch 'system-error (let ((port #f))
(lambda ()
(lock-file file))
(lambda args
;; 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 args))
#f
(apply throw args))))))
(dynamic-wind (dynamic-wind
(lambda () (lambda ()
#t) (set! port
(catch 'system-error
(lambda ()
(lock-file file))
(lambda args
;; 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 args))
#f
(apply throw args))))))
thunk thunk
(lambda () (lambda ()
(when port (when port
(unlock-file port)))))) (unlock-file port))))))
(define (call-with-file-lock/no-wait file thunk handler) (define (call-with-file-lock/no-wait file thunk handler)
(let ((port (catch #t (let ((port #f))
(lambda ()
(lock-file file #:wait? #f))
(lambda (key . args)
(match key
('flock-error
(apply handler args)
;; No open port to the lock, so return #f.
#f)
('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 key args)))
(_ (apply throw key args)))))))
(dynamic-wind (dynamic-wind
(lambda () (lambda ()
#t) (set! port
(catch #t
(lambda ()
(lock-file file #:wait? #f))
(lambda (key . args)
(match key
('flock-error
(apply handler args)
;; No open port to the lock, so return #f.
#f)
('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 key args)))
(_ (apply throw key args)))))))
thunk thunk
(lambda () (lambda ()
(when port (when port