[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] posix_spawn blocks SIGCHLD in spawned processes
From: |
Jürgen Hötzel |
Subject: |
Re: [PATCH] posix_spawn blocks SIGCHLD in spawned processes |
Date: |
Fri, 04 Mar 2022 16:41:15 +0100 |
Robert Pluim <rpluim@gmail.com> writes:
>>>>>> On Fri, 04 Mar 2022 09:38:25 +0100, Jürgen Hötzel <juergen@hoetzel.info>
>>>>>> said:
> Jürgen> IMO the correct way to fix this issue is to use the oldset passed
> by
> Jürgen> emacs_spawn (patch enclosed) just like the fork/exec
> implementation does.
>
> Sure, that would work as well.
>
> Jürgen> I guess without a fix many forking commands (that don't examine
> and
> Jürgen> change mask of blocked signals) will "hang" in Emacs.
>
> Not really. Itʼs a code path thatʼs non-default, since
> process-connection-type defaults to t => use pty's, and the command in
‘call-process’ invokes emacs_spawn 'call-process' with pty set to NULL
so ‘process-connection-type’ doesn't have an effect here.
A minimal C example to reproduce the HANG is
--8<---------------cut here---------------start hang.c------------->8---
#include <signal.h>
#include <stdio.h>
#include <sys/wait.h>
#include <unistd.h>
void chld_handler(int signum) { printf("\nInside CHLD handler function\n"); }
int main(int argc, char *argv[]) {
sigset_t blocked, old;
signal(SIGCHLD, chld_handler); // Setup Child handler
sigemptyset(&blocked);
sigaddset(&blocked, SIGCHLD);
sigprocmask(SIG_BLOCK, &blocked, &old);
if (!fork()) {
return 0; /* child signals SIGCHLD */
}
sigsuspend(&old); /* WAITS for ever when SIGCHILD was originally blocked */
printf("Parent terminates\n");
return 0;
}
--8<---------------cut here---------------end hang.c--------------->8---
(call-process "chldtest" nil t nil) will never return.
Regards, Jürgen