From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Subject: bug#36375: [PATCH] Re: =?UTF-8?Q?=E2=80=98guix_?= =?UTF-8?Q?package=E2=80=99?= should lock the profile Date: Fri, 25 Oct 2019 23:21:34 +0200 Message-ID: <87tv7wldwh.fsf@gnu.org> References: <875zotn4c1.fsf@gnu.org> <20191025214451.284c3530@sybil.lepiller.eu> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:40484) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iO724-0005c1-FP for bug-guix@gnu.org; Fri, 25 Oct 2019 17:22:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iO722-000275-O1 for bug-guix@gnu.org; Fri, 25 Oct 2019 17:22:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:58890) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iO722-00026l-7N for bug-guix@gnu.org; Fri, 25 Oct 2019 17:22:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iO721-0002s9-V8 for bug-guix@gnu.org; Fri, 25 Oct 2019 17:22:02 -0400 Sender: "Debbugs-submit" Resent-Message-ID: In-Reply-To: <20191025214451.284c3530@sybil.lepiller.eu> (Julien Lepiller's message of "Fri, 25 Oct 2019 21:44:51 +0200") List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+gcggb-bug-guix=m.gmane.org@gnu.org Sender: "bug-Guix" To: Julien Lepiller Cc: 36375@debbugs.gnu.org Hello, Julien Lepiller skribis: > attached is a patch for guix package to grab a lock file. Note that I'm > using flock, so it won't work on NFS shares. The other option would be > to use fcntl but guile doesn't seem to implement the locking function > from it. (guix build syscalls) has it though, so you should probably use it. :-) > From 987e9711f1fa6bfd270e48ee5624f69696e7e5c4 Mon Sep 17 00:00:00 2001 > From: Julien Lepiller > Date: Fri, 25 Oct 2019 21:39:21 +0200 > Subject: [PATCH] guix: package: lock profiles when processing them. > > * guix/scripts/package.scm (process-actions): Get a per-profile lock to > prevent concurrent actions on profiles. [...] > - ;; First, process roll-backs, generation removals, etc. > + ;; First, acquire a lock on the profile, to ensure only one guix proce= ss > + ;; is modifying it at a time. > + (define lock-file (open (string-append profile ".lock") O_CREAT)) > + (catch 'system-error > + (lambda _ > + (flock lock-file (logior LOCK_EX LOCK_NB))) > + (lambda (key . args) > + (leave (G_ "profile ~a is being locked by another guix process.~%") > + profile))) Nitpick: "profile ~a is locked by another process~%". > + ;; Then, process roll-backs, generation removals, etc. > (for-each (match-lambda > ((key . arg) > (and=3D> (assoc-ref %actions key) > @@ -905,7 +915,10 @@ processed, #f otherwise." > #:allow-collisions? allow-collisions? > #:bootstrap? bootstrap? > #:use-substitutes? substitutes? > - #:dry-run? dry-run?)))) > + #:dry-run? dry-run?))) > + > + ;; Finaly, close the lock file > + (close lock-file)) I=E2=80=99d recommend wrapping the body in =E2=80=98with-file-lock=E2=80=99= (from (guix build syscalls)), which handles non-local exits. However you=E2=80=99d first need to add a #:wait? argument to =E2=80=98with= -file-lock=E2=80=99 and perhaps an additional argument to handle the already-locked case. Or maybe call that =E2=80=98with-file-lock/no-wait=E2=80=99. How does that sound? Thanks for working on it! Ludo=E2=80=99.