Kaydet (Commit) 73a508f5 authored tarafından Tor Lillqvist's avatar Tor Lillqvist

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
üst 70f56860
......@@ -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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment