[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
06/07: secret-service: Abstract 'wait-for-readable-fd'.
From: |
guix-commits |
Subject: |
06/07: secret-service: Abstract 'wait-for-readable-fd'. |
Date: |
Wed, 30 Mar 2022 15:46:17 -0400 (EDT) |
civodul pushed a commit to branch wip-shepherd-upgrade
in repository guix.
commit 247690c61995ecfa7bfe87a3ab8bbc9dd7cf4462
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Mon Mar 28 14:27:34 2022 +0200
secret-service: Abstract 'wait-for-readable-fd'.
* gnu/build/secret-service.scm (wait-for-readable-fd): New procedure.
(secret-service-send-secrets): Use it instead of 'select'.
---
gnu/build/secret-service.scm | 42 ++++++++++++++++++++++++------------------
1 file changed, 24 insertions(+), 18 deletions(-)
diff --git a/gnu/build/secret-service.scm b/gnu/build/secret-service.scm
index 4e183e11e8..621c4447dc 100644
--- a/gnu/build/secret-service.scm
+++ b/gnu/build/secret-service.scm
@@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2020, 2021 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2020-2022 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
;;;
;;; This file is part of GNU Guix.
@@ -47,6 +47,13 @@
;; to syslog.
#'(format (current-output-port) fmt args ...))))))
+(define (wait-for-readable-fd port timeout)
+ "Wait until PORT has data available for reading or TIMEOUT has expired.
+Return #t in the former case and #f in the latter case."
+ (match (select (list port) '() '() timeout)
+ (((_) () ()) #t)
+ ((() () ()) #f)))
+
(define* (secret-service-send-secrets port secret-root
#:key (retry 60)
(handshake-timeout 120))
@@ -93,23 +100,22 @@ wait for at most HANDSHAKE-TIMEOUT seconds for handshake
to complete. Return
;; Wait for "hello" message from the server. This is the only way to know
;; that we're really connected to the server inside the guest.
- (match (select (list sock) '() '() handshake-timeout)
- (((_) () ())
- (match (read sock)
- (('secret-service-server ('version version ...))
- (log "sending files from ~s...~%" secret-root)
- (send-files sock)
- (log "done sending files to port ~a~%" port)
- (close-port sock)
- secret-root)
- (x
- (log "invalid handshake ~s~%" x)
- (close-port sock)
- #f)))
- ((() () ()) ;timeout
- (log "timeout while sending files to ~a~%" port)
- (close-port sock)
- #f))))
+ (if (wait-for-readable-fd sock handshake-timeout)
+ (match (read sock)
+ (('secret-service-server ('version version ...))
+ (log "sending files from ~s...~%" secret-root)
+ (send-files sock)
+ (log "done sending files to port ~a~%" port)
+ (close-port sock)
+ secret-root)
+ (x
+ (log "invalid handshake ~s~%" x)
+ (close-port sock)
+ #f))
+ (begin ;timeout
+ (log "timeout while sending files to ~a~%" port)
+ (close-port sock)
+ #f))))
(define (delete-file* file)
"Ensure FILE does not exist."
- branch wip-shepherd-upgrade created (now b50cd62fe5), guix-commits, 2022/03/30
- 05/07: services: openssh: Start as an inetd service., guix-commits, 2022/03/30
- 02/07: shepherd: Adjust 'fork+exec-command/container' for the Shepherd 0.9., guix-commits, 2022/03/30
- 01/07: gnu: shepherd: Add 0.9.0rc1., guix-commits, 2022/03/30
- 06/07: secret-service: Abstract 'wait-for-readable-fd'.,
guix-commits <=
- 03/07: services: shepherd: Default to version 0.9., guix-commits, 2022/03/30
- 04/07: home: shepherd: Default to version 0.9., guix-commits, 2022/03/30
- 07/07: secret-service: Allow cooperative scheduling when Fibers is used., guix-commits, 2022/03/30