diff options
author | Tor Lillqvist <tml@iki.fi> | 2013-07-29 16:50:22 +0300 |
---|---|---|
committer | Tor Lillqvist <tml@iki.fi> | 2013-07-29 18:25:51 +0300 |
commit | 73a508f574995f09559c003cb810e5d2ff2691c2 (patch) | |
tree | a6369ce51838aa6377c41c0d0dfec7513ffb1097 /sal | |
parent | 70f56860e4a9ee2a25abf64142a7f0ed4d446bfb (diff) |
Avoid crash on OS X: guarded fd exception
On OS X, a file descriptor that shows up as being of type "KQUEUE" in
lsof output is apparently created behind the scenes when starting a
thread. (Related to BSD kernel event queues: see man kqueue.) When we
re-exec ourselves on OS X, and then close all file descriptors >= 3,
closing such a KQUEUE fd causes a crash.
Guard against this by closing only regular files.
Change-Id: I5011bfbaed156b04248b6bddb2a1a58624bee3d4
5011bfbaed156b04248b6bddb2a1a58624bee3d4
Diffstat (limited to 'sal')
-rw-r--r-- | sal/osl/unx/salinit.cxx | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/sal/osl/unx/salinit.cxx b/sal/osl/unx/salinit.cxx index c71c6a3d67ac..10553b6cf5cf 100644 --- a/sal/osl/unx/salinit.cxx +++ b/sal/osl/unx/salinit.cxx @@ -23,6 +23,7 @@ #include <cassert> #include <limits> #include <unistd.h> +#include <sys/stat.h> #endif #include "osl/process.h" @@ -64,7 +65,9 @@ void sal_detail_initialize(int argc, char ** argv) { } assert(openMax >= 0 && openMax <= std::numeric_limits< int >::max()); for (int fd = 3; fd < openMax; ++fd) { - close(fd); + struct stat s; + if (fstat(fd, &s) != -1 && S_ISREG(s.st_mode)) + close(fd); } #endif sal_initGlobalTimer(); |