From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?utf-8?Q?J=C3=BCrgen_H=C3=B6tzel?= Newsgroups: gmane.emacs.devel Subject: [PATCH] posix_spawn blocks SIGCHLD in spawned processes (was: Re: master 2c79a8f 2/2: Use posix_spawn if possible.) Date: Fri, 04 Mar 2022 09:38:25 +0100 Message-ID: <86o82mvybj.fsf@hoetzel.info> References: <7CFD5E28-8266-4004-BF66-255146D72722@gnu.org> <83r18whunp.fsf@gnu.org> <36bbd45c-0a87-13b7-1589-afe943329e20@fastmail.com> <83ee4whqpf.fsf@gnu.org> <87v8y33hu1.fsf@rfc20.org> <83sft7aqxd.fsf@gnu.org> <3db6c69c-0c08-3f92-491b-0b715b18eb40@fastmail.com> <87pmo6c3h6.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23688"; mail-complaints-to="usenet@ciao.gmane.io" Cc: alan@idiocy.org, emacs-devel@gnu.org, Saulius Menkevicius , p.stephani2@gmail.com, Matt Armstrong , Eli Zaretskii , mituharu@math.s.chiba-u.ac.jp To: Robert Pluim Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Mar 04 10:54:16 2022 Return-path: Envelope-to: ged-emacs-devel@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 1nQ4dc-0005x9-6e for ged-emacs-devel@m.gmane-mx.org; Fri, 04 Mar 2022 10:54:16 +0100 Original-Received: from localhost ([::1]:37110 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nQ4da-0004PS-FQ for ged-emacs-devel@m.gmane-mx.org; Fri, 04 Mar 2022 04:54:14 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:33398) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nQ4cn-0003aQ-0N for emacs-devel@gnu.org; Fri, 04 Mar 2022 04:53:25 -0500 Original-Received: from mout-p-101.mailbox.org ([80.241.56.151]:41086) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_CHACHA20_POLY1305:256) (Exim 4.90_1) (envelope-from ) id 1nQ4ck-0008Rl-EK; Fri, 04 Mar 2022 04:53:24 -0500 Original-Received: from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4K937v2NJjz9sTV; Fri, 4 Mar 2022 10:53:15 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hoetzel.info; s=MBO0001; t=1646387593; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=6CPuphmOoeaNXsRYGBoJ6PL/c2DHZaHbHNwoqia7mUM=; b=UZrYkJKdsodNj2BEnCU8nBYILmHHYPrceGzWbEcjnr/TO/pp4Cu/rkVag41e+j9Hau9Yna fhROPUKEnRoduE68yGwAd93nqrhg4FnlByk5fJ4FDiBfVFFqf3MhGyY7ZdhwQRsi39s8Mb pPAYKdS/gSPwr2rLXXf3RTg7hB2rJ+k0Wf0Dlzy+aCFHhr1bVatEtrws1RsfVQGTK0pAZp CaMRDPkCmLxdwgAxih3hf+DRjJ270XPJOeD2wX7Z77IjbSYa60EWySqWdfeGVZ4hA3PXtc aWIqnZhkpq0412fNcNV2pKGNUSn/iPK/+DqisbdJajdO3B+nhzx9FC0RWcC2Mw== In-reply-to: <87pmo6c3h6.fsf@gmail.com> Received-SPF: pass client-ip=80.241.56.151; envelope-from=juergen@hoetzel.info; helo=mout-p-101.mailbox.org X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:286812 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Robert Pluim writes: >>>>>> On Mon, 31 Jan 2022 22:48:33 +0200, Saulius Menkevicius said: > Try the following: > > diff --git a/src/callproc.c b/src/callproc.c > index 4d3b0bb8e0..2b4e8977a3 100644 > --- a/src/callproc.c > +++ b/src/callproc.c > @@ -1378,6 +1378,12 @@ emacs_posix_spawn_init_attributes (posix_spawnattr= _t *attributes) > /* Stop blocking SIGCHLD in the child. */ > sigset_t oldset; ^^^ This is the root-cause of the issue: A new/invalid signal mask is introduced. The correct oldset mask from emacs_spawn(...,const sigset_t *oldset) is simply ignored. > error =3D pthread_sigmask (SIG_SETMASK, NULL, &oldset); > + if (error !=3D 0) > + goto out; > + error =3D sigdelset (&oldset, SIGCHLD); > + if (error !=3D 0) > + goto out; > + error =3D sigdelset (&oldset, SIGINT); > if (error !=3D 0) > goto out; > error =3D posix_spawnattr_setsigmask (attributes, &oldset); IMO the correct way to fix this issue is to use the oldset passed by emacs_spawn (patch enclosed) just like the fork/exec implementation does. I guess without a fix many forking commands (that don't examine and change mask of blocked signals) will "hang" in Emacs. "dotnet" is just a prominent one. J=C3=BCrgen --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Use-correct-signal-oldset-in-posix_spawn-implementat.patch Content-Description: [PATCH] Use correct signal oldset in posix_spawn implementation >From f691f4c304d226f99ac0377de3b6186154c0d8fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20H=C3=B6tzel?= Date: Fri, 4 Mar 2022 10:08:14 +0100 Subject: [PATCH] Use correct signal oldset in posix_spawn implementation * src/callproc.c (emacs_spawn): Pass oldset parameter. (emacs_posix_spawn_init_attributes): Use correct oldset. (emacs_posix_spawn_init): remove intermediate function. --- src/callproc.c | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/src/callproc.c b/src/callproc.c index 018c9ce690..0922e10f01 100644 --- a/src/callproc.c +++ b/src/callproc.c @@ -1335,7 +1335,8 @@ emacs_posix_spawn_init_actions (posix_spawn_file_actions_t *actions, } static int -emacs_posix_spawn_init_attributes (posix_spawnattr_t *attributes) +emacs_posix_spawn_init_attributes (posix_spawnattr_t *attributes, + const sigset_t *oldset) { int error = posix_spawnattr_init (attributes); if (error != 0) @@ -1377,11 +1378,7 @@ emacs_posix_spawn_init_attributes (posix_spawnattr_t *attributes) goto out; /* Stop blocking SIGCHLD in the child. */ - sigset_t oldset; - error = pthread_sigmask (SIG_SETMASK, NULL, &oldset); - if (error != 0) - goto out; - error = posix_spawnattr_setsigmask (attributes, &oldset); + error = posix_spawnattr_setsigmask (attributes, oldset); if (error != 0) goto out; @@ -1392,23 +1389,6 @@ emacs_posix_spawn_init_attributes (posix_spawnattr_t *attributes) return error; } -static int -emacs_posix_spawn_init (posix_spawn_file_actions_t *actions, - posix_spawnattr_t *attributes, int std_in, - int std_out, int std_err, const char *cwd) -{ - int error = emacs_posix_spawn_init_actions (actions, std_in, - std_out, std_err, cwd); - if (error != 0) - return error; - - error = emacs_posix_spawn_init_attributes (attributes); - if (error != 0) - return error; - - return 0; -} - #endif /* Start a new asynchronous subprocess. If successful, return zero @@ -1443,9 +1423,12 @@ emacs_spawn (pid_t *newpid, int std_in, int std_out, int std_err, if (use_posix_spawn) { /* Initialize optional attributes before blocking. */ - int error - = emacs_posix_spawn_init (&actions, &attributes, std_in, - std_out, std_err, cwd); + int error = emacs_posix_spawn_init_actions (&actions, std_in, + std_out, std_err, cwd); + if (error != 0) + return error; + + error = emacs_posix_spawn_init_attributes (&attributes, oldset); if (error != 0) return error; } -- 2.35.1 --=-=-=--