Skip to content

gmain: Use waitid() on pidfds rather than a global SIGCHLD handler

Philip Withnall requested to merge wip/pwithnall/2216-pidfd-sigchld into main

When the system supports it (as all Linux kernels ≥ 5.3 should), it’s preferable to use pidfd_open() and waitid() to be notified of child processes exiting or being signalled, rather than installing a default SIGCHLD handler.

A default SIGCHLD handler is global, and can never interact well with other code (from the application or other libraries) which also wants to install a SIGCHLD handler.

This use of pidfd_open() is racy (the PID may be reused between g_child_watch_source_new() being called and pidfd_open() being called), so it doesn’t improve behaviour there. For that, we’d need continuous use of pidfds throughout GLib, from fork/spawn time until here. See #1866 for that.

Signed-off-by: Philip Withnall pwithnall@endlessos.org

Helps: #1866 Fixes: #2216 (closed)

Closes #2216 (closed)

Edited by Philip Withnall

Merge request reports