$OpenBSD: patch-libi3_ipc_connect_c,v 1.1 2013/05/17 10:21:42 dcoppa Exp $

commit fa1b436fca50077b7d3446e5e49e48f50d88a5cb
Author: Michael Stapelberg <michael@stapelberg.de>
Date:   Sun Apr 14 10:12:21 2013 +0200

Bugfix: mark IPC fd CLOEXEC

Without this fix, children of i3bar would inherit the file descriptor
of the IPC connection to i3. Therefore, even if i3bar exits with
SIGSEGV, the connection to i3 stays open. Because nobody actually
reads any messages by i3, the buffer will fill up and i3 can't
deliver any more messages, and thus busy-loops at that point.

--- libi3/ipc_connect.c.orig	Mon Mar 18 22:43:36 2013
+++ libi3/ipc_connect.c	Fri May 17 11:13:18 2013
@@ -11,6 +11,8 @@
 #include <string.h>
 #include <err.h>
 #include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
 
 #include "libi3.h"
 
@@ -23,6 +25,8 @@ int ipc_connect(const char *socket_path) {
     int sockfd = socket(AF_LOCAL, SOCK_STREAM, 0);
     if (sockfd == -1)
         err(EXIT_FAILURE, "Could not create socket");
+
+    (void)fcntl(sockfd, F_SETFD, FD_CLOEXEC);
 
     struct sockaddr_un addr;
     memset(&addr, 0, sizeof(struct sockaddr_un));
