From: Josselin Poiret via Bug reports for GNU Guix <bug-guix@gnu.org>
To: "Ludovic Courtès" <ludo@gnu.org>,
"Christopher Baines" <mail@cbaines.net>
Cc: 55441@debbugs.gnu.org, Josselin Poiret <dev@jpoiret.xyz>
Subject: bug#55441: [PATCH] guix: inferior: Make open-bidirectional-pipe use piped-process.
Date: Thu, 26 May 2022 22:50:16 +0200 [thread overview]
Message-ID: <20220526205016.23899-1-dev@jpoiret.xyz> (raw)
In-Reply-To: <87sfow10lc.fsf@jpoiret.xyz>
* guix/inferior.scm: Load up scm_init_popen extension to be able to
use piped-process.
(open-bidirectional-pipe): Remove custom fork+exec code and use
piped-process instead.
---
guix/inferior.scm | 39 ++++++++++++++++++---------------------
1 file changed, 18 insertions(+), 21 deletions(-)
diff --git a/guix/inferior.scm b/guix/inferior.scm
index 54200b75e4..a4a4c1d40e 100644
--- a/guix/inferior.scm
+++ b/guix/inferior.scm
@@ -134,6 +134,10 @@ (define (write-inferior inferior port)
(set-record-type-printer! <inferior> write-inferior)
+(eval-when (expand load eval)
+ (load-extension (string-append "libguile-" (effective-version))
+ "scm_init_popen"))
+
(define (open-bidirectional-pipe command . args)
"Open a bidirectional pipe to COMMAND invoked with ARGS and return it, as a
regular file port (socket).
@@ -147,27 +151,20 @@ (define (open-bidirectional-pipe command . args)
;; the REPL process wouldn't get EOF on standard input.
(match (socketpair AF_UNIX (logior SOCK_STREAM SOCK_CLOEXEC) 0)
((parent . child)
- (match (primitive-fork)
- (0
- (dynamic-wind
- (lambda ()
- #t)
- (lambda ()
- (close-port parent)
- (close-fdes 0)
- (close-fdes 1)
- (dup2 (fileno child) 0)
- (dup2 (fileno child) 1)
- ;; Mimic 'open-pipe*'.
- (unless (file-port? (current-error-port))
- (close-fdes 2)
- (dup2 (open-fdes "/dev/null" O_WRONLY) 2))
- (apply execlp command command args))
- (lambda ()
- (primitive-_exit 127))))
- (pid
- (close-port child)
- (values parent pid))))))
+ (let* ((proc
+ (lambda ()
+ (piped-process command args
+ ;; Use port->fdes on child to increase the
+ ;; revealed count, so that the fd does not get
+ ;; closed again when child gets gc'd, as
+ ;; piped-process already closes it.
+ (cons (fileno parent) (port->fdes child))
+ (cons (fileno child) (fileno parent)))))
+ (pid
+ (if (file-port? (current-error-port))
+ (proc)
+ (with-error-to-file "/dev/null" proc))))
+ (values parent pid)))))
(define* (inferior-pipe directory command error-port)
"Return two values: an input/output pipe on the Guix instance in DIRECTORY
--
2.36.0
next prev parent reply other threads:[~2022-05-26 20:52 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <87fslcaznn.fsf@gmail.com>
[not found] ` <87mtfj174l.fsf@gnu.org>
2022-05-16 3:49 ` bug#55441: [cuirass] hang in "In progress..."; runs out of pgsql connections Maxim Cournoyer
2022-05-16 7:32 ` Mathieu Othacehe
2022-05-16 9:13 ` Ludovic Courtès
2022-05-16 10:32 ` Ludovic Courtès
2022-05-16 12:19 ` Ludovic Courtès
2022-05-16 17:32 ` Maxim Cournoyer
2022-05-17 7:45 ` Ludovic Courtès
2022-05-18 7:44 ` Ludovic Courtès
2022-05-20 18:32 ` Ludovic Courtès
2022-05-24 21:02 ` Ludovic Courtès
2022-05-25 16:32 ` Ludovic Courtès
2022-05-25 18:21 ` Ludovic Courtès
2022-05-25 23:13 ` Christopher Baines
2022-05-26 9:44 ` Ludovic Courtès
2022-05-26 20:49 ` Josselin Poiret via Bug reports for GNU Guix
2022-05-26 20:50 ` Josselin Poiret via Bug reports for GNU Guix [this message]
2022-05-26 21:02 ` bug#55441: [PATCH] guix: inferior: Make open-bidirectional-pipe use piped-process Maxime Devos
2022-05-28 17:15 ` Ludovic Courtès
2022-05-26 20:50 ` bug#55441: [PATCH 1/2] Fix child spawning closing standard fds prematurely Josselin Poiret via Bug reports for GNU Guix
2022-05-26 20:55 ` Maxime Devos
2022-05-26 20:50 ` bug#55441: [PATCH 2/2] Improve thread safety of piped-process Josselin Poiret via Bug reports for GNU Guix
2022-05-26 20:58 ` bug#55441: [cuirass] hang in "In progress..."; runs out of pgsql connections Maxime Devos
2022-05-28 14:02 ` Josselin Poiret via Bug reports for GNU Guix
2023-01-26 14:39 ` Ludovic Courtès
2022-05-26 12:29 ` Ludovic Courtès
2022-05-16 12:49 ` Maxim Cournoyer
2022-05-17 12:52 ` Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220526205016.23899-1-dev@jpoiret.xyz \
--to=bug-guix@gnu.org \
--cc=55441@debbugs.gnu.org \
--cc=dev@jpoiret.xyz \
--cc=ludo@gnu.org \
--cc=mail@cbaines.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).