Leaving SIG_IGN for SIGCHLD reaps an earlier zombie where Linux keeps it
I maintainer di solito rispondono entro 2 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 18/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- c
- Ambito
- operating-systems
Direzione di ricerca
Start with signal_rt_sigaction in src/syscall/signal.c and proc_autoreap_exited_children in src/syscall/proc.c, where the reap runs for every exited child. Run the reproduction in the issue, then check the ign case in tests/test-sigchld-after-wait.c, which currently accepts ECHILD. Done means waitpid returns the pre-existing zombie after SIG_IGN is set and then restored. That needs a per-child record of the disposition at exit, which is a design choice, so confirm the approach with maintainers first.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
What happens
When a new SIGCHLD action replaces one that reaps children by itself (SIG_IGN or SA_NOCLDWAIT, see sigaction_autoreaps_sigchld), signal_rt_sigaction in src/syscall/signal.c calls proc_autoreap_exited_children in src/syscall/proc.c. That reaps every child that has exited, including one that was already a zombie before SIG_IGN was installed, so a later waitpid for it returns ECHILD. Linux reaps automatically only a child whose exit finds SIG_IGN or SA_NOCLDWAIT in force (do_notify_parent in kernel/signal.c); a child that is already a zombie stays one, and waitpid returns it.
Evidence
The probe below, run with elfuse-probe-diff:
| build | waitpid after SIG_IGN and the handler again |
|---|---|
| elfuse, upstream/main c57282f | ECHILD |
| elfuse, #538 at 850d08a | ECHILD |
| Linux 6.18.63 (QEMU) | the child, exit status 7 |
Run for SIG_IGN only; SA_NOCLDWAIT takes the same path by reading, not run.
Cause
Checked by reading: the reap in signal_rt_sigaction runs whenever the old action reaps automatically, and proc_autoreap_exited_children takes every child in a terminal lifecycle state. It cannot tell a child that exited under SIG_IGN from one that was a zombie before it, because no record says which disposition the exit found (the mark #538 adds says only that the SIGCHLD was discarded, which SIG_DFL also does). The comment above the reap says it closes a race where the guest restores SIG_DFL after it sees the child's teardown but before the exit's record is drained.
Reproduce
/* A child exits under a SIGCHLD handler; SIG_IGN, then the handler again,
* while the child is still a zombie. Linux keeps the zombie for waitpid. */
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
static void on_chld(int sig) { (void) sig; }
int main(void)
{
struct sigaction catch, ign;
memset(&catch, 0, sizeof(catch));
sigemptyset(&catch.sa_mask);
catch.sa_handler = on_chld;
ign = catch;
ign.sa_handler = SIG_IGN;
sigaction(SIGCHLD, &catch, NULL);
pid_t pid = fork();
if (pid == 0)
_exit(7);
siginfo_t si;
memset(&si, 0, sizeof(si));
waitid(P_PID, pid, &si, WEXITED | WNOWAIT); /* now a zombie */
sigaction(SIGCHLD, &ign, NULL);
sigaction(SIGCHLD, &catch, NULL);
int status = 0;
pid_t r = waitpid(pid, &status, 0);
if (r == pid)
printf("waitpid: the child, exit status %d\n", WEXITSTATUS(status));
else
printf("waitpid: %s\n", errno == ECHILD ? "ECHILD" : strerror(errno));
return 0;
}
Possible fix
Reap only the children whose exit found the auto-reap disposition. Since #538 the exiting child reads its parent's SIGCHLD flag file at the exit; a second value there ("the parent reaps automatically") would let the child's record say so, and the parent would reap only those children.
Origin
Follow-up from #538 (https://github.com/sysprog21/elfuse/pull/538), whose ign case in tests/test-sigchld-after-wait.c accepts ECHILD from its last waitpid for this reason.
- Lingua principale
- C
- Stelle
- 287
- Fork
- 33
- Merge medio
- 2g 17h
- PR unite (30g)
- 18
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di sysprog21/elfuse
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 80/100
I maintainer di solito rispondono entro 2 giorni
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
I maintainer di solito rispondono entro 2 giorni
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 2 giorni
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di sysprog21/elfuse
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
libreswan/libreswan#3185 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
[SDL3pp] update to 0.12.0Apertacategory:port-update
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 2 giorni
-
[InstCombine] 23.x folds 0.0 * (0.0 / x) to 0.0 when x may be zero (fixed on main by #202482)Apertallvm:instcombine
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
llvm/llvm-project#246503 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno