Path: csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail From: "CHIGOT, CLEMENT" 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: References: , , 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 , "REIX, Tony" , Sanket Rathi To: "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: =?us-ascii?q?MDFdK08YvJ7lL79RLPxXFTzc+TWeNDYqM9QM+W?= =?us-ascii?q?Zk00FqXsrvyHWc6VY63lo24LkkT1YSWtjLnPFTaqDBMM5XxT3SJtvR0Y?= =?us-ascii?q?ks+KXip6lxwA6AIZHmopj3ArK6bPhCcNPyMBrIzqFm0UAjEIP89ZXaIb?= =?us-ascii?q?Ts?= 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: 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: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: , , Xref: csiph.com gnu.bash.bug:16604 Hi everyone,=0A= =0A= It's been a while and I've forgotten to submit the=A0solution I've found to= avoid subprocesses stuck with named pipes. =0A= It's more a work around than a true fix, but I didn't manage to find a bett= er solution.=0A= =0A= I haven't checked version 5.1 yet. Did many things changed regarding named = pipes ? =0A= =0A= Thanks, =0A= Cl=E9ment =0A= =0A= ---------------------------------------------------------------------------= --------------=0A= =0A= >From 77baaa524c385d720edcc6944985ddfc5cbc0651 Mon Sep 17 00:00:00 2001=0A= From: =3D?UTF-8?q?Cl=3DC3=3DA9ment=3D20Chigot?=3D = =0A= Date: Thu, 20 Feb 2020 14:19:24 +0100=0A= Subject: [PATCH] process substitution: unlink named pipes when closing shel= l=0A= =0A= This patch forces the removal of named pipes made by process=0A= substitution when the shell is closing, even if the subprocess still=0A= exist.=0A= As the subprocess might be blocked while opening its named pipe,=0A= the parent process is also opening it to release the subprocess.=0A= =0A= This avoids having unkilled subprocesses which are waiting for any=0A= inputs from their parent.=0A= ---=0A= eval.c | 2 +-=0A= execute_cmd.c | 16 ++++++++--------=0A= shell.c | 4 ++--=0A= sig.c | 6 +++---=0A= subst.c | 17 +++++++++++------=0A= subst.h | 2 +-=0A= 6 files changed, 26 insertions(+), 21 deletions(-)=0A= =0A= diff --git a/eval.c b/eval.c=0A= index f02d6e40..d98aefe7 100644=0A= --- a/eval.c=0A= +++ b/eval.c=0A= @@ -79,7 +79,7 @@ reader_loop ()=0A= code =3D setjmp_nosigs (top_level);=0A= =0A= #if defined (PROCESS_SUBSTITUTION)=0A= - unlink_fifo_list ();=0A= + unlink_fifo_list (0);=0A= #endif /* PROCESS_SUBSTITUTION */=0A= =0A= /* XXX - why do we set this every time through the loop? And why do= =0A= diff --git a/execute_cmd.c b/execute_cmd.c=0A= index 3864986d..c56be789 100644=0A= --- a/execute_cmd.c=0A= +++ b/execute_cmd.c=0A= @@ -400,7 +400,7 @@ execute_command (command)=0A= /* don't unlink fifos if we're in a shell function; wait until the funct= ion=0A= returns. */=0A= if (variable_context =3D=3D 0 && executing_list =3D=3D 0)=0A= - unlink_fifo_list ();=0A= + unlink_fifo_list (0);=0A= #endif /* PROCESS_SUBSTITUTION */=0A= =0A= QUIT;=0A= @@ -665,7 +665,7 @@ execute_command_internal (command, asynchronous, pipe_i= n, pipe_out,=0A= =0A= #if defined (PROCESS_SUBSTITUTION) && defined (HAVE_DEV_FD)=0A= if (variable_context =3D=3D 0) /* wait until shell function completes *= /=0A= - unlink_fifo_list ();=0A= + unlink_fifo_list (0);=0A= #endif=0A= /* If we are part of a pipeline, and not the end of the pipeline,=0A= then we should simply return and let the last command in the=0A= @@ -2444,7 +2444,7 @@ execute_coproc (command, pipe_in, pipe_out, fds_to_cl= ose)=0A= =0A= close_pipes (pipe_in, pipe_out);=0A= #if defined (PROCESS_SUBSTITUTION) && defined (HAVE_DEV_FD)=0A= - unlink_fifo_list ();=0A= + unlink_fifo_list (0);=0A= #endif=0A= stop_pipeline (1, (COMMAND *)NULL);=0A= DESCRIBE_PID (coproc_pid);=0A= @@ -4030,7 +4030,7 @@ execute_null_command (redirects, pipe_in, pipe_out, a= sync)=0A= close_pipes (pipe_in, pipe_out);=0A= #if defined (PROCESS_SUBSTITUTION) && defined (HAVE_DEV_FD)=0A= if (pipe_out =3D=3D NO_PIPE)=0A= - unlink_fifo_list ();=0A= + unlink_fifo_list (0);=0A= #endif=0A= return (EXECUTION_SUCCESS);=0A= }=0A= @@ -4298,7 +4298,7 @@ execute_simple_command (simple_command, pipe_in, pipe= _out, async, fds_to_close)=0A= last child in a (possibly one-element) pipeline. Defer this=0A= until any running shell function completes. */=0A= if (pipe_out =3D=3D NO_PIPE && variable_context =3D=3D 0) /* XXX */=0A= - unlink_fifo_list (); /* XXX */=0A= + unlink_fifo_list (0); /* XXX */=0A= #endif=0A= #endif=0A= command_line =3D (char *)NULL; /* don't free this. */=0A= @@ -5024,7 +5024,7 @@ execute_function (var, words, flags, fds_to_close, as= ync, subshell)=0A= {=0A= make_funcname_visible (0);=0A= #if defined (PROCESS_SUBSTITUTION)=0A= - unlink_fifo_list ();=0A= + unlink_fifo_list (0);=0A= #endif=0A= }=0A= =0A= @@ -5438,7 +5438,7 @@ execute_disk_command (words, redirects, command_line,= pipe_in, pipe_out,=0A= #if defined (PROCESS_SUBSTITUTION)=0A= /* Try to remove named pipes that may have been created as the=0A= result of redirections. */=0A= - unlink_fifo_list ();=0A= + unlink_fifo_list (0);=0A= #endif /* PROCESS_SUBSTITUTION */=0A= exit (EXECUTION_FAILURE);=0A= }=0A= @@ -5488,7 +5488,7 @@ parent_return:=0A= #if defined (PROCESS_SUBSTITUTION) && defined (HAVE_DEV_FD)=0A= #if 0=0A= if (variable_context =3D=3D 0)=0A= - unlink_fifo_list ();=0A= + unlink_fifo_list (0);=0A= #endif=0A= #endif=0A= FREE (command);=0A= diff --git a/shell.c b/shell.c=0A= index a2b2a55e..2802ff08 100644=0A= --- a/shell.c=0A= +++ b/shell.c=0A= @@ -973,7 +973,7 @@ exit_shell (s)=0A= s =3D run_exit_trap ();=0A= =0A= #if defined (PROCESS_SUBSTITUTION)=0A= - unlink_fifo_list ();=0A= + unlink_fifo_list (1);=0A= #endif /* PROCESS_SUBSTITUTION */=0A= =0A= #if defined (HISTORY)=0A= @@ -1397,7 +1397,7 @@ run_one_command (command)=0A= if (code !=3D NOT_JUMPED)=0A= {=0A= #if defined (PROCESS_SUBSTITUTION)=0A= - unlink_fifo_list ();=0A= + unlink_fifo_list (0);=0A= #endif /* PROCESS_SUBSTITUTION */=0A= switch (code)=0A= {=0A= diff --git a/sig.c b/sig.c=0A= index f8a0e0f7..ece10274 100644=0A= --- a/sig.c=0A= +++ b/sig.c=0A= @@ -376,7 +376,7 @@ top_level_cleanup ()=0A= parse_and_execute_cleanup (-1);=0A= =0A= #if defined (PROCESS_SUBSTITUTION)=0A= - unlink_fifo_list ();=0A= + unlink_fifo_list (0);=0A= #endif /* PROCESS_SUBSTITUTION */=0A= =0A= run_unwind_protects ();=0A= @@ -434,7 +434,7 @@ throw_to_top_level ()=0A= #endif /* READLINE */=0A= =0A= #if defined (PROCESS_SUBSTITUTION)=0A= - unlink_fifo_list ();=0A= + unlink_fifo_list (0);=0A= #endif /* PROCESS_SUBSTITUTION */=0A= =0A= run_unwind_protects ();=0A= @@ -580,7 +580,7 @@ termsig_handler (sig)=0A= #endif /* JOB_CONTROL */=0A= =0A= #if defined (PROCESS_SUBSTITUTION)=0A= - unlink_fifo_list ();=0A= + unlink_fifo_list (0);=0A= #endif /* PROCESS_SUBSTITUTION */=0A= =0A= /* Reset execution context */=0A= diff --git a/subst.c b/subst.c=0A= index fd6db240..fdbafe63 100644=0A= --- a/subst.c=0A= +++ b/subst.c=0A= @@ -5382,7 +5382,8 @@ unlink_fifo (i)=0A= }=0A= =0A= void=0A= -unlink_fifo_list ()=0A= +unlink_fifo_list (force)=0A= + int force;=0A= {=0A= int saved, i, j;=0A= =0A= @@ -5391,8 +5392,11 @@ unlink_fifo_list ()=0A= =0A= for (i =3D saved =3D 0; i < nfifo; i++)=0A= {=0A= - if ((fifo_list[i].proc =3D=3D (pid_t)-1) || (fifo_list[i].proc > 0 &= & (kill(fifo_list[i].proc, 0) =3D=3D -1)))=0A= + if ((fifo_list[i].proc =3D=3D (pid_t)-1) || (fifo_list[i].proc > 0 &= & (kill(fifo_list[i].proc, 0) =3D=3D -1)) || force)=0A= {=0A= + // Open the named pipe to release eventual subprocesses=0A= + // being blocked on an open syscall.=0A= + open(fifo_list[i].file, O_RDWR | O_NONBLOCK);=0A= unlink (fifo_list[i].file);=0A= free (fifo_list[i].file);=0A= fifo_list[i].file =3D (char *)NULL;=0A= @@ -5432,7 +5436,7 @@ close_new_fifos (list, lsize)=0A= =0A= if (list =3D=3D 0)=0A= {=0A= - unlink_fifo_list ();=0A= + unlink_fifo_list (0);=0A= return;=0A= }=0A= =0A= @@ -5627,7 +5631,8 @@ unlink_fifo (fd)=0A= }=0A= =0A= void=0A= -unlink_fifo_list ()=0A= +unlink_fifo_list (force)=0A= + int force;=0A= {=0A= register int i;=0A= =0A= @@ -5654,7 +5659,7 @@ close_new_fifos (list, lsize)=0A= =0A= if (list =3D=3D 0)=0A= {=0A= - unlink_fifo_list ();=0A= + unlink_fifo_list (0);=0A= return;=0A= }=0A= =0A= @@ -6349,7 +6354,7 @@ command_substitute (string, quoted, flags)=0A= last_command_exit_value =3D rc;=0A= rc =3D run_exit_trap ();=0A= #if defined (PROCESS_SUBSTITUTION)=0A= - unlink_fifo_list ();=0A= + unlink_fifo_list (0);=0A= #endif=0A= exit (rc);=0A= }=0A= diff --git a/subst.h b/subst.h=0A= index 34763222..931ec1e8 100644=0A= --- a/subst.h=0A= +++ b/subst.h=0A= @@ -270,7 +270,7 @@ extern char *pat_subst __P((char *, char *, char *, int= ));=0A= #if defined (PROCESS_SUBSTITUTION)=0A= extern int fifos_pending __P((void));=0A= extern int num_fifos __P((void));=0A= -extern void unlink_fifo_list __P((void));=0A= +extern void unlink_fifo_list __P((int));=0A= extern void unlink_fifo __P((int));=0A= =0A= extern void *copy_fifo_list __P((int *));=0A= -- =0A= 2.17.1=0A= =0A=