From 1f6639eac7e44d55b6a859450ad0cc64b78c0889 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 12 Oct 2021 15:50:39 +0200 Subject: [PATCH] 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. --- src/basic/fd-util.c | 3 +++ 1 file changed, 3 insertions(+) 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;