2 * vim:ts=4:sw=4:expandtab
4 * i3 - an improved dynamic tiling window manager
5 * © 2009 Michael Stapelberg and contributors (see also: LICENSE)
9 #include <sys/socket.h>
20 * Connects to the i3 IPC socket and returns the file descriptor for the
21 * socket. die()s if anything goes wrong.
24 int ipc_connect(const char *socket_path) {
25 int sockfd = socket(AF_LOCAL, SOCK_STREAM, 0);
27 err(EXIT_FAILURE, "Could not create socket");
29 (void)fcntl(sockfd, F_SETFD, FD_CLOEXEC);
31 struct sockaddr_un addr;
32 memset(&addr, 0, sizeof(struct sockaddr_un));
33 addr.sun_family = AF_LOCAL;
34 strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path) - 1);
35 if (connect(sockfd, (const struct sockaddr *)&addr, sizeof(struct sockaddr_un)) < 0)
36 err(EXIT_FAILURE, "Could not connect to i3");