sd-event: Clean up SIGCHLD conditions for sd_event_add_child()

First, don't require blocking SIGCHLD for WEXITED. We watch for WEXITED
via pidfd instead of signalfd, so no need to insist on blocking SIGCHLD
anymore if we're only watching for WEXITED.

Second, do a proper check to see if the kernel autoreaping logic is
enabled. That has nothing to do with SIGCHLD being blocked for the current
thread or not. Instead, the kernel autoreaping logic is enabled either if
the disposition is set to SIG_IGN or if the SA_NOCLDWAIT flag is enabled.
This commit is contained in:
Daan De Meyer
2025-12-20 15:27:22 +01:00
parent 20367ade71
commit a1e5d7f865
7 changed files with 82 additions and 30 deletions
+9
View File
@@ -238,6 +238,15 @@ int signal_is_blocked(int sig) {
return RET_NERRNO(sigismember(&ss, sig));
}
int autoreaping_enabled(void) {
struct sigaction sa;
if (sigaction(SIGCHLD, /* __act= */ NULL, &sa) < 0)
return -errno;
return sa.sa_handler == SIG_IGN || FLAGS_SET(sa.sa_flags, SA_NOCLDWAIT);
}
int pop_pending_signal_internal(int sig, ...) {
sigset_t ss;
va_list ap;
+2
View File
@@ -66,6 +66,8 @@ static inline const char* signal_to_string_with_check(int n) {
int signal_is_blocked(int sig);
int autoreaping_enabled(void);
int pop_pending_signal_internal(int sig, ...);
#define pop_pending_signal(...) pop_pending_signal_internal(__VA_ARGS__, -1)