GNU bug report logs - #66387
[PATCH] home: services: Fix race condition when detecting first login

Previous Next

Package: guix-patches;

Reported by: Carlo Zancanaro <carlo <at> zancanaro.id.au>

Date: Sat, 7 Oct 2023 12:08:02 UTC

Severity: normal

Tags: patch

Done: Ludovic Courtès <ludo <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Andrew Tropin <andrew <at> trop.in>
To: Ludovic Courtès <ludo <at> gnu.org>, Carlo Zancanaro <carlo <at> zancanaro.id.au>
Cc: 66387-done <at> debbugs.gnu.org, paren <at> disroot.org
Subject: [bug#66387] [PATCH] home: services: Fix race condition when detecting first login
Date: Fri, 20 Oct 2023 10:55:46 +0400
[Message part 1 (text/plain, inline)]
On 2023-10-19 22:29, Ludovic Courtès wrote:

> Hi Carlo,
>
> Carlo Zancanaro <carlo <at> 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)

Very nice trick!  Carol, Ludo, Thank you for the fix!

>           (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
>  

-- 
Best regards,
Andrew Tropin
[signature.asc (application/pgp-signature, inline)]

This bug report was last modified 1 year and 275 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.