Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #16604

Re: Procsub.tests on OSes using named pipes

Path csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail
From "CHIGOT, CLEMENT" <clement.chigot@atos.net>
Newsgroups gnu.bash.bug
Subject Re: Procsub.tests on OSes using named pipes
Date Wed, 22 Jul 2020 13:23:01 +0000
Lines 275
Approved bug-bash@gnu.org
Message-ID <mailman.321.1595424276.24492.bug-bash@gnu.org> (permalink)
References <DB7PR02MB4075AEFED9BEDC6FDC0C2D2EEA1A0@DB7PR02MB4075.eurprd02.prod.outlook.com> <DB7PR02MB4075BA041EDA6A45E9D85386EA130@DB7PR02MB4075.eurprd02.prod.outlook.com> <AM0PR0202MB3442B671678DE7902279038BEA790@AM0PR0202MB3442.eurprd02.prod.outlook.com>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset="iso-8859-1"
Content-Transfer-Encoding quoted-printable
X-Trace usenet.stanford.edu 1595424277 30996 209.51.188.17 (22 Jul 2020 13:24:37 GMT)
X-Complaints-To action@cs.stanford.edu
Cc Chet Ramey <chet.ramey@case.edu>, "REIX, Tony" <tony.reix@atos.net>, Sanket Rathi <sanrathi@in.ibm.com>
To "bug-bash@gnu.org" <bug-bash@gnu.org>
Envelope-to bug-bash@gnu.org
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=atos.net; i=@atos.net; q=dns/txt; s=mail; t=1595424271; x=1626960271; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=7PeGosrUJ7fhamtUofGy5QTpjoegoQ1ivef2Ev2yfgI=; b=2s2/tMkCp0sWCRF4MIR98mRfOxgJJRagegPSxIE+gLJrcIwH4tjuXnoV yuVIVjSUt62NTsd5+XO1uMUG2yPNYP1Z3iL1GC1U9JxHe9ljyrzxgaeQn DKoyHF9KLABlraxh5Sb7ROQ4fU1RWlfdxKAtnS54IqIgJo6GSg1j8b4Y+ k=;
IronPort-SDR 3OOxJjUSL+aHRee1/lHU0GxfpSTzy58vV2vj/5OKQuUrx7QdEE6lvSn9Mn+G9DvHYIqiXVSR82 x7MSM5aUQeBXyXV5fiptPFi+6UcJzmz52QJhuQPOYe3hmfENKPLy+QKLhY0jmaq+iTNrdBt0oc 0/fsLL3DvHssm5j3zz3BUIX3f/9yyzfBySJktoGhnijnBKMHn9VBuLexBt/UPuLXiL/foDCfW5 iWz0vqTymjq0me13+c21Lk1NiFd/K6OXZTNVp61fkbLJU/MhoEDnROaaMENHFgRt34mVmcfR0k FBX4bR1yNHEIn78WhvbOeyAN
X-IronPort-AV E=Sophos;i="5.75,383,1589234400"; d="scan'208";a="82965564"
X-MGA-submission MDFdK08YvJ7lL79RLPxXFTzc+TWeNDYqM9QM+WZk00FqXsrvyHWc6VY63lo24LkkT1YSWtjLnPFTaqDBMM5XxT3SJtvR0Yks+KXip6lxwA6AIZHmopj3ArK6bPhCcNPyMBrIzqFm0UAjEIP89ZXaIbTs
ARC-Seal i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d6qSIeRC1DX06uWDIcqmIi6qS+p7iqUulIQ1R4CXj4NQAzNbu8exPgGJPD5HEAURuGb/cBzJGeN6/5NPwSNoKXwkIRE/5fCis8z7s5LJ1ublYKHeXx1EjxIOA3Puu/Qzy67eyeZe/Sc+dc8oV4/HO3p3TengHZYThm1qi98PW1gLlO0M0ksAQNVwcbbAsRtsjO67DavKssERevw/r4JB1AVI7yxAFa5nc6OX4gJLdDU8g0x8hqA9krLGC6H+qBw2YA3zHqi8Q/9fxDKcpq+A0qzSkj0/WwUH/3Ern1JWyDHbsFphBbIq1bt5TunpX9mtGyo2tduEqBC42YItpLyjmQ==
ARC-Message-Signature i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7PeGosrUJ7fhamtUofGy5QTpjoegoQ1ivef2Ev2yfgI=; b=QaCXped0dLeXvC8UawRceBNoOmcwuI4lCzrokaad0seqAA2Rw6JvIeBt0yMIxDGqQjvREL5sXBW+sRLzQtU98vgLRDXPVV2khLUgfbhjp6Dgi9M4SHO93J7RhctYswOze8OTWhnW22tYhc6FQbW7ye4+Fs/ERJr7P8MLE0qxKjplgPYkuKsotvumUiHDiH5hROzmM9I2iTrlVjnjBvTMPInJUo7Yuz1qXap7q8ODcubxSDT4raHqHr6JElSgxFarKNcCjlbQ+LHRj+EO8R61T2MqI665FvcLca7eFb2+HscjYRf5SxUNmMWl5chfDtleb2qAZOCYGdt1YmZmzXijtQ==
ARC-Authentication-Results i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=atos.net; dmarc=pass action=none header.from=atos.net; dkim=pass header.d=atos.net; arc=none
Thread-Topic Procsub.tests on OSes using named pipes
Thread-Index AQHV4lMjRZ+lXL7UvEW8UUbE72cdUKgaugJugAH3RoCAB28UwIDwb8H/
In-Reply-To <DB7PR02MB4075BA041EDA6A45E9D85386EA130@DB7PR02MB4075.eurprd02.prod.outlook.com>
Accept-Language en-US
Content-Language en-US
X-MS-Has-Attach
X-MS-TNEF-Correlator
msip_labels MSIP_Label_e463cba9-5f6c-478d-9329-7b2295e4e8ed_Enabled=True; MSIP_Label_e463cba9-5f6c-478d-9329-7b2295e4e8ed_SiteId=33440fc6-b7c7-412c-bb73-0e70b0198d5a; MSIP_Label_e463cba9-5f6c-478d-9329-7b2295e4e8ed_SetDate=2020-07-22T13:23:01.270Z; MSIP_Label_e463cba9-5f6c-478d-9329-7b2295e4e8ed_Name=Atos For Internal Use - All Employees; MSIP_Label_e463cba9-5f6c-478d-9329-7b2295e4e8ed_ContentBits=0; MSIP_Label_e463cba9-5f6c-478d-9329-7b2295e4e8ed_Method=Standard;
authentication-results gnu.org; dkim=none (message not signed) header.d=none;gnu.org; dmarc=none action=none header.from=atos.net;
x-originating-ip [80.78.5.107]
x-ms-publictraffictype Email
x-ms-office365-filtering-correlation-id 90c035a6-6dc2-4a76-ff22-08d82e425bfb
x-ms-traffictypediagnostic AM4PR02MB3124:
x-ms-exchange-transport-forked True
x-microsoft-antispam-prvs <AM4PR02MB3124D85D92E20BBC1F8945F3EA790@AM4PR02MB3124.eurprd02.prod.outlook.com>
x-ms-oob-tlc-oobclassifiers OLM:7219;
x-ms-exchange-senderadcheck 1
x-microsoft-antispam BCL:0;
x-microsoft-antispam-message-info WaiB+blBe+HFvPW5TwQSv025LcMtEj3C9MKKYFy7CcNicxViKrk3F55JkFgVlww7Vr1EyXZD9OYnw8XGBxstRsV9SiIO2Ci//EQU2p0kRNLsKTE5rSn2LXGjatQ4BE9ZPlgudc/kwzEzPYWNR/QoH2nDUwHAZb/UlAh/eel/apa/XwNyldfX72jxteBpSJRRIB24vG72xnqzqeYsv9bFRv8DjEEDXTnHkRgBArSmEe0sxXSjq2Uk0NNdMVcQwYhFkx1v+UowYF7dA1SOpg6gqSUKjVfKNJR+BB620Rd5OCv82JBzm8kgXP70poS4aEZj0CUKDVp08litbw6VbClXgxpqObLSw6Z+gerALylSwUMxNaqKo1EK7C62ALSeL7+E
x-forefront-antispam-report CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR0202MB3442.eurprd02.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(396003)(39860400002)(376002)(346002)(366004)(136003)(6916009)(6506007)(71200400001)(86362001)(53546011)(66946007)(9686003)(7696005)(52536014)(186003)(8936002)(66574015)(26005)(83380400001)(4326008)(91956017)(76116006)(55016002)(8676002)(54906003)(2906002)(33656002)(316002)(478600001)(5660300002)(66476007)(66556008)(64756008)(66446008)(21314003); DIR:OUT; SFP:1102;
x-ms-exchange-antispam-messagedata mxFcI/pEpyr0fWJkybdBb+P3j/koEgvaERSXJ2uTwnGr0iSkhYiMzx9ssgBg6wWKBdguLFX2g4Hu4sjV8tIk0uWxSy7mK46cIwuIvsoR6/k1SFaBZGEjqv/PEUhOO7IZ6BHAYoUCa9fzKtN+NSDSmCxaVrBdi76K4zQtD56zyV39NkzVqnZseigBKGPKA9hUpLB+SgbWSu8rsIv//pKJUGFgaWnc8E838hJUjgzNggFhlxh2oScetrw9Qk29GBrmYMoLAVt3X3blQpDeu6u0Usp/HEp9vG2QaQJ/t+OwS9ZBYXfdhcjXR3aAwRUg8RVN9WUy+ideuZfLbBwI93dCAsx5nwLBV0yArrSQnhxT0R/nbi784Ai9718tr0y8Tr48fvs+EULJdWT/bKreV3loYf6P9xtfUdCRe+4EfPrn4x20NKRh255CXEpG+9wecphJY82QJlUFbLeCwe9LOl3T+mIBAHpaz2fSUCdk9pjpv9k=
X-MS-Exchange-CrossTenant-AuthAs Internal
X-MS-Exchange-CrossTenant-AuthSource AM0PR0202MB3442.eurprd02.prod.outlook.com
X-MS-Exchange-CrossTenant-Network-Message-Id 90c035a6-6dc2-4a76-ff22-08d82e425bfb
X-MS-Exchange-CrossTenant-originalarrivaltime 22 Jul 2020 13:23:01.8036 (UTC)
X-MS-Exchange-CrossTenant-fromentityheader Hosted
X-MS-Exchange-CrossTenant-id 33440fc6-b7c7-412c-bb73-0e70b0198d5a
X-MS-Exchange-CrossTenant-mailboxtype HOSTED
X-MS-Exchange-CrossTenant-userprincipalname Z2gR16C1/XQPShVhCY6vi9wYq/t31Fv+9zMqklBgxSKzwXXMpK6DMTuZyblz4E6NZeQBP+5GKeoNvMx8s7/NDA==
X-MS-Exchange-Transport-CrossTenantHeadersStamped AM4PR02MB3124
X-OriginatorOrg atos.net
Received-SPF pass client-ip=193.56.114.176; envelope-from=clement.chigot@atos.net; helo=smarthost1.atos.net
X-detected-operating-system by eggs.gnu.org: First seen = 2020/07/22 09:24:24
X-ACL-Warn Detected OS = FreeBSD 9.x or newer [fuzzy]
X-Spam_score_int -53
X-Spam_score -5.4
X-Spam_bar -----
X-Spam_report (-5.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=ham autolearn_force=no
X-Spam_action no action
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.23
Precedence list
List-Id Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <https://lists.gnu.org/archive/html/bug-bash>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
X-Mailman-Original-Message-ID <AM0PR0202MB3442B671678DE7902279038BEA790@AM0PR0202MB3442.eurprd02.prod.outlook.com>
X-Mailman-Original-References <DB7PR02MB4075AEFED9BEDC6FDC0C2D2EEA1A0@DB7PR02MB4075.eurprd02.prod.outlook.com> <DB7PR02MB40752C791155F28BD5ACB44DEA150@DB7PR02MB4075.eurprd02.prod.outlook.com>, <c981c061-010a-d8f4-e9dd-d403a10c5bdd@case.edu>, <DB7PR02MB4075BA041EDA6A45E9D85386EA130@DB7PR02MB4075.eurprd02.prod.outlook.com>
Xref csiph.com gnu.bash.bug:16604

Show key headers only | View raw


Hi everyone,

It's been a while and I've forgotten to submit the solution I've found to avoid subprocesses stuck with named pipes. 
It's more a work around than a true fix, but I didn't manage to find a better solution.

I haven't checked version 5.1 yet. Did many things changed regarding named pipes ? 

Thanks, 
Clément 

-----------------------------------------------------------------------------------------

>From 77baaa524c385d720edcc6944985ddfc5cbc0651 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20Chigot?= <clement.chigot@atos.net>
Date: Thu, 20 Feb 2020 14:19:24 +0100
Subject: [PATCH] process substitution: unlink named pipes when closing shell

This patch forces the removal of named pipes made by process
substitution when the shell is closing, even if the subprocess still
exist.
As the subprocess might be blocked while opening its named pipe,
the parent process is also opening it to release the subprocess.

This avoids having unkilled subprocesses which are waiting for any
inputs from their parent.
---
 eval.c        |  2 +-
 execute_cmd.c | 16 ++++++++--------
 shell.c       |  4 ++--
 sig.c         |  6 +++---
 subst.c       | 17 +++++++++++------
 subst.h       |  2 +-
 6 files changed, 26 insertions(+), 21 deletions(-)

diff --git a/eval.c b/eval.c
index f02d6e40..d98aefe7 100644
--- a/eval.c
+++ b/eval.c
@@ -79,7 +79,7 @@ reader_loop ()
       code = setjmp_nosigs (top_level);
 
 #if defined (PROCESS_SUBSTITUTION)
-      unlink_fifo_list ();
+      unlink_fifo_list (0);
 #endif /* PROCESS_SUBSTITUTION */
 
       /* XXX - why do we set this every time through the loop?  And why do
diff --git a/execute_cmd.c b/execute_cmd.c
index 3864986d..c56be789 100644
--- a/execute_cmd.c
+++ b/execute_cmd.c
@@ -400,7 +400,7 @@ execute_command (command)
   /* don't unlink fifos if we're in a shell function; wait until the function
      returns. */
   if (variable_context == 0 && executing_list == 0)
-    unlink_fifo_list ();
+    unlink_fifo_list (0);
 #endif /* PROCESS_SUBSTITUTION */
 
   QUIT;
@@ -665,7 +665,7 @@ execute_command_internal (command, asynchronous, pipe_in, pipe_out,
 
 #if defined (PROCESS_SUBSTITUTION) && defined (HAVE_DEV_FD)
 	  if (variable_context == 0)	/* wait until shell function completes */
-	    unlink_fifo_list ();
+	    unlink_fifo_list (0);
 #endif
 	  /* If we are part of a pipeline, and not the end of the pipeline,
 	     then we should simply return and let the last command in the
@@ -2444,7 +2444,7 @@ execute_coproc (command, pipe_in, pipe_out, fds_to_close)
 
   close_pipes (pipe_in, pipe_out);
 #if defined (PROCESS_SUBSTITUTION) && defined (HAVE_DEV_FD)
-  unlink_fifo_list ();
+  unlink_fifo_list (0);
 #endif
   stop_pipeline (1, (COMMAND *)NULL);
   DESCRIBE_PID (coproc_pid);
@@ -4030,7 +4030,7 @@ execute_null_command (redirects, pipe_in, pipe_out, async)
 	  close_pipes (pipe_in, pipe_out);
 #if defined (PROCESS_SUBSTITUTION) && defined (HAVE_DEV_FD)
 	  if (pipe_out == NO_PIPE)
-	    unlink_fifo_list ();
+	    unlink_fifo_list (0);
 #endif
 	  return (EXECUTION_SUCCESS);
 	}
@@ -4298,7 +4298,7 @@ execute_simple_command (simple_command, pipe_in, pipe_out, async, fds_to_close)
 	     last child in a (possibly one-element) pipeline.  Defer this
 	     until any running shell function completes. */
 	  if (pipe_out == NO_PIPE && variable_context == 0)	/* XXX */
-	    unlink_fifo_list ();		/* XXX */
+	    unlink_fifo_list (0);		/* XXX */
 #endif
 #endif
 	  command_line = (char *)NULL;      /* don't free this. */
@@ -5024,7 +5024,7 @@ execute_function (var, words, flags, fds_to_close, async, subshell)
     {
       make_funcname_visible (0);
 #if defined (PROCESS_SUBSTITUTION)
-      unlink_fifo_list ();
+      unlink_fifo_list (0);
 #endif
     }
 
@@ -5438,7 +5438,7 @@ execute_disk_command (words, redirects, command_line, pipe_in, pipe_out,
 #if defined (PROCESS_SUBSTITUTION)
 	  /* Try to remove named pipes that may have been created as the
 	     result of redirections. */
-	  unlink_fifo_list ();
+	  unlink_fifo_list (0);
 #endif /* PROCESS_SUBSTITUTION */
 	  exit (EXECUTION_FAILURE);
 	}
@@ -5488,7 +5488,7 @@ parent_return:
 #if defined (PROCESS_SUBSTITUTION) && defined (HAVE_DEV_FD)
 #if 0
       if (variable_context == 0)
-        unlink_fifo_list ();
+        unlink_fifo_list (0);
 #endif
 #endif
       FREE (command);
diff --git a/shell.c b/shell.c
index a2b2a55e..2802ff08 100644
--- a/shell.c
+++ b/shell.c
@@ -973,7 +973,7 @@ exit_shell (s)
     s = run_exit_trap ();
 
 #if defined (PROCESS_SUBSTITUTION)
-  unlink_fifo_list ();
+  unlink_fifo_list (1);
 #endif /* PROCESS_SUBSTITUTION */
 
 #if defined (HISTORY)
@@ -1397,7 +1397,7 @@ run_one_command (command)
   if (code != NOT_JUMPED)
     {
 #if defined (PROCESS_SUBSTITUTION)
-      unlink_fifo_list ();
+      unlink_fifo_list (0);
 #endif /* PROCESS_SUBSTITUTION */
       switch (code)
 	{
diff --git a/sig.c b/sig.c
index f8a0e0f7..ece10274 100644
--- a/sig.c
+++ b/sig.c
@@ -376,7 +376,7 @@ top_level_cleanup ()
     parse_and_execute_cleanup (-1);
 
 #if defined (PROCESS_SUBSTITUTION)
-  unlink_fifo_list ();
+  unlink_fifo_list (0);
 #endif /* PROCESS_SUBSTITUTION */
 
   run_unwind_protects ();
@@ -434,7 +434,7 @@ throw_to_top_level ()
 #endif /* READLINE */
 
 #if defined (PROCESS_SUBSTITUTION)
-  unlink_fifo_list ();
+  unlink_fifo_list (0);
 #endif /* PROCESS_SUBSTITUTION */
 
   run_unwind_protects ();
@@ -580,7 +580,7 @@ termsig_handler (sig)
 #endif /* JOB_CONTROL */
 
 #if defined (PROCESS_SUBSTITUTION)
-  unlink_fifo_list ();
+  unlink_fifo_list (0);
 #endif /* PROCESS_SUBSTITUTION */
 
   /* Reset execution context */
diff --git a/subst.c b/subst.c
index fd6db240..fdbafe63 100644
--- a/subst.c
+++ b/subst.c
@@ -5382,7 +5382,8 @@ unlink_fifo (i)
 }
 
 void
-unlink_fifo_list ()
+unlink_fifo_list (force)
+     int force;
 {
   int saved, i, j;
 
@@ -5391,8 +5392,11 @@ unlink_fifo_list ()
 
   for (i = saved = 0; i < nfifo; i++)
     {
-      if ((fifo_list[i].proc == (pid_t)-1) || (fifo_list[i].proc > 0 && (kill(fifo_list[i].proc, 0) == -1)))
+      if ((fifo_list[i].proc == (pid_t)-1) || (fifo_list[i].proc > 0 && (kill(fifo_list[i].proc, 0) == -1)) || force)
 	{
+	  // Open the named pipe to release eventual subprocesses
+	  // being blocked on an open syscall.
+	  open(fifo_list[i].file, O_RDWR | O_NONBLOCK);
 	  unlink (fifo_list[i].file);
 	  free (fifo_list[i].file);
 	  fifo_list[i].file = (char *)NULL;
@@ -5432,7 +5436,7 @@ close_new_fifos (list, lsize)
 
   if (list == 0)
     {
-      unlink_fifo_list ();
+      unlink_fifo_list (0);
       return;
     }
 
@@ -5627,7 +5631,8 @@ unlink_fifo (fd)
 }
 
 void
-unlink_fifo_list ()
+unlink_fifo_list (force)
+     int force;
 {
   register int i;
 
@@ -5654,7 +5659,7 @@ close_new_fifos (list, lsize)
 
   if (list == 0)
     {
-      unlink_fifo_list ();
+      unlink_fifo_list (0);
       return;
     }
 
@@ -6349,7 +6354,7 @@ command_substitute (string, quoted, flags)
       last_command_exit_value = rc;
       rc = run_exit_trap ();
 #if defined (PROCESS_SUBSTITUTION)
-      unlink_fifo_list ();
+      unlink_fifo_list (0);
 #endif
       exit (rc);
     }
diff --git a/subst.h b/subst.h
index 34763222..931ec1e8 100644
--- a/subst.h
+++ b/subst.h
@@ -270,7 +270,7 @@ extern char *pat_subst __P((char *, char *, char *, int));
 #if defined (PROCESS_SUBSTITUTION)
 extern int fifos_pending __P((void));
 extern int num_fifos __P((void));
-extern void unlink_fifo_list __P((void));
+extern void unlink_fifo_list __P((int));
 extern void unlink_fifo __P((int));
 
 extern void *copy_fifo_list __P((int *));
-- 
2.17.1

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Re: Procsub.tests on OSes using named pipes "CHIGOT, CLEMENT" <clement.chigot@atos.net> - 2020-07-22 13:23 +0000

csiph-web