mirror of
				https://github.com/swaywm/sway.git
				synced 2025-11-03 09:01:43 -05:00 
			
		
		
		
	properly exit sway
- wlc_terminate() instead of exit(0) - unlink IPC socket
This commit is contained in:
		
							parent
							
								
									bfbadadf70
								
							
						
					
					
						commit
						91c0877264
					
				
					 4 changed files with 22 additions and 10 deletions
				
			
		| 
						 | 
					@ -12,6 +12,7 @@ enum ipc_command_type {
 | 
				
			||||||
	IPC_GET_VERSION    = 7,
 | 
						IPC_GET_VERSION    = 7,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void init_ipc(void);
 | 
					void ipc_init(void);
 | 
				
			||||||
 | 
					void ipc_shutdown(void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -186,7 +186,7 @@ static bool cmd_exit(struct sway_config *config, int argc, char **argv) {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	// Close all views
 | 
						// Close all views
 | 
				
			||||||
	container_map(&root_container, kill_views, NULL);
 | 
						container_map(&root_container, kill_views, NULL);
 | 
				
			||||||
	exit(0);
 | 
						wlc_terminate();
 | 
				
			||||||
	return true;
 | 
						return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										23
									
								
								sway/ipc.c
									
										
									
									
									
								
							
							
						
						
									
										23
									
								
								sway/ipc.c
									
										
									
									
									
								
							| 
						 | 
					@ -16,6 +16,11 @@
 | 
				
			||||||
#include "commands.h"
 | 
					#include "commands.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int ipc_socket = -1;
 | 
					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 const char ipc_magic[] = {'i', '3', '-', 'i', 'p', 'c'};
 | 
					static const char ipc_magic[] = {'i', '3', '-', 'i', 'p', 'c'};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -32,17 +37,12 @@ void ipc_client_disconnect(struct ipc_client *client);
 | 
				
			||||||
void ipc_client_handle_command(struct ipc_client *client);
 | 
					void ipc_client_handle_command(struct ipc_client *client);
 | 
				
			||||||
bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t payload_length);
 | 
					bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t payload_length);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void init_ipc() {
 | 
					void ipc_init(void) {
 | 
				
			||||||
	ipc_socket = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
 | 
						ipc_socket = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
 | 
				
			||||||
	if (ipc_socket == -1) {
 | 
						if (ipc_socket == -1) {
 | 
				
			||||||
		sway_abort("Unable to create IPC socket");
 | 
							sway_abort("Unable to create IPC socket");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct sockaddr_un ipc_sockaddr = {
 | 
					 | 
				
			||||||
		.sun_family = AF_UNIX,
 | 
					 | 
				
			||||||
		.sun_path = "/tmp/sway-ipc.sock"
 | 
					 | 
				
			||||||
	};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (getenv("SWAYSOCK") != NULL) {
 | 
						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));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -56,10 +56,19 @@ void init_ipc() {
 | 
				
			||||||
		sway_abort("Unable to listen on IPC socket");
 | 
							sway_abort("Unable to listen on IPC socket");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	wlc_event_loop_add_fd(ipc_socket, WLC_EVENT_READABLE, ipc_handle_connection, NULL);
 | 
						ipc_event_source = wlc_event_loop_add_fd(ipc_socket, WLC_EVENT_READABLE, ipc_handle_connection, NULL);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void ipc_shutdown(void) {
 | 
				
			||||||
 | 
						if (ipc_event_source) {
 | 
				
			||||||
 | 
							wlc_event_source_remove(ipc_event_source);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						close(ipc_socket);
 | 
				
			||||||
 | 
						unlink(ipc_sockaddr.sun_path);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int ipc_handle_connection(int fd, uint32_t mask, void *data) {
 | 
					int ipc_handle_connection(int fd, uint32_t mask, void *data) {
 | 
				
			||||||
 | 
						(void) fd; (void) data;
 | 
				
			||||||
	sway_log(L_DEBUG, "Event on IPC listening socket");
 | 
						sway_log(L_DEBUG, "Event on IPC listening socket");
 | 
				
			||||||
	assert(mask == WLC_EVENT_READABLE);
 | 
						assert(mask == WLC_EVENT_READABLE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -100,13 +100,15 @@ int main(int argc, char **argv) {
 | 
				
			||||||
		free(config_path);
 | 
							free(config_path);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	init_ipc();
 | 
						ipc_init();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	wlc_run();
 | 
						wlc_run();
 | 
				
			||||||
	if (devnull) {
 | 
						if (devnull) {
 | 
				
			||||||
		fclose(devnull);
 | 
							fclose(devnull);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ipc_shutdown();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue