Systemd/src/systemd
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-common.h Use c99 static array size declarations in exported functions too 2019-01-04 12:37:25 +01:00
meson.build dhcp: remove struct sd_dhcp_raw_option 2019-11-18 23:37:22 +09:00
sd-bus-protocol.h tree-wide: drop empty lines in the begining of comments 2018-06-29 10:50:23 +09:00
sd-bus-vtable.h codespell: fix spelling errors 2019-04-29 16:47:18 +02:00
sd-bus.h sd-bus: add define for the maximum name length 2019-04-11 14:07:22 +02:00
sd-daemon.h sd-daemon: don't mention strerror_safe() in examples in public headers 2019-07-23 15:56:41 +02:00
sd-device.h sd-device: drop priority and description from sd_device_monitor_attach_event() and sd_device_monitor_start() 2018-11-10 22:53:00 +09:00
sd-dhcp-client.h dhcp: remove struct sd_dhcp_raw_option 2019-11-18 23:37:22 +09:00
sd-dhcp-lease.h network: DHCP server Add support to transmit SIP server 2019-09-20 21:22:23 +09:00
sd-dhcp-option.h dhcp: remove struct sd_dhcp_raw_option 2019-11-18 23:37:22 +09:00
sd-dhcp-server.h dhcp: remove struct sd_dhcp_raw_option 2019-11-18 23:37:22 +09:00
sd-dhcp6-client.h network: DHCPv6 client add support for prefix delegation hint 2019-10-01 23:52:40 +09:00
sd-dhcp6-lease.h tree-wide: drop copyright headers from frequent contributors 2018-06-20 11:58:53 +02:00
sd-event.h sd-event: add pidfd support 2019-12-04 10:34:41 +01:00
sd-hwdb.h tree-wide: drop copyright headers from frequent contributors 2018-06-20 11:58:53 +02:00
sd-id128.h tree-wide: drop duplicated blank lines 2019-07-15 18:41:27 +02:00
sd-ipv4acd.h tree-wide: drop copyright headers from frequent contributors 2018-06-20 11:58:53 +02:00
sd-ipv4ll.h tree-wide: use proper unicode © instead of (C) where we can 2018-06-14 10:20:20 +02:00
sd-journal.h tree-wide: drop empty lines in the begining of comments 2018-06-29 10:50:23 +09:00
sd-lldp.h Merge pull request #11241 from bengal/lldp-802-3-subtypes 2019-01-06 18:15:51 +01:00
sd-login.h tree-wide: drop empty lines in the begining of comments 2018-06-29 10:50:23 +09:00
sd-messages.h core: ExecCondition= for services 2019-07-17 11:35:02 +02:00
sd-ndisc.h ndisc: improve debug log message 2018-11-06 20:15:09 +09:00
sd-netlink.h network: introduce TrafficControl 2019-10-30 09:33:51 +09:00
sd-network.h network: DHCP server Add support to transmit SIP server 2019-09-20 21:22:23 +09:00
sd-path.h sd-path: drop redundant "= 0ULL" assignment in enum 2018-11-09 17:19:45 +01:00
sd-radv.h network: Add support to advertie ipv6 route 2019-09-17 12:09:59 +02:00
sd-resolve.h tree-wide: add whitespace between type and variable name 2018-12-04 09:29:54 +01:00
sd-utf8.h tree-wide: drop empty lines in the begining of comments 2018-06-29 10:50:23 +09:00