From 9b33efc8e896f855f6ba1b7c0c8da10427a3f00e Mon Sep 17 00:00:00 2001 From: Jacob Rosenthal Date: Fri, 10 Apr 2015 11:41:12 -0700 Subject: [PATCH] set cloexec after open, possible fix for #468 --- src/serialport_unix.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/serialport_unix.cpp b/src/serialport_unix.cpp index da22b22..aaa28ec 100644 --- a/src/serialport_unix.cpp +++ b/src/serialport_unix.cpp @@ -147,7 +147,7 @@ void EIO_Open(uv_work_t* req) { } - int flags = (O_RDWR | O_NOCTTY | O_NONBLOCK | O_CLOEXEC | O_SYNC); + int flags = (O_RDWR | O_NOCTTY | O_NONBLOCK | O_SYNC); int fd = open(data->path, flags); if (fd == -1) { @@ -155,6 +155,12 @@ void EIO_Open(uv_work_t* req) { return; } + //Snow Leopard doesn't have O_CLOEXEC + int cloexec = fcntl(fd, F_SETFD, FD_CLOEXEC); + if (cloexec == -1) { + snprintf(data->errorString, sizeof(data->errorString), "Cannot open %s", data->path); + return; + } // struct sigaction saio; // saio.sa_handler = sigio_handler;