]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fd-util: close_all() check d_type
authorLennart Poettering <lennart@poettering.net>
Tue, 12 Oct 2021 13:50:39 +0000 (15:50 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 27 Oct 2021 15:56:36 +0000 (17:56 +0200)
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

index b9df043aa7d5dc50e25c8859e274f221710a5723..70c036db173ec23b14eb2ed58eb793df170ba501 100644 (file)
@@ -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;