From debbugs-submit-bounces@debbugs.gnu.org Mon Dec 07 08:17:24 2020 Received: (at submit) by debbugs.gnu.org; 7 Dec 2020 13:17:24 +0000 Received: from localhost ([127.0.0.1]:52862 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kmGOJ-00005t-Mr for submit@debbugs.gnu.org; Mon, 07 Dec 2020 08:17:24 -0500 Received: from lists.gnu.org ([209.51.188.17]:50316) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kmGOH-00005l-5y for submit@debbugs.gnu.org; Mon, 07 Dec 2020 08:17:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36530) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmGOG-0005KT-C4 for guix-patches@gnu.org; Mon, 07 Dec 2020 08:17:20 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]:53817) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kmGOG-0001mu-4w for guix-patches@gnu.org; Mon, 07 Dec 2020 08:17:20 -0500 Received: from [2a01:e0a:19b:d9a0:34f0:bcad:cad1:16d6] (port=32976 helo=localhost.localdomain) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1kmGOF-0002Vy-7v; Mon, 07 Dec 2020 08:17:19 -0500 From: Mathieu Othacehe To: guix-patches@gnu.org Subject: [PATCH] scripts: discover: Remove file locks. Date: Mon, 7 Dec 2020 14:17:06 +0100 Message-Id: <20201207131706.96073-1-othacehe@gnu.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: submit Cc: Mathieu Othacehe X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) * guix/scripts/discover.scm (call-once, call-with-output-file/atomic): New procedures copied from (system base compile). (call-with-read-file-lock, with-read-file-lock): Remove them. (write-publish-file): Use "call-with-output-file/atomic" instead of "with-file-lock". (read-substitute-urls): Remve file lock. --- guix/scripts/discover.scm | 86 +++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 40 deletions(-) diff --git a/guix/scripts/discover.scm b/guix/scripts/discover.scm index 007db0d49d..86834a7afb 100644 --- a/guix/scripts/discover.scm +++ b/guix/scripts/discover.scm @@ -75,50 +75,60 @@ CACHE-DIRECTORY." (define %publish-file (make-parameter (publish-file %state-directory))) +;; XXX: Copied from (system base compile). +(define (call-once thunk) + (let ((entered #f)) + (dynamic-wind + (lambda () + (when entered + (error "thunk may only be entered once: ~a" thunk)) + (set! entered #t)) + thunk + (lambda () #t)))) + +(define* (call-with-output-file/atomic filename proc #:optional reference) + (let* ((template (string-append filename ".XXXXXX")) + (tmp (mkstemp! template "wb"))) + (call-once + (lambda () + (with-throw-handler #t + (lambda () + (proc tmp) + ;; Chmodding by name instead of by port allows this chmod to + ;; work on systems without fchmod, like MinGW. + (let ((perms (or (false-if-exception (stat:perms (stat reference))) + (lognot (umask))))) + (chmod template (logand #o0666 perms))) + (close-port tmp) + (rename-file template filename)) + (lambda args + (close-port tmp) + (delete-file template))))))) + (define* (write-publish-file #:key (file (%publish-file))) "Dump the content of %PUBLISH-SERVICES hash table into FILE. Use a write lock on FILE to synchronize with any potential readers." - (with-file-lock file - (call-with-output-file file - (lambda (port) - (hash-for-each - (lambda (name service) - (format port "http://~a:~a~%" - (avahi-service-address service) - (avahi-service-port service))) - %publish-services))) - (chmod file #o644))) - -(define (call-with-read-file-lock file thunk) - "Call THUNK with a read lock on FILE." - (let ((port #f)) - (dynamic-wind - (lambda () - (set! port - (let ((port (open-file file "r0"))) - (fcntl-flock port 'read-lock) - port))) - thunk - (lambda () - (when port - (unlock-file port)))))) - -(define-syntax-rule (with-read-file-lock file exp ...) - "Wait to acquire a read lock on FILE and evaluate EXP in that context." - (call-with-read-file-lock file (lambda () exp ...))) + (call-with-output-file/atomic file + (lambda (port) + (hash-for-each + (lambda (name service) + (format port "http://~a:~a~%" + (avahi-service-address service) + (avahi-service-port service))) + %publish-services))) + (chmod file #o644)) (define* (read-substitute-urls #:key (file (%publish-file))) "Read substitute urls list from FILE and return it. Use a read lock on FILE to synchronize with the writer." (if (file-exists? file) - (with-read-file-lock file - (call-with-input-file file - (lambda (port) - (let loop ((url (read-line port)) - (urls '())) - (if (eof-object? url) - urls - (loop (read-line port) (cons url urls))))))) + (call-with-input-file file + (lambda (port) + (let loop ((url (read-line port)) + (urls '())) + (if (eof-object? url) + urls + (loop (read-line port) (cons url urls)))))) '())) @@ -158,7 +168,3 @@ to synchronize with the writer." (mkdir-p (dirname publish-file)) (avahi-browse-service-thread service-proc #:types %services))))) - -;;; Local Variables: -;;; eval: (put 'with-read-file-lock 'scheme-indent-function 1) -;;; End: -- 2.29.2 From debbugs-submit-bounces@debbugs.gnu.org Sat Dec 12 14:52:26 2020 Received: (at 45101) by debbugs.gnu.org; 12 Dec 2020 19:52:26 +0000 Received: from localhost ([127.0.0.1]:46695 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1koAwL-0006yC-Pu for submit@debbugs.gnu.org; Sat, 12 Dec 2020 14:52:25 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48388) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1koAwK-0006xw-Mj for 45101@debbugs.gnu.org; Sat, 12 Dec 2020 14:52:25 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]:50744) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1koAwE-0002g5-Ca for 45101@debbugs.gnu.org; Sat, 12 Dec 2020 14:52:18 -0500 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=34760 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1koAvy-0000sq-TG; Sat, 12 Dec 2020 14:52:14 -0500 From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: Mathieu Othacehe Subject: Re: [bug#45101] [PATCH] scripts: discover: Remove file locks. References: <20201207131706.96073-1-othacehe@gnu.org> Date: Sat, 12 Dec 2020 20:52:01 +0100 In-Reply-To: <20201207131706.96073-1-othacehe@gnu.org> (Mathieu Othacehe's message of "Mon, 7 Dec 2020 14:17:06 +0100") Message-ID: <87o8iy2466.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 45101 Cc: 45101@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Hi! Mathieu Othacehe skribis: > * guix/scripts/discover.scm (call-once, call-with-output-file/atomic): New > procedures copied from (system base compile). > (call-with-read-file-lock, with-read-file-lock): Remove them. > (write-publish-file): Use "call-with-output-file/atomic" instead of > "with-file-lock". > (read-substitute-urls): Remve file lock. I think you could use =E2=80=98with-atomic-file-output=E2=80=99 from (guix = utils). (Apologies if I gave you the wrong name before!) Apart from that LGTM, thanks! :-) Ludo=E2=80=99. From debbugs-submit-bounces@debbugs.gnu.org Sun Dec 13 07:25:49 2020 Received: (at 45101-done) by debbugs.gnu.org; 13 Dec 2020 12:25:49 +0000 Received: from localhost ([127.0.0.1]:47592 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1koQRh-00012i-3q for submit@debbugs.gnu.org; Sun, 13 Dec 2020 07:25:49 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43774) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1koQRg-00012M-B7 for 45101-done@debbugs.gnu.org; Sun, 13 Dec 2020 07:25:48 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]:34796) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1koQRb-0005R6-4g; Sun, 13 Dec 2020 07:25:43 -0500 Received: from [2a01:e0a:19b:d9a0:69ea:da6a:415c:952b] (port=54714 helo=cervin) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1koQRV-0006nV-LU; Sun, 13 Dec 2020 07:25:38 -0500 From: Mathieu Othacehe To: Ludovic =?utf-8?Q?Court=C3=A8s?= Subject: Re: [bug#45101] [PATCH] scripts: discover: Remove file locks. References: <20201207131706.96073-1-othacehe@gnu.org> <87o8iy2466.fsf@gnu.org> Date: Sun, 13 Dec 2020 13:25:36 +0100 In-Reply-To: <87o8iy2466.fsf@gnu.org> ("Ludovic =?utf-8?Q?Court=C3=A8s=22'?= =?utf-8?Q?s?= message of "Sat, 12 Dec 2020 20:52:01 +0100") Message-ID: <877dplao5b.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 45101-done Cc: 45101-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Hey, > I think you could use =E2=80=98with-atomic-file-output=E2=80=99 from (gui= x utils). > (Apologies if I gave you the wrong name before!) > > Apart from that LGTM, thanks! :-) Fixed and pushed! Thanks, Mathieu From unknown Sat Jun 21 12:16:05 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Mon, 11 Jan 2021 12:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator