diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2015-03-07 10:37:52 -0800 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2020-01-09 13:52:20 -0800 |
commit | 22f0905b4ac1af125d382440716b97f4e6142676 (patch) | |
tree | e9a63b7a74edc81c8de8e4e119d57baf2e1a421d /src/3rdparty/forkfd/forkfd.c | |
parent | e8199a5c4d8c7218178db809bbfc0464f49714b1 (diff) |
forkfd: Implement forkfd in terms of Linux 5.2's CLONE_PIDFD
Linux 5.2 added the CLONE_PIDFD flag to the clone(2) system call. Linux
5.3 also added the clone3(2) system call, which allows both CLONE_PIDFD
and CLONE_PARENT_SETTID, which we could use but don't really need.
Unfortunately, 5.2 missed one crucial and one convenient change. Without
the P_PIDFD support in waitid(2), we would need to either remember the
PID of the child process or obtain it from /proc. But without support
for polling on pidfds, we can't find out when the child process
exited. Support for the latter was added in 5.3, which would be
sufficient for us, but it's not easy to detect it at runtime. The
support is also being backported to Android's 4.9 kernel[1], so we can't
do version checks, only functionality.
This commit relies on waitid(2) support, which was the last to be added
and is fortunately the easiest to detect. If it's present, we assume the
whole series is present and use pidfds.
[1] https://android-review.googlesource.com/q/topic:%22pidfd+polling+support+4.9+backport%22
See-Also: https://lkml.org/lkml/2015/3/12/1044 (original idea)
See-Also: https://lkml.org/lkml/2019/4/19/441 (CLONE_PIDFD)
See-Also: https://lkml.org/lkml/2019/4/25/884 (poll(2) support)
See-Also: https://lkml.org/lkml/2019/7/27/334 (P_PIDFD)
Change-Id: Ia0aac2f09e9245339951ffff13c94b3aa13d8b63
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/3rdparty/forkfd/forkfd.c')
-rw-r--r-- | src/3rdparty/forkfd/forkfd.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/3rdparty/forkfd/forkfd.c b/src/3rdparty/forkfd/forkfd.c index e4f3bd85de..2ae85d6f37 100644 --- a/src/3rdparty/forkfd/forkfd.c +++ b/src/3rdparty/forkfd/forkfd.c @@ -822,6 +822,8 @@ int forkfd_close(int ffd) #if defined(__FreeBSD__) && __FreeBSD__ >= 9 # include "forkfd_freebsd.c" +#elif defined(__linux__) +# include "forkfd_linux.c" #else int system_has_forkfd() { |