Systemd/src/libsystemd
Lennart Poettering f8f3f9263e sd-event: add pidfd support
This adds support for watching for process exits via Linux new pidfd
concept. This makes watching processes and killing them race-free if
properly used, fixing a long-standing UNIX misdesign.

This patch adds implicit and explicit pidfd support to sd-event: if a
process shall be watched and is specified by PID we will now internally
create a pidfd for it and use that, if available. Alternatively a new
constructor for child process event sources is added that takes pidfds
as input.

Besides mere watching of child processes via pidfd two additional
features are added:

→ sd_event_source_send_child_signal() allows sending a signal to the
  process being watched in the safest way possible (wrapping
  the new pidfd_send_signal() syscall).

→ sd_event_source_set_child_process_own() allows marking a process
  watched for destruction as soon as the event source is freed. This is
  currently implemented in userspace, but hopefully will become a kernel
  feature eventually.

Altogether this means an sd_event_source object is now a safe and stable
concept for referencing processes in race-free way, with automatic
fallback to pre-pidfd kernels.

Note that this patch adds support for this only to sd-event, not to PID
1. That's because PID 1 needs to use waitid(P_ALL) for reaping any
process that might get reparented to it. This currently semantically
conflicts with pidfd use for watching processes since we P_ALL is
undirected and thus might reap process earlier than the pidfd notifies
process end, which is hard to handle. The kernel will likely gain a
concept for excluding specific pidfds from P_ALL watching, as soon as
that is around we can start making use of this in PID 1 too.
2019-12-04 10:34:41 +01:00
..
sd-bus network: do not return error but return UINT64_MAX if speed meter is disabled 2019-12-04 09:11:34 +01:00
sd-daemon tree-wide: drop socket.h when socket-util.h is included 2019-11-04 00:30:32 +09:00
sd-device sd-device-enumerator: do not return error when a device is removed 2019-11-05 22:13:11 +01:00
sd-event sd-event: add pidfd support 2019-12-04 10:34:41 +01:00
sd-hwdb tree-wide: drop string.h when string-util.h or friends are included 2019-11-04 00:30:32 +09:00
sd-id128 tree-wide: drop missing.h 2019-10-31 17:57:03 +09:00
sd-login tree-wide: drop string.h when string-util.h or friends are included 2019-11-04 00:30:32 +09:00
sd-netlink sd-netlink: support NLMSGERR_ATTR_MSG 2019-11-30 16:13:51 +09:00
sd-network tree-wide: drop string.h when string-util.h or friends are included 2019-11-04 00:30:32 +09:00
sd-path tree-wide: drop missing.h 2019-10-31 17:57:03 +09:00
sd-resolve tree-wide: drop socket.h when socket-util.h is included 2019-11-04 00:30:32 +09:00
sd-utf8 tree-wide: drop empty comments 2018-06-29 11:00:30 +09:00
disable-mempool.c mempool: only enable mempool use when linked to libsystemd-shared.so 2018-10-11 11:10:37 +02:00
libsystemd.pc.in meson: define PROJECT_VERSION as the "bare" project version 2018-12-20 21:35:29 +01:00
libsystemd.sym sd-event: add pidfd support 2019-12-04 10:34:41 +01:00
meson.build sd-netlink: save dynamic general netlink message type 2019-10-15 01:57:19 +09:00