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.
This commit is contained in:
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

View file

@ -1104,7 +1104,11 @@ (define (unlock-file port)
#t)
(define (call-with-file-lock file thunk)
(let ((port (catch 'system-error
(let ((port #f))
(dynamic-wind
(lambda ()
(set! port
(catch 'system-error
(lambda ()
(lock-file file))
(lambda args
@ -1115,16 +1119,17 @@ (define (call-with-file-lock file thunk)
(if (= ENOSYS (system-error-errno args))
#f
(apply throw args))))))
(dynamic-wind
(lambda ()
#t)
thunk
(lambda ()
(when port
(unlock-file port))))))
(define (call-with-file-lock/no-wait file thunk handler)
(let ((port (catch #t
(let ((port #f))
(dynamic-wind
(lambda ()
(set! port
(catch #t
(lambda ()
(lock-file file #:wait? #f))
(lambda (key . args)
@ -1142,9 +1147,6 @@ (define (call-with-file-lock/no-wait file thunk handler)
#f
(apply throw key args)))
(_ (apply throw key args)))))))
(dynamic-wind
(lambda ()
#t)
thunk
(lambda ()
(when port