From patchwork Thu Oct 19 20:29:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 55061 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 0BC6127BBE9; Thu, 19 Oct 2023 21:31:20 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 10D8227BBE2 for ; Thu, 19 Oct 2023 21:31:19 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtZfC-0002Tu-Dr; Thu, 19 Oct 2023 16:30:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qtZf9-0002T4-VT for guix-patches@gnu.org; Thu, 19 Oct 2023 16:30:35 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtZf9-000522-Mz for guix-patches@gnu.org; Thu, 19 Oct 2023 16:30:35 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qtZfa-0000h8-1E for guix-patches@gnu.org; Thu, 19 Oct 2023 16:31:02 -0400 Subject: bug#66387: [PATCH] home: services: Fix race condition when detecting first login Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-To: guix-patches@gnu.org Resent-Date: Thu, 19 Oct 2023 20:31:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 66387 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Carlo Zancanaro Cc: 66387-done@debbugs.gnu.org, Andrew Tropin , paren@disroot.org Mail-Followup-To: 66387@debbugs.gnu.org, ludo@gnu.org, carlo@zancanaro.id.au Received: via spool by 66387-done@debbugs.gnu.org id=D66387.16977474142596 (code D ref 66387); Thu, 19 Oct 2023 20:31:01 +0000 Received: (at 66387-done) by debbugs.gnu.org; 19 Oct 2023 20:30:14 +0000 Received: from localhost ([127.0.0.1]:37924 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qtZen-0000fo-Vi for submit@debbugs.gnu.org; Thu, 19 Oct 2023 16:30:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41700) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qtZel-0000eS-2v for 66387-done@debbugs.gnu.org; Thu, 19 Oct 2023 16:30:13 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qtZeC-0004iR-V7; Thu, 19 Oct 2023 16:29:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=YuqmrsYRuZzp5Hu4lr6tEXVqT58o0HgxfKW4i77voLg=; b=Zh+f3B5mIHAynh35A9FD 8NPi4KgMe62Q9yJHOTl0NKpl/xVHqpxY0fy9C+FgwwVLRTRYEiIPOG/faRjRPboTkLoOXxlz97bKj 3A3ztyHswunyllo4shdYdvjsZQA5pTtY6VOLhECgTFRjU4G1hZziJUy2ZUtXLBKTGfgLVAUgYNhnH YW22sb7qMtLqVKb08QMZb607eSdMfQ59Cg7TyAiqdSR/P4i3C9oh0MYNTylqIZTGWVC2hmKk2yMmm w2i9dcUjXPfulGgzEyhjBuQ1CAIn80z69fL7u2s0FcA4mlIGkAqdvolJE+Gh9IrgqgUlvczjyLMPo IlGGfE+qhl3Vsw==; From: Ludovic =?utf-8?q?Court=C3=A8s?= In-Reply-To: (Carlo Zancanaro's message of "Wed, 11 Oct 2023 22:57:19 +1100") References: <87bkd8djri.fsf@zancanaro.id.au> Date: Thu, 19 Oct 2023 22:29:34 +0200 Message-ID: <87v8b2xsnl.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches Hi Carlo, Carlo Zancanaro 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