From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id 4P4pJJnoj2JqhAEAbAwnHQ (envelope-from ) for ; Thu, 26 May 2022 22:52:41 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id 0P9SI5noj2Jf5AAAG6o9tA (envelope-from ) for ; Thu, 26 May 2022 22:52:41 +0200 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 2E2582D668 for ; Thu, 26 May 2022 22:52:41 +0200 (CEST) Received: from localhost ([::1]:41406 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nuKTI-0005jy-Ck for larch@yhetil.org; Thu, 26 May 2022 16:52:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45588) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nuKRl-0004Yv-Do for bug-guix@gnu.org; Thu, 26 May 2022 16:51:05 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:38018) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nuKRh-0001Kv-Sx for bug-guix@gnu.org; Thu, 26 May 2022 16:51:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nuKRh-0005lg-Qz for bug-guix@gnu.org; Thu, 26 May 2022 16:51:01 -0400 X-Loop: help-debbugs@gnu.org Subject: bug#55441: [PATCH] guix: inferior: Make open-bidirectional-pipe use piped-process. Resent-From: Josselin Poiret Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Thu, 26 May 2022 20:51:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 55441 X-GNU-PR-Package: guix X-GNU-PR-Keywords: To: Ludovic =?UTF-8?Q?Court=C3=A8s?= , Christopher Baines Cc: 55441@debbugs.gnu.org, Josselin Poiret Received: via spool by 55441-submit@debbugs.gnu.org id=B55441.165359822622102 (code B ref 55441); Thu, 26 May 2022 20:51:01 +0000 Received: (at 55441) by debbugs.gnu.org; 26 May 2022 20:50:26 +0000 Received: from localhost ([127.0.0.1]:60140 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nuKR8-0005kQ-Fd for submit@debbugs.gnu.org; Thu, 26 May 2022 16:50:26 -0400 Received: from jpoiret.xyz ([206.189.101.64]:48866) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nuKR6-0005kI-MT for 55441@debbugs.gnu.org; Thu, 26 May 2022 16:50:25 -0400 Received: from authenticated-user (jpoiret.xyz [206.189.101.64]) by jpoiret.xyz (Postfix) with ESMTPA id 9F3BD184F6C; Thu, 26 May 2022 20:50:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpoiret.xyz; s=dkim; t=1653598224; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZNNvuGSlLHpGEsUl5ZBc26eelUowqCS/1hVsxj6DLfc=; b=rNyBzEVJXg0l4DIzgSijgG8MkV8k4Me/V++REj9EKG6mR+uejy8JAS8EI3683WyCDQEmgl 9rMXYGSJJ+C+5xKg4p69rSeJQn2SvuTDGv1m1pAqHtXWccWkXV14QLF37p67oVHG1+qsyp WNU30YAs9h+eNP3OWufWMI+sUjDC/ekwJJp79KzIdzc2dO+btIbfpKmlIWLRnOJRgWxuLv SySlIG4lfYEW3+D+k+cEYLGeIcg8gpDjUuxHQdvk7h0VHTAby09RYYbk+2lP9lLASNkjP9 TYvnwvKIHoahU2ZUTNb6BGOJEaqaPJDAjzmAlmimPYbY09r2HaFZSmrYsTJqFA== Date: Thu, 26 May 2022 22:50:16 +0200 Message-Id: <20220526205016.23899-1-dev@jpoiret.xyz> In-Reply-To: <87sfow10lc.fsf@jpoiret.xyz> References: <87sfow10lc.fsf@jpoiret.xyz> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spamd-Bar: / X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guix@gnu.org List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+larch=yhetil.org@gnu.org Sender: "bug-Guix" Reply-to: Josselin Poiret From: Josselin Poiret via Bug reports for GNU Guix X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1653598361; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: 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=ZNNvuGSlLHpGEsUl5ZBc26eelUowqCS/1hVsxj6DLfc=; b=Sfd705gyTkv3pxG9JC3LCTRkTCwsFxew1GH3sngVxGoP52tdrwqrpe4hKT7KOtIrFcPu3c CP5G79T+bx8WWKO1Mbz3nJhc57Hm0jK6hTdjuUWuIYbAeieq/0PAk6XznvOtN0RsMPfh7r L0BNjmB2Pp4wJxgZkyJZvVlOxKqhBuyw0s8zvNygIO5w3sNBZI7HPdYPy0TAxx5cqqsQ9k 8JbEJup1/gH5H0Ck56LUksyt9oscv9rQ9bZf+OLm5WfCF7dRZZD7h66XHbXSwPpbA5blLu ORaUskSTQbTVIqi2lFXG5KU8/xQYgU2FJ/1f5xr0MkKzlNfsDpTADrsFccmaIw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1653598361; a=rsa-sha256; cv=none; b=QtI7kt7coTO20MPLUJb9aYx3WbIoLwM1m8OQxGECN+7+0/1gOQzymrO4n2mJfrKV0ChXkz VMLFRaIXPwpMq5LKUPGShbY/meFxfJenab7EEEGAZfjR+2byRlT8iWiOy/iDi+UgS9ErN4 eMtnooaB6VPfk5DQ6Cmn/aeh6UlVjfPc/5jd6p58NzGWpJ+B6XOZbnYhrixIUmprWE55Bs d1qu8273AcCuDeX+sGWb2cOL6tRvuZ92SbmnpuEJcCPvd21s4Bbbpeao2EYACKL3W/Doo3 V9KIOD4OAC4KYI9P1r5CPi/B2ZmA+cjTZuatBpROeUS0I+rKYrC6qrQGQmAyUg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=jpoiret.xyz header.s=dkim header.b=rNyBzEVJ; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "bug-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="bug-guix-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -1.54 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=jpoiret.xyz header.s=dkim header.b=rNyBzEVJ; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "bug-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="bug-guix-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 2E2582D668 X-Spam-Score: -1.54 X-Migadu-Scanner: scn1.migadu.com X-TUID: 9Cx/+rGPQaaO * 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! 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