New system calls: pidfd_open() and close_range()
New system calls: pidfd_open() and close_range()
Posted May 23, 2019 15:02 UTC (Thu) by mezcalero (subscriber, #45103)Parent article: New system calls: pidfd_open() and close_range()
I must say, for all purposes I have in the codebases I care for (systemd…) the range thing is a bit weird though, usually we want to close everything but a few arbitrary fds, and then rearrange those fds to specific positions. But for that close_range() is not particularly useful, as it requires you to sort your list of fds to keep open first and then find all ranges between them. This means behaviour of closing everything is O(n*log(n)) (for the worst case where the fds to keep open are fully distributed over the entire range), for n being the number of fds to keep open. This is only marginally better than enumerating /proc/self/fd/ and closing everything found there, which is O(m) for m being the number of fds previously open. Marginally better since usually n ≪ m.
I personally would much rather prefer a prototype like:
int close_except(const int *fds, size_t n_fds);
i.e. just specify the fds you want to keep open explicitly, regardless of order, trivially easily...
And I think not only systemd would benefit from such a close_except() call, but also everything else that invokes something with fds set up in a special way, for example popen() and friends.
Lennart