summaryrefslogtreecommitdiffstats
path: root/src/basic/fd-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-10-12 15:50:39 +0200
committerLennart Poettering <lennart@poettering.net>2021-10-27 17:56:36 +0200
commit1f6639eac7e44d55b6a859450ad0cc64b78c0889 (patch)
tree0cedbae9dec5341aedc0fcd5cb46dcf86a760632 /src/basic/fd-util.c
parentfd-util: always return 0 on success in close_all_fds() (diff)
downloadsystemd-1f6639eac7e44d55b6a859450ad0cc64b78c0889.tar.xz
systemd-1f6639eac7e44d55b6a859450ad0cc64b78c0889.zip
fd-util: close_all() check d_type
Tiny optimization: check dirent's d_type before trying to parse /proc/self/fd/ filenames, given we have that anyway.
Diffstat (limited to '')
-rw-r--r--src/basic/fd-util.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/basic/fd-util.c b/src/basic/fd-util.c
index b9df043aa7..70c036db17 100644
--- a/src/basic/fd-util.c
+++ b/src/basic/fd-util.c
@@ -353,6 +353,9 @@ int close_all_fds(const int except[], size_t n_except) {
FOREACH_DIRENT(de, d, return -errno) {
int fd = -1, q;
+ if (!IN_SET(de->d_type, DT_LNK, DT_UNKNOWN))
+ continue;
+
if (safe_atoi(de->d_name, &fd) < 0)
/* Let's better ignore this, just in case */
continue;