mirror of
				https://github.com/swaywm/sway.git
				synced 2025-11-03 09:01:43 -05:00 
			
		
		
		
	Handle SIGTERM sent to sway
This makes sway handle and gracefully shut down everything when receiving a SIGTERM. Fix #416
This commit is contained in:
		
							parent
							
								
									b18f004210
								
							
						
					
					
						commit
						16b8c2e915
					
				
					 4 changed files with 24 additions and 7 deletions
				
			
		| 
						 | 
					@ -260,4 +260,9 @@ void add_gaps(swayc_t *view, void *amount);
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
void update_visibility(swayc_t *container);
 | 
					void update_visibility(swayc_t *container);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Close all child views of container
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					void close_views(swayc_t *container);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -318,12 +318,6 @@ static struct cmd_results *cmd_exec(int argc, char **argv) {
 | 
				
			||||||
	return cmd_exec_always(argc, argv);
 | 
						return cmd_exec_always(argc, argv);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void kill_views(swayc_t *container, void *data) {
 | 
					 | 
				
			||||||
	if (container->type == C_VIEW) {
 | 
					 | 
				
			||||||
		wlc_view_close(container->handle);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static struct cmd_results *cmd_exit(int argc, char **argv) {
 | 
					static struct cmd_results *cmd_exit(int argc, char **argv) {
 | 
				
			||||||
	struct cmd_results *error = NULL;
 | 
						struct cmd_results *error = NULL;
 | 
				
			||||||
	if (config->reading) return cmd_results_new(CMD_FAILURE, "exit", "Can't be used in config file.");
 | 
						if (config->reading) return cmd_results_new(CMD_FAILURE, "exit", "Can't be used in config file.");
 | 
				
			||||||
| 
						 | 
					@ -331,7 +325,7 @@ static struct cmd_results *cmd_exit(int argc, char **argv) {
 | 
				
			||||||
		return error;
 | 
							return error;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	// Close all views
 | 
						// Close all views
 | 
				
			||||||
	container_map(&root_container, kill_views, NULL);
 | 
						close_views(&root_container);
 | 
				
			||||||
	sway_terminate();
 | 
						sway_terminate();
 | 
				
			||||||
	return cmd_results_new(CMD_SUCCESS, NULL, NULL);
 | 
						return cmd_results_new(CMD_SUCCESS, NULL, NULL);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -796,3 +796,13 @@ void add_gaps(swayc_t *view, void *_data) {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void close_view(swayc_t *container, void *data) {
 | 
				
			||||||
 | 
						if (container->type == C_VIEW) {
 | 
				
			||||||
 | 
							wlc_view_close(container->handle);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void close_views(swayc_t *container) {
 | 
				
			||||||
 | 
						container_map(container, close_view, NULL);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -26,6 +26,11 @@ void sway_terminate(void) {
 | 
				
			||||||
	wlc_terminate();
 | 
						wlc_terminate();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void sig_handler(int signal) {
 | 
				
			||||||
 | 
						close_views(&root_container);
 | 
				
			||||||
 | 
						sway_terminate();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void wlc_log_handler(enum wlc_log_type type, const char *str) {
 | 
					static void wlc_log_handler(enum wlc_log_type type, const char *str) {
 | 
				
			||||||
	if (type == WLC_LOG_ERROR) {
 | 
						if (type == WLC_LOG_ERROR) {
 | 
				
			||||||
		sway_log(L_ERROR, "[wlc] %s", str);
 | 
							sway_log(L_ERROR, "[wlc] %s", str);
 | 
				
			||||||
| 
						 | 
					@ -176,6 +181,9 @@ int main(int argc, char **argv) {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	register_extensions();
 | 
						register_extensions();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// handle SIGTERM signals
 | 
				
			||||||
 | 
						signal(SIGTERM, sig_handler);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE
 | 
					#if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE
 | 
				
			||||||
	sway_log(L_INFO, "Starting sway version %s (%s, branch \"%s\")\n", SWAY_GIT_VERSION, SWAY_VERSION_DATE, SWAY_GIT_BRANCH);
 | 
						sway_log(L_INFO, "Starting sway version %s (%s, branch \"%s\")\n", SWAY_GIT_VERSION, SWAY_VERSION_DATE, SWAY_GIT_BRANCH);
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue