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.
This commit is contained in:
Lennart Poettering
2021-10-27 17:56:36 +02:00
parent c844f0a924
commit 1f6639eac7
+3
View 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;