diff --git a/telldus-core/common/Socket_unix.cpp b/telldus-core/common/Socket_unix.cpp index 3f8a68b7..b810ba8c 100644 --- a/telldus-core/common/Socket_unix.cpp +++ b/telldus-core/common/Socket_unix.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -17,6 +18,9 @@ #include "common/Strings.h" #define BUFSIZE 512 +#if defined(_MACOSX) && !defined(SOCK_CLOEXEC) + #define SOCK_CLOEXEC 0 +#endif namespace TelldusCore { @@ -60,6 +64,10 @@ void Socket::connect(const std::wstring &server) { if ((d->socket = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0)) == -1) { return; } +#if defined(_MACOSX) + int op = fcntl(d->socket, F_GETFD); + fcntl(d->socket, op | FD_CLOEXEC); // OS X doesn't support SOCK_CLOEXEC yet +#endif std::string name = "/tmp/" + std::string(server.begin(), server.end()); remote.sun_family = AF_UNIX; snprintf(remote.sun_path, sizeof(remote.sun_path), "%s", name.c_str()); diff --git a/telldus-core/service/ConnectionListener_unix.cpp b/telldus-core/service/ConnectionListener_unix.cpp index adef9cb8..a4af59a5 100644 --- a/telldus-core/service/ConnectionListener_unix.cpp +++ b/telldus-core/service/ConnectionListener_unix.cpp @@ -10,12 +10,17 @@ #include #include #include +#include #include #include #include "service/ConnectionListener.h" #include "common/Socket.h" +#if defined(_MACOSX) && !defined(SOCK_CLOEXEC) + #define SOCK_CLOEXEC 0 +#endif + class ConnectionListener::PrivateData { public: TelldusCore::EventRef waitEvent; @@ -51,6 +56,10 @@ void ConnectionListener::run() { if (serverSocket < 0) { return; } +#if defined(_MACOSX) + int op = fcntl(serverSocket, F_GETFD); + fcntl(serverSocket, op | FD_CLOEXEC); // OS X doesn't support SOCK_CLOEXEC yet +#endif name.sun_family = AF_LOCAL; memset(name.sun_path, '\0', sizeof(name.sun_path)); strncpy(name.sun_path, d->name.c_str(), sizeof(name.sun_path));