From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id 2JoxOAvur2VlugAAqHPOHw:P1 (envelope-from ) for ; Tue, 23 Jan 2024 17:49:16 +0100 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id 2JoxOAvur2VlugAAqHPOHw (envelope-from ) for ; Tue, 23 Jan 2024 17:49:16 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b="i/TzJXbC"; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1706028555; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=cGLxYu+dVr5jOkZbNRHT6+oiFJRAtqVY5y0OdXmWqBw=; b=FXOly2s6Io3k6DnzeAivoDeN3FWYD3zdZ9bGoToLmQHWZHSIN1yGS8K+lQAQRP/Pfg7rMI 8zTIv1n5yPbtJ2TfeTVwg/TxnlA5x+x/4rUu3aSm4sccCrvDaZkKNEMQkDHojFZ6kK4Ncs WK21Ju0X7iQnWWAKdSNXfkum/yKT2/1LhdurQR06WUKqTWa3Mn4qJOH2NA93BLD932Xc4/ yVmd6g/JbULWzL+2jotPw1Zll05N9oMhGQqDj0xvYM8lY0aR0RzB/YlJNyM1MB1D4RBCXE xeVOfC+MjgdrlrbBh1O8XkB99ES/ZXmd9KKTJ7U7HnPP73XA1usqQmTOh3fxNQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b="i/TzJXbC"; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org ARC-Seal: i=1; s=key1; d=yhetil.org; t=1706028555; a=rsa-sha256; cv=none; b=azyzWx+svP3oYjWHoh0KBBIfOePUDUx7jlOtQ8vELDo7P/yFduNmtGQnQcn3tLF5KLFruZ ooVkhaKdbAwczFDS5dA6uMLmB8kAysbeTsrEVKafhnpj00igmz/sdxJoC4Q1UWOfL7r0qB Bph5I7kVor/61uQWwosKKqg8pBtEOlLn7SqnmJ7tnqg3fplcJFkbwDBMR1F/QhV+LvyN/J 0LPPpRDtCif4d/MkIuOayqvMJgVZNHhgsMX3hOtofdjsVrchG3+wZ82dCXaL1JNKmvw1Up B8YEAITab8gJR6U1yjY4N/XSbmMQXQY/YUmdoFD9cR3eI0daGGBGA4y/uhmcJg== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id B8DB13FD0E for ; Tue, 23 Jan 2024 17:49:15 +0100 (CET) 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?Q?=E2=80=98wait-for-tcp-port=3F=E2=80=99.?= 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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -6.36 X-Migadu-Queue-Id: B8DB13FD0E X-Spam-Score: -6.36 X-Migadu-Scanner: mx11.migadu.com X-TUID: +O4zjC/NTx3e * 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) -- 2.41.0