From patchwork Tue Jan 23 16:48:20 2024 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: 59345 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 90C0227BBE2; Tue, 23 Jan 2024 16:49:16 +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=-3.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, 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 CDD9F27BBE9 for ; Tue, 23 Jan 2024 16:49:15 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rSJxN-0003wC-TN; Tue, 23 Jan 2024 11:49:01 -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 1rSJxL-0003ur-E9 for guix-patches@gnu.org; Tue, 23 Jan 2024 11:48:59 -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 1rSJxL-0004OO-5H for guix-patches@gnu.org; Tue, 23 Jan 2024 11:48:59 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rSJxP-00049E-Ra for guix-patches@gnu.org; Tue, 23 Jan 2024 11:49:03 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#68677] [PATCH 5/6] marionette: Add #:peek? to =?utf-8?b?4oCY?= =?utf-8?b?d2FpdC1mb3ItdGNwLXBvcnQ/4oCZLg==?= Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 23 Jan 2024 16:49:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 68677 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 68677@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= Received: via spool by 68677-submit@debbugs.gnu.org id=B68677.170602853715888 (code B ref 68677); Tue, 23 Jan 2024 16:49:03 +0000 Received: (at 68677) by debbugs.gnu.org; 23 Jan 2024 16:48:57 +0000 Received: from localhost ([127.0.0.1]:43888 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rSJxJ-000486-11 for submit@debbugs.gnu.org; Tue, 23 Jan 2024 11:48:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39910) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rSJxD-00046c-Hy for 68677@debbugs.gnu.org; Tue, 23 Jan 2024 11:48:52 -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 1rSJx3-0004Ll-H6; Tue, 23 Jan 2024 11:48:41 -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=cGLxYu+dVr5jOkZbNRHT6+oiFJRAtqVY5y0OdXmWqBw=; b=i/TzJXbCsMWl2zNBAI9m XeesP6cOOUDBpr7mTmoPTONk1fAD9qQRtCLB2Ly/ZHQ24HpaWJUgkAnwGMrhStnO1b+32xYGP9+hi /snztD4NiN2iDilyTWMuf1duGx90JlIuxJegNAgmkotthyiTlUEj/XQD6JmaStGxyfhzGt5UdNCA6 Z8BxcqDr5q8ESrGWRp5lPIza86k3eH8YPJeBZ6rOx8VorBY+a7bRl9+214jri+iCM5zyZff54hpJH XgO4bd6b7TRXFsnGfQjxXuBejwPNd5zaQ+kfQzujCg7/5ObSzz2GJXCM/Px/frjupzrupZ7IR9Buh AWgxhigzDqzNXg==; From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Tue, 23 Jan 2024 17:48:20 +0100 Message-ID: <85175dd568a9283816652a6124f14cd65505bb22.1706027375.git.ludo@gnu.org> X-Mailer: git-send-email 2.41.0 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 * gnu/build/marionette.scm (wait-for-tcp-port): Add #:peek? parameter and honor it. Change-Id: Ie7515a5223299390ab8af6fe5aa3cf63ba5c8078 --- gnu/build/marionette.scm | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/gnu/build/marionette.scm b/gnu/build/marionette.scm index 27c10e3dfe..0b0a8a70d8 100644 --- a/gnu/build/marionette.scm +++ b/gnu/build/marionette.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2016-2022 Ludovic Courtès +;;; Copyright © 2016-2022, 2024 Ludovic Courtès ;;; Copyright © 2018 Chris Marusich ;;; Copyright © 2022, 2023 Maxim Cournoyer ;;; Copyright © 2023 Bruno Victal @@ -223,29 +223,49 @@ (define* (wait-for-file file marionette (define* (wait-for-tcp-port port marionette #:key (timeout 20) + (peek? #f) (address `(make-socket-address AF_INET INADDR_LOOPBACK ,port))) "Wait for up to TIMEOUT seconds for PORT to accept connections in MARIONETTE. ADDRESS must be an expression that returns a socket address, -typically a call to 'make-socket-address'. Raise an error on failure." +typically a call to 'make-socket-address'. When PEEK? is true, attempt to +read a byte from the socket upon connection; retry if that gives the +end-of-file object. + +Raise an error on failure." ;; Note: The 'connect' loop has to run within the guest because, when we ;; forward ports to the host, connecting to the host never raises ;; ECONNREFUSED. (match (marionette-eval - `(let* ((address ,address) - (sock (socket (sockaddr:fam address) SOCK_STREAM 0))) - (let loop ((i 0)) + `(let* ((address ,address)) + (define (open-socket) + (socket (sockaddr:fam address) SOCK_STREAM 0)) + + (let loop ((sock (open-socket)) + (i 0)) (catch 'system-error (lambda () (connect sock address) + (when ,peek? + (let ((byte ((@ (ice-9 binary-ports) lookahead-u8) + sock))) + (when (eof-object? byte) + (close-port sock) + (throw 'system-error + "wait-for-tcp-port" "~A" + (list (strerror ECONNRESET)) + (list ECONNRESET))))) (close-port sock) 'success) (lambda args (if (< i ,timeout) (begin (sleep 1) - (loop (+ 1 i))) + (loop (if (port-closed? sock) + (open-socket) + sock) + (+ 1 i))) (list 'failure address)))))) marionette) ('success #t)