From: Lennart Poettering Date: Tue, 12 Oct 2021 13:50:39 +0000 (+0200) Subject: fd-util: close_all() check d_type X-Git-Tag: v250-rc1~399^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1f6639eac7e44d55b6a859450ad0cc64b78c0889;p=thirdparty%2Fsystemd.git 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. --- diff --git a/src/basic/fd-util.c b/src/basic/fd-util.c index b9df043aa7d..70c036db173 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;