So here's the thing. One library we use (libselinux) is opening fds behind our back when we initialize it and keeps it open. On the other hand we want to automatically pick up all fds passed in to us, so that we can distribute them to our services and close the rest. We pick them up very early in our code, to ensure that we don't get confused by open fds at that point. Except that libselinux insists on being initialized even earlier. So suddenly we might take possession of libselinux' fds, and then close them later when we decide no service wants them. Then during shutdown we close down selinux and selinux closes its fds, but since already closed long ago this ight close our fds instead. Hilarity ensues. I wish low-level software wouldn't do such things behind our back, but well, let's make the best of it. This changes the fd pick-up logic to only pick up fds that have O_CLOEXEC unset. O_CLOEXEC must be unset for any fds passed in to us over execve() after all. And for all our own fds we should set O_CLOEXEC since we generally don't want to litter fd tables for execve(). Also, libselinux thankfully appears to set O_CLOEXEC correctly on its fds, hence the filter works. Fixes: #27491
System and Service Manager
Details
Most documentation is available on systemd's web site.
Assorted, older, general information about systemd can be found in the systemd Wiki.
Information about build requirements is provided in the README file.
Consult our NEWS file for information about what's new in the most recent systemd versions.
Please see the Code Map for information about this repository's layout and content.
Please see the Hacking guide for information on how to hack on systemd and test your modifications.
Please see our Contribution Guidelines for more information about filing GitHub Issues and posting GitHub Pull Requests.
When preparing patches for systemd, please follow our Coding Style Guidelines.
If you are looking for support, please contact our mailing list or join our IRC channel.
Stable branches with backported patches are available in the stable repo.
