From: "Jürgen Hötzel" <juergen@hoetzel.info>
To: Robert Pluim <rpluim@gmail.com>
Cc: alan@idiocy.org, emacs-devel@gnu.org,
Saulius Menkevicius <sauliusmenkevicius@fastmail.com>,
p.stephani2@gmail.com, Matt Armstrong <matt@rfc20.org>,
Eli Zaretskii <eliz@gnu.org>,
mituharu@math.s.chiba-u.ac.jp
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 [thread overview]
Message-ID: <86o82mvybj.fsf@hoetzel.info> (raw)
In-Reply-To: <87pmo6c3h6.fsf@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1305 bytes --]
Robert Pluim <rpluim@gmail.com> writes:
>>>>>> On Mon, 31 Jan 2022 22:48:33 +0200, Saulius Menkevicius <sauliusmenkevicius@fastmail.com> 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 = pthread_sigmask (SIG_SETMASK, NULL, &oldset);
> + if (error != 0)
> + goto out;
> + error = sigdelset (&oldset, SIGCHLD);
> + if (error != 0)
> + goto out;
> + error = sigdelset (&oldset, SIGINT);
> if (error != 0)
> goto out;
> error = 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ürgen
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: [PATCH] Use correct signal oldset in posix_spawn implementation --]
[-- Type: text/x-patch, Size: 2748 bytes --]
From f691f4c304d226f99ac0377de3b6186154c0d8fd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=BCrgen=20H=C3=B6tzel?= <juergen@archlinux.org>
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
next prev parent reply other threads:[~2022-03-04 8:38 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-25 6:48 master 2c79a8f 2/2: Use posix_spawn if possible Saulius Menkevicius
2022-01-25 8:41 ` Eli Zaretskii
2022-01-25 8:58 ` Saulius Menkevicius
2022-01-25 11:46 ` Jostein Kjønigsen
2022-01-25 11:55 ` Po Lu
2022-01-25 12:22 ` Eli Zaretskii
2022-01-25 12:25 ` Saulius Menkevicius
2022-01-25 13:47 ` Eli Zaretskii
2022-01-28 17:12 ` Matt Armstrong
2022-01-29 8:03 ` Saulius Menkevičius
2022-01-29 8:26 ` Eli Zaretskii
2022-01-31 20:48 ` Saulius Menkevicius
2022-02-01 9:59 ` Robert Pluim
2022-02-01 18:30 ` Saulius Menkevicius
2022-02-01 19:23 ` Robert Pluim
2022-02-01 19:52 ` Eli Zaretskii
2022-02-02 8:30 ` Robert Pluim
2022-02-02 8:54 ` Saulius Menkevičius
2022-02-07 21:12 ` Saulius Menkevicius
2022-02-08 8:27 ` Robert Pluim
2022-02-08 12:12 ` Eli Zaretskii
2022-02-08 12:18 ` Saulius Menkevicius
2022-02-08 14:59 ` Robert Pluim
2022-02-08 21:09 ` Saulius Menkevicius
2022-02-09 8:48 ` Robert Pluim
2022-02-12 8:44 ` Saulius Menkevicius
2022-02-12 8:59 ` Eli Zaretskii
2022-02-12 9:42 ` Saulius Menkevicius
2022-03-04 8:38 ` Jürgen Hötzel [this message]
2022-03-04 10:07 ` [PATCH] posix_spawn blocks SIGCHLD in spawned processes Robert Pluim
2022-03-04 15:41 ` Jürgen Hötzel
2022-03-04 16:08 ` Robert Pluim
2022-04-17 18:22 ` Philipp Stephani
2022-04-19 14:36 ` Robert Pluim
2022-04-19 14:48 ` Philipp Stephani
2022-04-19 16:07 ` Eli Zaretskii
2022-04-19 17:32 ` Robert Pluim
2022-04-04 14:13 ` Robert Pluim
2022-01-25 13:15 ` master 2c79a8f 2/2: Use posix_spawn if possible Stefan Monnier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86o82mvybj.fsf@hoetzel.info \
--to=juergen@hoetzel.info \
--cc=alan@idiocy.org \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
--cc=matt@rfc20.org \
--cc=mituharu@math.s.chiba-u.ac.jp \
--cc=p.stephani2@gmail.com \
--cc=rpluim@gmail.com \
--cc=sauliusmenkevicius@fastmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.