diff options
author | Riccardo Spagni <ric@spagni.net> | 2018-10-20 20:42:05 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2018-10-20 20:42:05 +0200 |
commit | dc6da786d3598d64e19735beb3f4a72d4899b99f (patch) | |
tree | 4db9967973508acdc31f46ecc5921bfd776767a9 /src/common/util.cpp | |
parent | Merge pull request #4627 (diff) | |
parent | spawn: close all file descriptors before execve (diff) | |
download | monero-dc6da786d3598d64e19735beb3f4a72d4899b99f.tar.xz |
Merge pull request #4630
e4ce26c7 spawn: close all file descriptors before execve (moneromooo-monero)
Diffstat (limited to 'src/common/util.cpp')
-rw-r--r-- | src/common/util.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/common/util.cpp b/src/common/util.cpp index 7d8c9aa99..f91230528 100644 --- a/src/common/util.cpp +++ b/src/common/util.cpp @@ -28,6 +28,7 @@ // // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers +#include <unistd.h> #include <cstdio> #ifdef __GLIBC__ @@ -967,4 +968,23 @@ std::string get_nix_version_display_string() } #endif + void closefrom(int fd) + { +#if defined __FreeBSD__ || defined __OpenBSD__ || defined __NetBSD__ || defined __DragonFly__ + ::closefrom(fd); +#else +#if defined __GLIBC__ + const int sc_open_max = sysconf(_SC_OPEN_MAX); + const int MAX_FDS = std::min(65536, sc_open_max); +#else + const int MAX_FDS = 65536; +#endif + while (fd < MAX_FDS) + { + close(fd); + ++fd; + } +#endif + } + } |