From f688c03961b26e50f51e2cfb2d1efc68c6ec7079 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 29 Mar 2017 12:03:29 +0200 Subject: close_files: do not close the fd to the dir whilst reading MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/libmdsserver/macros.h | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/libmdsserver/macros.h b/src/libmdsserver/macros.h index f5c6808..14ce80b 100644 --- a/src/libmdsserver/macros.h +++ b/src/libmdsserver/macros.h @@ -444,15 +444,18 @@ if (dir == NULL) \ perror(*argv); /* Well, that is just unfortunate, but we cannot really do anything. */ \ else \ - while ((file = readdir(dir)) != NULL) \ - if (strcmp(file->d_name, ".") && strcmp(file->d_name, "..")) \ - { \ - int fd = atoi(file->d_name); \ - if (condition) \ - xclose(fd); \ - } \ - \ - closedir(dir); \ + { \ + int dfd = dirfd(dir); \ + while ((file = readdir(dir)) != NULL) \ + if (strcmp(file->d_name, ".") && strcmp(file->d_name, "..")) \ + { \ + int fd = atoi(file->d_name); \ + if (fd != dfd) \ + if (condition) \ + xclose(fd); \ + } \ + closedir(dir); \ + } \ } \ while (0) -- cgit v1.2.3-70-g09d2