aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2017-03-29 12:03:29 +0200
committerMattias Andrée <maandree@kth.se>2017-03-29 12:03:29 +0200
commitf688c03961b26e50f51e2cfb2d1efc68c6ec7079 (patch)
treefc304196aed9805d27ef605bd67359e3bb8107cb
parentUpdate TODO (diff)
downloadmds-f688c03961b26e50f51e2cfb2d1efc68c6ec7079.tar.gz
mds-f688c03961b26e50f51e2cfb2d1efc68c6ec7079.tar.bz2
mds-f688c03961b26e50f51e2cfb2d1efc68c6ec7079.tar.xz
close_files: do not close the fd to the dir whilst reading
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r--src/libmdsserver/macros.h21
1 files 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)