syscalls: 'with-lock-file' catches ENOSYS.
authorLudovic Courtès <ludo@gnu.org>
Mon, 3 Jun 2019 15:13:30 +0000 (17:13 +0200)
committerLudovic Courtès <ludo@gnu.org>
Wed, 5 Jun 2019 21:10:36 +0000 (23:10 +0200)
* guix/build/syscalls.scm (call-with-file-lock): Catch ENOSYS raised by
'lock-file'.

guix/build/syscalls.scm

index 3af41f2..5c2eb3c 100644 (file)
@@ -1084,13 +1084,24 @@ exception if it's already taken."
   #t)
 
 (define (call-with-file-lock file thunk)
-  (let ((port (lock-file file)))
+  (let ((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))))))
     (dynamic-wind
       (lambda ()
         #t)
       thunk
       (lambda ()
-        (unlock-file port)))))
+        (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."