guix-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#66387: [PATCH] home: services: Fix race condition when detecting fir


From: Ludovic Courtès
Subject: bug#66387: [PATCH] home: services: Fix race condition when detecting first login
Date: Thu, 19 Oct 2023 22:29:34 +0200
User-agent: Gnus/5.13 (Gnus v5.13)

Hi Carlo,

Carlo Zancanaro <carlo@zancanaro.id.au> skribis:

> * gnu/home/services.scm (compute-on-first-login-script): Use open to
> atomically check whether a file exists and create it if not.

Good catch!

I made the following cosmetic changes (‘open-fdes’ is cheaper than
‘open’) and applied it.

Thanks!

Ludo’.

diff --git a/gnu/home/services.scm b/gnu/home/services.scm
index 7137925b30..651c068f79 100644
--- a/gnu/home/services.scm
+++ b/gnu/home/services.scm
@@ -414,15 +414,15 @@ (define (compute-on-first-login-script _ gexps)
          (use-modules (guix i18n)
                       (guix diagnostics))
 
-       (define (claim-first-run file-name)
+       (define (claim-first-run file)
          (catch #t
            (lambda ()
-             ;; This incantation will raise an error if the file at
-             ;; flag-file-path already exists, and will create it otherwise.
-             (close (open file-name (logior O_CREAT O_EXCL)))
+             ;; This incantation raises an error if FILE already exists, and
+             ;; creates it otherwise.
+             (close-fdes
+              (open-fdes file (logior O_CREAT O_EXCL O_CLOEXEC)))
              #t)
-           (lambda _
-             #f)))
+           (const #f)))
 
        #$%initialize-gettext
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]