From patchwork Wed Jan 15 22:14:49 2025 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: 37081 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 01AFB27BBE9; Wed, 15 Jan 2025 22:16:24 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE, 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 953FD27BBE2 for ; Wed, 15 Jan 2025 22:16:24 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tYBgF-0003g4-KJ; Wed, 15 Jan 2025 17:16:07 -0500 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 1tYBgC-0003dV-Fq for guix-patches@gnu.org; Wed, 15 Jan 2025 17:16:04 -0500 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 1tYBgC-0004Ic-5n; Wed, 15 Jan 2025 17:16:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=EEmkrxEMwEH54raUCy3OqS3sH9z13xWJZZYF6ieEMmU=; b=o8QpU5R9JvuGWZeuoIJqsIdb1P2K5JxzJGv7zz43wUxz0ZrUSywGuL+aqbLOI+Kx8oIn4/dBu3OVZ6buBUECWPzPXQfDO6/wZu6n0N65xicuDEdo1sZEdnVPq4S9qr1uACOO3Fh2LzNt7SjjdaHYJG8MKBLcocsCLdL2rYjSaTPJv8S57ZdtqwLAQgOoaDB+QqZlJkTSg9ogdG52z4NAZsvEhW307rA54KwuUwujX2l4FbI0M7GGdEHQ/kHNNvLk/gh+c4t/Vkg3BoQw/g4I54r1XoA4GJ74QiKWIjvwhQPkgOpHCe9IN2kuvQm08Lkcwq2hWYYlM9Yga9+d2x0BxQ==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tYBgB-0002tt-5j; Wed, 15 Jan 2025 17:16:03 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#75595] [PATCH 3/4] inferior: Store the bridge directory name in . Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Wed, 15 Jan 2025 22:16:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 75595 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 75595@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= , Christopher Baines , Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by 75595-submit@debbugs.gnu.org id=B75595.173697931611067 (code B ref 75595); Wed, 15 Jan 2025 22:16:03 +0000 Received: (at 75595) by debbugs.gnu.org; 15 Jan 2025 22:15:16 +0000 Received: from localhost ([127.0.0.1]:59080 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tYBfQ-0002sP-27 for submit@debbugs.gnu.org; Wed, 15 Jan 2025 17:15:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36434) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1tYBfF-0002lH-ST for 75595@debbugs.gnu.org; Wed, 15 Jan 2025 17:15:06 -0500 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 1tYBfA-00042T-Jl; Wed, 15 Jan 2025 17:15:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=EEmkrxEMwEH54raUCy3OqS3sH9z13xWJZZYF6ieEMmU=; b=Kg50xm9u2KiF5Sh3Sb7N KM8LIgaz74pqQ0Mw6dWn4hooFObcQrQNul3M9zqFKoiYflXQb6pOfRIU43x8Ka9y0PuwbyIzDrGLj mm6emc87CCqrd1N2YiQZe0Z+lZHbQP4i4hv6aPe7q98Big4EKd2slPaNbepofQnHJWVbDSkhbgm9C e7FhGpY4Uq9py0Tfswccto05HxTT88/5IkPkIdsPOe4F2UeIVGiPUhGtGsyr2daP1QzZ7PD7Ykjr7 DZ4wzecC7p+rOdxzhUoWInsq0TdRNZWQAl6Ea8iaJIijCcq0zm9oZNvZtQHxRBBMinn57LrV1C1Wy DtT8Mvo9CwsrWQ==; From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Wed, 15 Jan 2025 23:14:49 +0100 Message-ID: <5175258f93e27140a2fcc0d1f23e396c682091da.1736977759.git.ludo@gnu.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: 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 * guix/inferior.scm ()[bridge-directory]: New field. (port->inferior): Add #:bridge-directory and honor it. (close-inferior): Delete the bridge directory. (allocate-temporary-directory, inferior-bridge-directory): New procedures. (open-store-bridge!): Use it instead of ‘call-with-temporary-directory’. Co-authored-by: Christopher Baines Change-Id: Ie469e3f272f29054cc50b1e1afb2784521c2e2e2 --- guix/inferior.scm | 68 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 22 deletions(-) diff --git a/guix/inferior.scm b/guix/inferior.scm index 8066cce2fc..ead6148667 100644 --- a/guix/inferior.scm +++ b/guix/inferior.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2018-2024 Ludovic Courtès +;;; Copyright © 2018-2025 Ludovic Courtès ;;; ;;; This file is part of GNU Guix. ;;; @@ -36,6 +36,7 @@ (define-module (guix inferior) &store-protocol-error)) #:use-module ((guix derivations) #:select (read-derivation-from-file)) + #:autoload (guix build syscalls) (mkdtemp!) #:use-module (guix gexp) #:use-module (guix search-paths) #:use-module (guix profiles) @@ -113,13 +114,15 @@ (define-module (guix inferior) ;; Inferior Guix process. (define-record-type - (inferior pid socket close version packages table - bridge-socket) + (inferior pid socket close version bridge-directory + packages table bridge-socket) inferior? (pid inferior-pid) (socket inferior-socket) (close inferior-close-socket) ;procedure (version inferior-version) ;REPL protocol version + (bridge-directory %inferior-bridge-directory ;#f | file name + set-inferior-bridge-directory!) (packages inferior-package-promise) ;promise of inferior packages (table inferior-package-table) ;promise of vhash @@ -233,6 +236,7 @@ (define* (port->inferior pipe #:optional (close close-port)) (match (read pipe) (('repl-version 0 rest ...) (letrec ((result (inferior 'pipe pipe close (cons 0 rest) + #f ;bridge directory (delay (%inferior-packages result)) (delay (%inferior-package-table result)) #f))) @@ -318,7 +322,14 @@ (define (close-inferior inferior) ;; Close and delete the store bridge, if any. (when (inferior-bridge-socket inferior) - (close-port (inferior-bridge-socket inferior))))) + (close-port (inferior-bridge-socket inferior))) + + ;; Delete the store bridge socket directory. + (when (%inferior-bridge-directory inferior) + (false-if-exception + (delete-file (in-vicinity (%inferior-bridge-directory inferior) + "inferior"))) + (rmdir (%inferior-bridge-directory inferior))))) ;; Non-self-quoting object of the inferior. (define-record-type @@ -656,6 +667,20 @@ (define (proxy inferior store) ;adapted from (guix ssh) (memq response-port reads)) (loop)))))) +(define (allocate-temporary-directory) + "Return the name of a fresh temporary directory." + (let* ((directory (or (getenv "TMPDIR") "/tmp")) + (template (string-append directory "/guix-inferior.XXXXXX"))) + (mkdtemp! template))) + +(define (inferior-bridge-directory inferior) + "Return the name of the directory shared between INFERIOR and its host to +contain the \"store bridge\"." + (or (%inferior-bridge-directory inferior) + (let ((directory (allocate-temporary-directory))) + (set-inferior-bridge-directory! inferior directory) + directory))) + (define (open-store-bridge! inferior) "Open a \"store bridge\" for INFERIOR--a named socket in /tmp that will be used to proxy store RPCs from the inferior to the store of the calling @@ -664,25 +689,24 @@ (define (open-store-bridge! inferior) ;; its store. This ensures the inferior uses the same store, with the same ;; options, the same per-session GC roots, etc. ;; FIXME: This strategy doesn't work for remote inferiors (SSH). - (call-with-temporary-directory - (lambda (directory) - (chmod directory #o700) - (let ((name (string-append directory "/inferior")) - (socket (socket AF_UNIX SOCK_STREAM 0))) - (bind socket AF_UNIX name) - (listen socket 2) + (let ((directory (inferior-bridge-directory inferior))) + (chmod directory #o700) + (let ((name (string-append directory "/inferior")) + (socket (socket AF_UNIX SOCK_STREAM 0))) + (bind socket AF_UNIX name) + (listen socket 2) - (send-inferior-request - `(define %bridge-socket - (let ((socket (socket AF_UNIX SOCK_STREAM 0))) - (connect socket AF_UNIX ,name) - socket)) - inferior) - (match (accept socket) - ((client . address) - (close-port socket) - (set-inferior-bridge-socket! inferior client))) - (read-inferior-response inferior))))) + (send-inferior-request + `(define %bridge-socket + (let ((socket (socket AF_UNIX SOCK_STREAM 0))) + (connect socket AF_UNIX ,name) + socket)) + inferior) + (match (accept socket) + ((client . address) + (close-port socket) + (set-inferior-bridge-socket! inferior client))) + (read-inferior-response inferior)))) (define (ensure-store-bridge! inferior) "Ensure INFERIOR has a connected bridge."