2009-09-20 15:44:14 +02:00
|
|
|
/*
|
|
|
|
* vim:ts=8:expandtab
|
|
|
|
*
|
|
|
|
* i3 - an improved dynamic tiling window manager
|
|
|
|
*
|
|
|
|
* © 2009 Michael Stapelberg and contributors
|
|
|
|
*
|
|
|
|
* See file LICENSE for license information.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/un.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <err.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Connects to the i3 IPC socket and returns the file descriptor for the
|
|
|
|
* socket. die()s if anything goes wrong.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
int connect_ipc(char *socket_path) {
|
|
|
|
int sockfd = socket(AF_LOCAL, SOCK_STREAM, 0);
|
|
|
|
if (sockfd == -1)
|
|
|
|
err(EXIT_FAILURE, "Could not create socket");
|
|
|
|
|
|
|
|
struct sockaddr_un addr;
|
|
|
|
memset(&addr, 0, sizeof(struct sockaddr_un));
|
|
|
|
addr.sun_family = AF_LOCAL;
|
2010-07-15 14:38:29 +02:00
|
|
|
strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path) - 1);
|
2009-09-20 15:44:14 +02:00
|
|
|
if (connect(sockfd, (const struct sockaddr*)&addr, sizeof(struct sockaddr_un)) < 0)
|
|
|
|
err(EXIT_FAILURE, "Could not connect to i3");
|
|
|
|
|
|
|
|
return sockfd;
|
|
|
|
}
|