aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-05-06 00:15:02 +0200
committerMattias Andrée <maandree@operamail.com>2014-05-06 00:15:02 +0200
commite16516fefca6ba22bf4d848b4207b4d5b8d1eef9 (patch)
treed68a59a01694997834fd0f56448795dbbde2ee3b
parentuse more macros (diff)
downloadmds-e16516fefca6ba22bf4d848b4207b4d5b8d1eef9.tar.gz
mds-e16516fefca6ba22bf4d848b4207b4d5b8d1eef9.tar.bz2
mds-e16516fefca6ba22bf4d848b4207b4d5b8d1eef9.tar.xz
close untracked files if unmarshal from re-exec fails
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--src/config.h8
-rw-r--r--src/mds-server.c26
2 files changed, 32 insertions, 2 deletions
diff --git a/src/config.h b/src/config.h
index 09c3210..174fe30 100644
--- a/src/config.h
+++ b/src/config.h
@@ -126,6 +126,14 @@
/**
+ * The path to the directory with symlinks to each file that is open
+ */
+#ifndef SELF_FD
+#define SELF_FD "/proc/self/fd"
+#endif
+
+
+/**
* Pattern for the names of shared object to which states are marshalled
*/
#ifndef SHM_PATH_PATTERN
diff --git a/src/mds-server.c b/src/mds-server.c
index 826e0d2..cb2bfc2 100644
--- a/src/mds-server.c
+++ b/src/mds-server.c
@@ -39,6 +39,8 @@
#include <sys/mman.h>
#include <fcntl.h>
#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h>
@@ -283,11 +285,31 @@ int main(int argc_, char** argv_)
}
if (r < 0)
{
- /* TODO: close all sockets we do not know what they are. */
+ /* Close all files (hopefully sockets) we do not know what they are. */
+ DIR* dir = opendir(SELF_FD);
+ struct dirent* file;
+
+ if (dir == NULL)
+ {
+ perror(*argv); /* Well, that is just unfortunate, but we cannot really do anything. */
+ closedir(dir);
+ goto unmarshal_double_fail;
+ }
+
+ while ((file = readdir(dir)) != NULL)
+ if (strcmp(file->d_name, ".") && strcmp(file->d_name, ".."))
+ {
+ int fd = atoi(file->d_name);
+ if ((fd > 2) && (fd != socket_fd) &&
+ (fd_table_contains_key(&client_map, fd) == 0))
+ close(fd);
+ }
+
+ closedir(dir);
}
}
-
+ unmarshal_double_fail:
/* Accepting incoming connections. */
while (running && (reexecing == 0))
{