From: Andrew Tropin <andrew@trop.in>
To: "Ludovic Courtès" <ludo@gnu.org>,
"Carlo Zancanaro" <carlo@zancanaro.id.au>
Cc: 66387-done@debbugs.gnu.org, paren@disroot.org
Subject: [bug#66387] [PATCH] home: services: Fix race condition when detecting first login
Date: Fri, 20 Oct 2023 10:55:46 +0400 [thread overview]
Message-ID: <87v8b1hjf1.fsf@trop.in> (raw)
In-Reply-To: <87v8b2xsnl.fsf@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 1555 bytes --]
On 2023-10-19 22:29, Ludovic Courtès wrote:
> 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)
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
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]
prev parent reply other threads:[~2023-10-20 6:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-07 11:59 [bug#66387] [PATCH] home: services: Fix race condition when detecting first login Carlo Zancanaro
2023-10-09 13:08 ` Carlo Zancanaro
2023-10-11 11:57 ` Carlo Zancanaro
2023-10-19 20:29 ` bug#66387: " Ludovic Courtès
2023-10-20 6:55 ` Andrew Tropin [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87v8b1hjf1.fsf@trop.in \
--to=andrew@trop.in \
--cc=66387-done@debbugs.gnu.org \
--cc=carlo@zancanaro.id.au \
--cc=ludo@gnu.org \
--cc=paren@disroot.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).