Signed-off-by: Uli Schlachter <psyc...@znc.in>
---
 common/socket.c |   13 +++++++++++++
 common/socket.h |    1 +
 2 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/common/socket.c b/common/socket.c
index 80e1438..a8d148f 100644
--- a/common/socket.c
+++ b/common/socket.c
@@ -25,6 +25,7 @@
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <unistd.h>
+#include <fcntl.h>

 #include <xcb/xcb.h>

@@ -123,4 +124,16 @@ socket_getclient(void)

     return csfd;
 }
+
+/** Mark a socket as close-on-exec
+ */
+void socket_close_on_exec(int fd)
+{
+    int flags = fcntl(fd, F_GETFD, 0);
+    if (flags < 0)
+        // Ignore errors, nothing we can do about them
+        return;
+    fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
+}
+
 // vim:
filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
diff --git a/common/socket.h b/common/socket.h
index d46ed28..33a6c69 100644
--- a/common/socket.h
+++ b/common/socket.h
@@ -30,6 +30,7 @@ typedef enum

 struct sockaddr_un *socket_open(const int, const socket_mode_t);
 int socket_getclient(void);
+void socket_close_on_exec(int);

 #endif
 // vim:
filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
-- 
1.6.2.1

-- 
"Do you know that books smell like nutmeg or some spice from a foreign land?"
                                                  -- Faber in Fahrenheit 451

-- 
To unsubscribe, send mail to awesome-devel-unsubscr...@naquadah.org.

Reply via email to