summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Lillqvist <tml@iki.fi>2013-07-29 16:50:22 +0300
committerFridrich Strba <fridrich@documentfoundation.org>2013-07-30 10:00:38 +0000
commit3ec3ef25217bd6f47c80630387dca4b05e402b8d (patch)
tree81b1bc5600ba01cb62412d999bc05d090e9e2f87
parent44ad2d98a5e9dbf7f6429caf920cdcf3931a62c4 (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>
-rw-r--r--sal/osl/unx/salinit.cxx5
1 files changed, 4 insertions, 1 deletions
diff --git a/sal/osl/unx/salinit.cxx b/sal/osl/unx/salinit.cxx
index 327ca0e0d0c5..99cde2ddee21 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"
@@ -61,7 +62,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
#if HAVE_SYSLOG_H