![]() |
|
Message-ID: <35c9d22e-7c52-4dfe-b58e-a22c2b4a933f@gmail.com> Date: Fri, 12 Sep 2025 21:40:22 -0400 From: Demi Marie Obenour <demiobenour@...il.com> To: musl@...ts.openwall.com Subject: closefrom and close_range wrappers Would it make sense for musl to provide close_range and closefrom? The main uses of them are to close unwanted FDs after a fork and before exec. close_range() can also be used to mark them close-on-exec instead. The main advantage of closefrom() is that it is portable to more systems. Closing file descriptors one doesn't own is not an issue because the code that does own these FDs will never get a chance to run. In particular, calling any stdio functions that use anything but stdin, stdout, and stderr would be UB. stdin, stdout, and stderr use FD 0, 1, and 2, respectively, and those are almost always left open. Yes, this is all a consequence of fork()/exec() being an extremely poor API, but I don't know of a better solution. There are third-party libraries (including glib and wlroots) that expect one to either use an API like this or emulate it by scanning /proc/self/fd (yuck). Yes, these libraries should be atomically setting O_CLOEXEC, but their authors disagree and maintaining downstream forks is not practical. -- Sincerely, Demi Marie Obenour (she/her/hers) Download attachment "OpenPGP_0xB288B55FFF9C22C1.asc" of type "application/pgp-keys" (7141 bytes) Download attachment "OpenPGP_signature.asc" of type "application/pgp-signature" (834 bytes)
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.