diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-05-06 00:22:25 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-05-06 00:22:25 +0200 |
commit | 8ef7900438ed190301a2d9585ad81aac5987ee2a (patch) | |
tree | 1a352bdc81cd4c84a9d25a89b42e0286ecebc69e /src/mds-server.c | |
parent | close untracked files if unmarshal from re-exec fails (diff) | |
download | mds-8ef7900438ed190301a2d9585ad81aac5987ee2a.tar.gz mds-8ef7900438ed190301a2d9585ad81aac5987ee2a.tar.bz2 mds-8ef7900438ed190301a2d9585ad81aac5987ee2a.tar.xz |
close files before running initrc
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/mds-server.c')
-rw-r--r-- | src/mds-server.c | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/src/mds-server.c b/src/mds-server.c index cb2bfc2..1349ee3 100644 --- a/src/mds-server.c +++ b/src/mds-server.c @@ -214,6 +214,25 @@ int main(int argc_, char** argv_) } if (pid == 0) /* Child process exec:s, the parent continues without waiting for it. */ { + /* Close all files except stdin, stdout and stderr. */ + DIR* dir = opendir(SELF_FD); + struct dirent* file; + + 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 (fd > 2) + close(fd); + } + + closedir(dir); + close(socket_fd); /* Perhaps it is stdin, stdout or stderr. */ + + /* Run initrc */ run_initrc(unparsed_args); return 1; } @@ -290,26 +309,21 @@ int main(int argc_, char** argv_) 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); - } + 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 ((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)) { |