X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;ds=sidebyside;f=libi3%2Fipc_connect.c;h=69629daa6a657b6d98abcf58824935d0dc1264fa;hb=8629c2e208930414f542435509594df051be2009;hp=2c41fcc2d54b9144ead4b214aa6d9f2e1178555d;hpb=4f57d49318d6e50ac03c427026b2653804a08527;p=i3%2Fi3 diff --git a/libi3/ipc_connect.c b/libi3/ipc_connect.c index 2c41fcc2..69629daa 100644 --- a/libi3/ipc_connect.c +++ b/libi3/ipc_connect.c @@ -2,10 +2,7 @@ * vim:ts=4:sw=4:expandtab * * i3 - an improved dynamic tiling window manager - * - * © 2009-2011 Michael Stapelberg and contributors - * - * See file LICENSE for license information. + * © 2009-2013 Michael Stapelberg and contributors (see also: LICENSE) * */ #include @@ -14,6 +11,10 @@ #include #include #include +#include +#include + +#include "libi3.h" /* * Connects to the i3 IPC socket and returns the file descriptor for the @@ -25,11 +26,13 @@ int ipc_connect(const char *socket_path) { 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)); addr.sun_family = AF_LOCAL; strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path) - 1); - if (connect(sockfd, (const struct sockaddr*)&addr, sizeof(struct sockaddr_un)) < 0) + if (connect(sockfd, (const struct sockaddr *)&addr, sizeof(struct sockaddr_un)) < 0) err(EXIT_FAILURE, "Could not connect to i3"); return sockfd;