From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:403:478a::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id gFweD/mNJmUeWQEAauVa8A:P1 (envelope-from ) for ; Wed, 11 Oct 2023 13:58:49 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:478a::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id gFweD/mNJmUeWQEAauVa8A (envelope-from ) for ; Wed, 11 Oct 2023 13:58:49 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id B15DC43DA0 for ; Wed, 11 Oct 2023 13:58:48 +0200 (CEST) Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=zancanaro.id.au header.s=k1 header.b=Wg8QwHPB; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=zancanaro.id.au (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1697025529; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=xSfowpn6ptj3E0eO6DXSIuON0h7+cn6GdA62mhtGlzk=; b=F6uL6ZPzhKI79JPZ0vRjQneMKvWxd37SzqdDL7L8dfrAyKVaZR6RzX/7MYxPBVfrknYj0D Mq4reTgxgl5OgS0YadqfACUw+nWPSK/Vjp3mCwJjoWwVUF9cgTTuSKtB2QAAk3HOgc/DKB Zwc1PkdN8D8nE4CJK0vxKspU8pPwbPk2Xg39SxAih4RR92AKMDwC701NpjC2N3jsi3e1Xe yHsnQQLQpELMb5MQxph8ry9c8Q7T856erz5VLqATVbz4pr+bCCuqZRW8nFDRVacXc5y9rY pp1a6ookBObVu1RhP9I0nsMNe6O8FKTSPFXS7bV/r9RGX73hn89WnOflISgE0w== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1697025529; a=rsa-sha256; cv=none; b=PQsgRcGTrHAGcfjcZvOlg0xnPDq20DZ4n7P+zdvtXBm/EvRRnuWKQcKeZEUQywINihH3Dd qZSHDl/EXqzcoLc9jpfVLW0XV3L8/PdKYyyzARMW35JP0FgOYCgiQiXQ49AImC8k5E69sc uL8zdxhkM0T5tDXnCC7poJhiJVI9JGzQ3GBpThsa4VUOCSkF1yA7ucprZYUnP7/dMR7+je 28Pbh47p6F7khquHHCsFz9m9geL0InrRCfrj0i+Lu9HKS/2qfceVoXRt2MGc2vTm6MFXM5 ttLtoD4lAMpfkj1vVGwqtJrRyCHBGhG9YMO6TcEJRrDVwJmzHjLo6+11GahfrA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=zancanaro.id.au header.s=k1 header.b=Wg8QwHPB; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=zancanaro.id.au (policy=none) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqXrQ-0000Xr-8y; Wed, 11 Oct 2023 07:58:44 -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 1qqXrM-0000XS-Rl for guix-patches@gnu.org; Wed, 11 Oct 2023 07:58:40 -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 1qqXrM-0000XX-Cx for guix-patches@gnu.org; Wed, 11 Oct 2023 07:58:40 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qqXri-0000Bu-4b for guix-patches@gnu.org; Wed, 11 Oct 2023 07:59:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#66387] [PATCH] home: services: Fix race condition when detecting first login Resent-From: Carlo Zancanaro Original-Sender: "Debbugs-submit" Resent-CC: , guix-patches@gnu.org Resent-Date: Wed, 11 Oct 2023 11:59:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66387 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 66387@debbugs.gnu.org Cc: ( , Andrew Tropin , Ludovic =?UTF-8?Q?Court=C3=A8s?= X-Debbugs-Original-Xcc: ( , Andrew Tropin , Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 66387-submit@debbugs.gnu.org id=B66387.1697025517701 (code B ref 66387); Wed, 11 Oct 2023 11:59:02 +0000 Received: (at 66387) by debbugs.gnu.org; 11 Oct 2023 11:58:37 +0000 Received: from localhost ([127.0.0.1]:37687 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qqXrI-0000BF-Q4 for submit@debbugs.gnu.org; Wed, 11 Oct 2023 07:58:37 -0400 Received: from voltorb.zancanaro.id.au ([45.77.50.64]:59542) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qqXrG-0000B3-5v for 66387@debbugs.gnu.org; Wed, 11 Oct 2023 07:58:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; s=k1; bh=xSfowpn6ptj3E0e O6DXSIuON0h7+cn6GdA62mhtGlzk=; h=references:in-reply-to:date:subject: to:from; d=zancanaro.id.au; b=Wg8QwHPBGWtrrSteFCwEHYTWgZbD2jGSRe5gxzw5 RaeFXD9gtfFJRfSMYa0cjpDbN3cW5qhdOfnP533JzshWK7UvnC+x0mhKFY5XLw6xBw+38g bgKVCxAKeoFCa1Es05xQ6TPpx+h84AyVIrrdMpiqjc20E8G9XSBHof+zvte8Q= Received: by voltorb.zancanaro.id.au (OpenSMTPD) with ESMTPSA id 1f5d753f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for <66387@debbugs.gnu.org>; Wed, 11 Oct 2023 11:57:46 +0000 (UTC) From: Carlo Zancanaro Date: Wed, 11 Oct 2023 22:57:19 +1100 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: <87bkd8djri.fsf@zancanaro.id.au> References: <87bkd8djri.fsf@zancanaro.id.au> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Spam-Score: 3.80 X-Migadu-Queue-Id: B15DC43DA0 X-Migadu-Scanner: mx0.migadu.com X-Migadu-Spam-Score: 3.80 X-TUID: rF5xHiWc/MAs * gnu/home/services.scm (compute-on-first-login-script): Use open to atomically check whether a file exists and create it if not. --- gnu/home/services.scm | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/gnu/home/services.scm b/gnu/home/services.scm index 8d53f2f4d3..7137925b30 100644 --- a/gnu/home/services.scm +++ b/gnu/home/services.scm @@ -2,6 +2,7 @@ ;;; Copyright © 2021-2023 Andrew Tropin ;;; Copyright © 2021 Xinglu Chen ;;; Copyright © 2022-2023 Ludovic Courtès +;;; Copyright © 2023 Carlo Zancanaro ;;; ;;; This file is part of GNU Guix. ;;; @@ -412,20 +413,29 @@ (define (compute-on-first-login-script _ gexps) #~(begin (use-modules (guix i18n) (guix diagnostics)) + + (define (claim-first-run file-name) + (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))) + #t) + (lambda _ + #f))) + #$%initialize-gettext (let* ((xdg-runtime-dir (or (getenv "XDG_RUNTIME_DIR") (format #f "/run/user/~a" (getuid)))) (flag-file-path (string-append - xdg-runtime-dir "/on-first-login-executed")) - (touch (lambda (file-name) - (call-with-output-file file-name (const #t))))) + xdg-runtime-dir "/on-first-login-executed"))) ;; XDG_RUNTIME_DIR dissapears on logout, that means such trick ;; allows to launch on-first-login script on first login only ;; after complete logout/reboot. (if (file-exists? xdg-runtime-dir) - (unless (file-exists? flag-file-path) - (begin #$@gexps (touch flag-file-path))) + (when (claim-first-run flag-file-path) + #$@gexps) ;; TRANSLATORS: 'on-first-login' is the name of a service and ;; shouldn't be translated (warning (G_ "XDG_RUNTIME_DIR doesn't exists, on-first-login script base-commit: 9ad9113fc238ee8de5191a5e15b5153fd149e9fa -- 2.41.0