diff options
| author | S. Christoffer Eliesen <[email protected]> | 2015-10-16 10:55:54 +0200 | 
|---|---|---|
| committer | S. Christoffer Eliesen <[email protected]> | 2015-10-16 12:15:11 +0200 | 
| commit | ae93c6e6fe5649473116aa081c1acedac10f2be4 (patch) | |
| tree | a9e64a324a1880c09423ae301db9474e16c55dc0 | |
| parent | 219c4848a78811b8e2166cade1ed9897b5d337a4 (diff) | |
sway/ipc: Dynamically assign ipc_sockaddr.
| -rw-r--r-- | sway/ipc.c | 28 | 
1 files changed, 19 insertions, 9 deletions
| @@ -21,10 +21,7 @@  static int ipc_socket = -1;  static struct wlc_event_source *ipc_event_source =  NULL; -static struct sockaddr_un ipc_sockaddr = { -	.sun_family = AF_UNIX, -	.sun_path = "/tmp/sway-ipc.sock" -}; +static struct sockaddr_un *ipc_sockaddr = NULL;  static const char ipc_magic[] = {'i', '3', '-', 'i', 'p', 'c'}; @@ -35,6 +32,7 @@ struct ipc_client {  	enum ipc_command_type current_command;  }; +struct sockaddr_un *ipc_user_sockaddr(void);  int ipc_handle_connection(int fd, uint32_t mask, void *data);  int ipc_client_handle_readable(int client_fd, uint32_t mask, void *data);  void ipc_client_disconnect(struct ipc_client *client); @@ -49,12 +47,14 @@ void ipc_init(void) {  		sway_abort("Unable to create IPC socket");  	} +	ipc_sockaddr = ipc_user_sockaddr(); +  	if (getenv("SWAYSOCK") != NULL) { -		strncpy(ipc_sockaddr.sun_path, getenv("SWAYSOCK"), sizeof(ipc_sockaddr.sun_path)); +		strncpy(ipc_sockaddr->sun_path, getenv("SWAYSOCK"), sizeof(ipc_sockaddr->sun_path));  	} -	unlink(ipc_sockaddr.sun_path); -	if (bind(ipc_socket, (struct sockaddr *)&ipc_sockaddr, sizeof(ipc_sockaddr)) == -1) { +	unlink(ipc_sockaddr->sun_path); +	if (bind(ipc_socket, (struct sockaddr *)ipc_sockaddr, sizeof(*ipc_sockaddr)) == -1) {  		sway_abort("Unable to bind IPC socket");  	} @@ -63,7 +63,7 @@ void ipc_init(void) {  	}  	// Set i3 IPC socket path so that i3-msg works out of the box -	setenv("I3SOCK", ipc_sockaddr.sun_path, 1); +	setenv("I3SOCK", ipc_sockaddr->sun_path, 1);  	ipc_event_source = wlc_event_loop_add_fd(ipc_socket, WLC_EVENT_READABLE, ipc_handle_connection, NULL);  } @@ -73,7 +73,17 @@ void ipc_terminate(void) {  		wlc_event_source_remove(ipc_event_source);  	}  	close(ipc_socket); -	unlink(ipc_sockaddr.sun_path); +	unlink(ipc_sockaddr->sun_path); +} + +struct sockaddr_un *ipc_user_sockaddr(void) { +  struct sockaddr_un *ipc_sockaddr = malloc(sizeof(struct sockaddr_un)); +  assert(ipc_sockaddr != NULL); + +  ipc_sockaddr->sun_family = AF_UNIX; +  strcpy(ipc_sockaddr->sun_path, "/tmp/sway-ipc.sock"); + +  return ipc_sockaddr;  }  int ipc_handle_connection(int fd, uint32_t mask, void *data) { | 
