diff options
author | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2021-03-10 12:26:32 -0300 |
---|---|---|
committer | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2021-07-08 14:08:14 -0300 |
commit | 607449506f197cc9514408908f41f22537a47a8c (patch) | |
tree | 9d4304b8a8a1ccdef78a305433d845bcd3e08ae6 /include | |
parent | 286286283e9bdc7ef894306e2dbcf4c115b97ba2 (diff) | |
download | glibc-607449506f197cc9514408908f41f22537a47a8c.tar.gz glibc-607449506f197cc9514408908f41f22537a47a8c.tar.xz glibc-607449506f197cc9514408908f41f22537a47a8c.zip |
io: Add closefrom [BZ #10353]
The function closes all open file descriptors greater than or equal to input argument. Negative values are clamped to 0, i.e, it will close all file descriptors. As indicated by the bug report, this is a common symbol provided by different systems (Solaris, OpenBSD, NetBSD, FreeBSD) and, although its has inherent issues with not taking in consideration internal libc file descriptors (such as syslog), this is also a common feature used in multiple projects [1][2][3][4][5]. The Linux fallback implementation iterates over /proc and close all file descriptors sequentially. Although it was raised the questioning whether getdents on /proc/self/fd might return disjointed entries when file descriptor are closed; it does not seems the case on my testing on multiple kernel (v4.18, v5.4, v5.9) and the same strategy is used on different projects [1][2][3][5]. Also, the interface is set a fail-safe meaning that a failure in the fallback results in a process abort. Checked on x86_64-linux-gnu and i686-linux-gnu on kernel 5.11 and 4.15. [1] https://github.com/systemd/systemd/blob/5238e9575906297608ff802a27e2ff9effa3b338/src/basic/fd-util.c#L217 [2] https://github.com/lxc/lxc/blob/ddf4b77e11a4d08f09b7b9cd13e593f8c047edc5/src/lxc/start.c#L236 [3] https://github.com/python/cpython/blob/9e4f2f3a6b8ee995c365e86d976937c141d867f8/Modules/_posixsubprocess.c#L220 [4] https://github.com/rust-lang/rust/blob/5f47c0613ed4eb46fca3633c1297364c09e5e451/src/libstd/sys/unix/process2.rs#L303-L308 [5] https://github.com/openjdk/jdk/blob/master/src/java.base/unix/native/libjava/childproc.c#L82
Diffstat (limited to 'include')
-rw-r--r-- | include/unistd.h | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/include/unistd.h b/include/unistd.h index 691405a945..114a43128e 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -158,6 +158,7 @@ extern int __brk (void *__addr) attribute_hidden; extern int __close (int __fd); libc_hidden_proto (__close) extern int __libc_close (int __fd); +extern _Bool __closefrom_fallback (int __lowfd) attribute_hidden; extern ssize_t __read (int __fd, void *__buf, size_t __nbytes); libc_hidden_proto (__read) extern ssize_t __write (int __fd, const void *__buf, size_t __n); |