diff options
author | Tor Lillqvist <tml@iki.fi> | 2013-07-29 16:50:22 +0300 |
---|---|---|
committer | Fridrich Strba <fridrich@documentfoundation.org> | 2013-08-17 14:52:22 +0000 |
commit | 8f3ce7b0a9688ebb9afee4b56de36feebd6cf091 (patch) | |
tree | 1905f35b08a50acc63bfd11108c0f1399b275ab6 /sal | |
parent | 218728583950aed00be955b5ccdebec69986cff2 (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.
(cherry picked from commit 73a508f574995f09559c003cb810e5d2ff2691c2)
Change-Id: I5011bfbaed156b04248b6bddb2a1a58624bee3d4
Reviewed-on: https://gerrit.libreoffice.org/5173
Reviewed-by: Fridrich Strba <fridrich@documentfoundation.org>
Tested-by: Fridrich Strba <fridrich@documentfoundation.org>
Reviewed-on: https://gerrit.libreoffice.org/5470
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 d880258f387e..93c7e9d8c877 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" @@ -54,7 +55,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 |