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: Wed, 06 Nov 2019 14:24:54 +0100 Message-ID: <87mud95e8p.fsf@gnu.org> References: <875zotn4c1.fsf@gnu.org> <20191025214451.284c3530@sybil.lepiller.eu> <87tv7wldwh.fsf@gnu.org> <20191026000806.7eb6342b@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]:44211) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iSLK3-00067X-2A for bug-guix@gnu.org; Wed, 06 Nov 2019 08:26:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iSLK1-0005RJ-AY for bug-guix@gnu.org; Wed, 06 Nov 2019 08:26:06 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:58999) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iSLK0-0005Qf-Go for bug-guix@gnu.org; Wed, 06 Nov 2019 08:26:05 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iSLJx-0003qf-Sp for bug-guix@gnu.org; Wed, 06 Nov 2019 08:26:03 -0500 Sender: "Debbugs-submit" Resent-Message-ID: In-Reply-To: <20191026000806.7eb6342b@sybil.lepiller.eu> (Julien Lepiller's message of "Sat, 26 Oct 2019 00:08:06 +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: >>From 5d86226f318a111cc1bdf5a6f044c6f540f51b45 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. > * guix/build/syscalls.scm (with-file-lock/no-wait): New procedure. > (lock-file): Take a #:wait? key. Nice! Could you make the syscalls.scm changes a separate patch? > +(define (call-with-file-lock/no-wait file thunk handler) > + (let ((port (catch 'system-error > + (lambda () > + (catch 'flock-error > + (lambda () > + (lock-file file #:wait? #f)) > + handler)) > + (lambda args > + ;; When using the statically-linked Guile in the initr= d, > + ;; 'fcntl-flock' returns ENOSYS unconditionally. Igno= re > + ;; that error since we're typically the only process r= unning > + ;; at this point. > + (if (or (=3D ENOSYS (system-error-errno args)) (=3D 'f= lock-error args)) Please remove tabs. :-) This is wrong because (1) =E2=80=98args=E2=80=99 is always a list, and (2) = =E2=80=98=3D=E2=80=99 is defined for numbers, not for symbols and lists. I think you actually want to catch two exceptions here: =E2=80=98system-err= or=E2=80=99 and =E2=80=98flock-error=E2=80=99. For that, you have to do: (catch #t (lambda () (lock-file =E2=80=A6)) (lambda (key . args) (match key ('flock-error =E2=80=A6) ('system-error (if (=3D ENOSYS (system-error-errno (cons key args))) =E2=80=A6)) (_ (apply throw key args))))) =20=20=20=20=20=20=20=20 Does that make sense? > + ;; First, acquire a lock on the profile, to ensure only one guix proce= ss > + ;; is modifying it at a time. > + (with-file-lock/no-wait > + (string-append profile ".lock") Nitpick: I=E2=80=99d move the lock file name on the same line as =E2=80=98with-file-lock/no-wait=E2=80=99. > + (lambda (key . args) > + (leave (G_ "profile ~a is locked by another guix process.~%") > + profile)) s/guix// and remove the trailing period. Could you add a test for that in tests/guix-package.sh? One way to do it may be to do something like: echo '(sleep 60) > /=E2=80=A6/manifest.scm guix package -m /=E2=80=A6/manifest.scm -p whatever & pid=3D$! if guix install emacs -p whatever; then false; else true; fi kill $pid Could you send updated patches? Thanks! Ludo=E2=80=99.