summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2022-05-22 18:23:27 +0200
committerLudovic Courtès <ludo@gnu.org>2022-05-22 21:56:40 +0200
commit52aceda4fd61970db118f23d316784ea8df244e8 (patch)
treecde97a001cb5d53f832d9e8e367bcbdef93b200c
parentgnu: shepherd: Update to 0.9.1. (diff)
downloadguix-52aceda4fd61970db118f23d316784ea8df244e8.tar.gz
guix-52aceda4fd61970db118f23d316784ea8df244e8.tar.bz2
guix-52aceda4fd61970db118f23d316784ea8df244e8.tar.xz
marionette: Add #:address parameter to 'wait-for-tcp-port'.
* gnu/build/marionette.scm (wait-for-tcp-port): Add #:address parameter. Honor it, and improve error reporting in the 'failure case.
-rw-r--r--gnu/build/marionette.scm45
1 files changed, 26 insertions, 19 deletions
diff --git a/gnu/build/marionette.scm b/gnu/build/marionette.scm
index b336024610..0d2af642c8 100644
--- a/gnu/build/marionette.scm
+++ b/gnu/build/marionette.scm
@@ -1,5 +1,5 @@
1;;; GNU Guix --- Functional package management for GNU 1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org> 2;;; Copyright © 2016-2022 Ludovic Courtès <ludo@gnu.org>
3;;; Copyright © 2018 Chris Marusich <cmmarusich@gmail.com> 3;;; Copyright © 2018 Chris Marusich <cmmarusich@gmail.com>
4;;; 4;;;
5;;; This file is part of GNU Guix. 5;;; This file is part of GNU Guix.
@@ -196,31 +196,38 @@ FILE has not shown up after TIMEOUT seconds, raise an error."
196 (error "file didn't show up" file)))) 196 (error "file didn't show up" file))))
197 197
198(define* (wait-for-tcp-port port marionette 198(define* (wait-for-tcp-port port marionette
199 #:key (timeout 20)) 199 #:key
200 (timeout 20)
201 (address `(make-socket-address AF_INET
202 INADDR_LOOPBACK
203 ,port)))
200 "Wait for up to TIMEOUT seconds for PORT to accept connections in 204 "Wait for up to TIMEOUT seconds for PORT to accept connections in
201MARIONETTE. Raise an error on failure." 205MARIONETTE. ADDRESS must be an expression that returns a socket address,
206typically a call to 'make-socket-address'. Raise an error on failure."
202 ;; Note: The 'connect' loop has to run within the guest because, when we 207 ;; Note: The 'connect' loop has to run within the guest because, when we
203 ;; forward ports to the host, connecting to the host never raises 208 ;; forward ports to the host, connecting to the host never raises
204 ;; ECONNREFUSED. 209 ;; ECONNREFUSED.
205 (match (marionette-eval 210 (match (marionette-eval
206 `(begin 211 `(let* ((address ,address)
207 (let ((sock (socket PF_INET SOCK_STREAM 0))) 212 (sock (socket (sockaddr:fam address) SOCK_STREAM 0)))
208 (let loop ((i 0)) 213 (let loop ((i 0))
209 (catch 'system-error 214 (catch 'system-error
210 (lambda () 215 (lambda ()
211 (connect sock AF_INET INADDR_LOOPBACK ,port) 216 (connect sock address)
212 (close-port sock) 217 (close-port sock)
213 'success) 218 'success)
214 (lambda args 219 (lambda args
215 (if (< i ,timeout) 220 (if (< i ,timeout)
216 (begin 221 (begin
217 (sleep 1) 222 (sleep 1)
218 (loop (+ 1 i))) 223 (loop (+ 1 i)))
219 'failure)))))) 224 (list 'failure address))))))
220 marionette) 225 marionette)
221 ('success #t) 226 ('success #t)
222 ('failure 227 (('failure address)
223 (error "nobody's listening on port" port)))) 228 (error "nobody's listening on port"
229 (list (inet-ntop (sockaddr:fam address) (sockaddr:addr address))
230 (sockaddr:port address))))))
224 231
225(define* (wait-for-unix-socket file-name marionette 232(define* (wait-for-unix-socket file-name marionette
226 #:key (timeout 20)) 233 #:key (timeout 20))