From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Josselin Poiret via "Bug reports for GUILE, GNU's Ubiquitous Extension Language" Newsgroups: gmane.lisp.guile.bugs Subject: bug#52835: [PATCH v4 2/4] Avoid double closes in piped-process. Date: Sat, 28 May 2022 14:46:32 +0200 Message-ID: <20220528124634.17353-3-dev@jpoiret.xyz> References: <20220207165543.12723-1-dev@jpoiret.xyz> <20220528124634.17353-1-dev@jpoiret.xyz> Reply-To: Josselin Poiret Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28841"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 52835@debbugs.gnu.org To: Josselin Poiret , Timothy Sample Original-X-From: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Sat May 28 14:47:45 2022 Return-path: Envelope-to: guile-bugs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nuvr6-0007Hn-Vf for guile-bugs@m.gmane-mx.org; Sat, 28 May 2022 14:47:45 +0200 Original-Received: from localhost ([::1]:47374 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nuvr4-0003rT-Mq for guile-bugs@m.gmane-mx.org; Sat, 28 May 2022 08:47:43 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35448) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nuvqR-0003qK-99 for bug-guile@gnu.org; Sat, 28 May 2022 08:47:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:42718) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nuvqQ-00048t-UA for bug-guile@gnu.org; Sat, 28 May 2022 08:47:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nuvqQ-00010W-Rt for bug-guile@gnu.org; Sat, 28 May 2022 08:47:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Josselin Poiret Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Sat, 28 May 2022 12:47:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 52835 X-GNU-PR-Package: guile X-GNU-PR-Keywords: patch Original-Received: via spool by 52835-submit@debbugs.gnu.org id=B52835.16537420183843 (code B ref 52835); Sat, 28 May 2022 12:47:02 +0000 Original-Received: (at 52835) by debbugs.gnu.org; 28 May 2022 12:46:58 +0000 Original-Received: from localhost ([127.0.0.1]:36610 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nuvqM-0000zp-8X for submit@debbugs.gnu.org; Sat, 28 May 2022 08:46:58 -0400 Original-Received: from jpoiret.xyz ([206.189.101.64]:34508) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nuvqJ-0000zN-57 for 52835@debbugs.gnu.org; Sat, 28 May 2022 08:46:55 -0400 Original-Received: from authenticated-user (jpoiret.xyz [206.189.101.64]) by jpoiret.xyz (Postfix) with ESMTPA id 1857F1851E0; Sat, 28 May 2022 12:46:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpoiret.xyz; s=dkim; t=1653742014; 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=Ixw8yr8Ja0KkKYb69ww3cZkLxihNOJ0RTZ2N/FG2uPc=; b=WBcDmxULcaHC5ujD48R61hyXdAKa4aOx7hkIETb/2zyda/kJLsyKwm/6sqw+naNGimK8B6 ynZaunx7rvDdu7b2J2bhZqbVSlTEnJP6GWxGbMHeqXgQbvp8qgV3fm65Zd2XJW1OqzkmzS 7itClbIulKr51Pfs5MJIvhXyw3dn49hJqJVCmHEl58MymFDtTo8eWj+9ToXaEB8zoRySiQ Byy1bg7MbpXaBV4HOzHKw4OqzVTNGODCUw6falsEkwgEcFrmvgmPBnLLAPdNbxi2/kcmbv f+02W5lThQW5qwQjfL+cTFP6OeKFqhd41TMO5MnJ9XYTq/zdZm0UoaideNZX1g== In-Reply-To: <20220528124634.17353-1-dev@jpoiret.xyz> Authentication-Results: jpoiret.xyz; auth=pass smtp.auth=jpoiret@jpoiret.xyz smtp.mailfrom=dev@jpoiret.xyz X-Spamd-Bar: / X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Original-Sender: "bug-guile" Xref: news.gmane.io gmane.lisp.guile.bugs:10285 Archived-At: * libguile/posix.c (scm_piped_process): Avoid double closes. --- libguile/posix.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/libguile/posix.c b/libguile/posix.c index e9f49fa27..155ad09b7 100644 --- a/libguile/posix.c +++ b/libguile/posix.c @@ -1475,12 +1475,18 @@ scm_piped_process (SCM prog, SCM args, SCM from, SCM to) if (reading) { close (c2p[0]); - close (c2p[1]); + if (c2p[1] != c2p[0]) + close (c2p[1]); } if (writing) { - close (p2c[0]); - close (p2c[1]); + if (!(reading && (c2p[0] == p2c[0] || + c2p[1] == p2c[0]))) + close (p2c[0]); + if (p2c[0] != p2c[1] && + !(reading && (c2p[0] == p2c[1] || + c2p[1] == p2c[1]))) + close (p2c[1]); } errno = errno_save; SCM_SYSERROR; @@ -1488,7 +1494,7 @@ scm_piped_process (SCM prog, SCM args, SCM from, SCM to) if (reading) close (c2p[1]); - if (writing) + if (writing && !(reading && c2p[1] == p2c[0])) close (p2c[0]); return scm_from_int (pid); -- 2.36.0