mirror of
				https://github.com/swaywm/sway.git
				synced 2025-11-03 09:01:43 -05:00 
			
		
		
		
	Merge pull request #3535 from RedSoxFan/cleanup-log-on-config-failure
Cleanup config reading failure error logs
This commit is contained in:
		
						commit
						4f4424f66c
					
				
					 3 changed files with 39 additions and 32 deletions
				
			
		| 
						 | 
					@ -515,6 +515,11 @@ bool load_include_configs(const char *path, struct sway_config *config,
 | 
				
			||||||
bool read_config(FILE *file, struct sway_config *config,
 | 
					bool read_config(FILE *file, struct sway_config *config,
 | 
				
			||||||
		struct swaynag_instance *swaynag);
 | 
							struct swaynag_instance *swaynag);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Run the commands that were deferred when reading the config file.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					void run_deferred_commands(void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Adds a warning entry to the swaynag instance used for errors.
 | 
					 * Adds a warning entry to the swaynag instance used for errors.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -20,6 +20,7 @@
 | 
				
			||||||
#include "sway/commands.h"
 | 
					#include "sway/commands.h"
 | 
				
			||||||
#include "sway/config.h"
 | 
					#include "sway/config.h"
 | 
				
			||||||
#include "sway/criteria.h"
 | 
					#include "sway/criteria.h"
 | 
				
			||||||
 | 
					#include "sway/desktop/transaction.h"
 | 
				
			||||||
#include "sway/swaynag.h"
 | 
					#include "sway/swaynag.h"
 | 
				
			||||||
#include "sway/tree/arrange.h"
 | 
					#include "sway/tree/arrange.h"
 | 
				
			||||||
#include "sway/tree/root.h"
 | 
					#include "sway/tree/root.h"
 | 
				
			||||||
| 
						 | 
					@ -343,6 +344,7 @@ static bool load_config(const char *path, struct sway_config *config,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct stat sb;
 | 
						struct stat sb;
 | 
				
			||||||
	if (stat(path, &sb) == 0 && S_ISDIR(sb.st_mode)) {
 | 
						if (stat(path, &sb) == 0 && S_ISDIR(sb.st_mode)) {
 | 
				
			||||||
 | 
							sway_log(SWAY_ERROR, "%s is a directory not a config file", path);
 | 
				
			||||||
		return false;
 | 
							return false;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -573,6 +575,29 @@ bool load_include_configs(const char *path, struct sway_config *config,
 | 
				
			||||||
	return true;
 | 
						return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void run_deferred_commands(void) {
 | 
				
			||||||
 | 
						if (!config->cmd_queue->length) {
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						sway_log(SWAY_DEBUG, "Running deferred commands");
 | 
				
			||||||
 | 
						while (config->cmd_queue->length) {
 | 
				
			||||||
 | 
							char *line = config->cmd_queue->items[0];
 | 
				
			||||||
 | 
							list_t *res_list = execute_command(line, NULL, NULL);
 | 
				
			||||||
 | 
							for (int i = 0; i < res_list->length; ++i) {
 | 
				
			||||||
 | 
								struct cmd_results *res = res_list->items[i];
 | 
				
			||||||
 | 
								if (res->status != CMD_SUCCESS) {
 | 
				
			||||||
 | 
									sway_log(SWAY_ERROR, "Error on line '%s': %s",
 | 
				
			||||||
 | 
											line, res->error);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								free_cmd_results(res);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							list_del(config->cmd_queue, 0);
 | 
				
			||||||
 | 
							list_free(res_list);
 | 
				
			||||||
 | 
							free(line);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						transaction_commit_dirty();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// get line, with backslash continuation
 | 
					// get line, with backslash continuation
 | 
				
			||||||
static ssize_t getline_with_cont(char **lineptr, size_t *line_size, FILE *file,
 | 
					static ssize_t getline_with_cont(char **lineptr, size_t *line_size, FILE *file,
 | 
				
			||||||
		int *nlines) {
 | 
							int *nlines) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										33
									
								
								sway/main.c
									
										
									
									
									
								
							
							
						
						
									
										33
									
								
								sway/main.c
									
										
									
									
									
								
							| 
						 | 
					@ -16,7 +16,6 @@
 | 
				
			||||||
#include "sway/commands.h"
 | 
					#include "sway/commands.h"
 | 
				
			||||||
#include "sway/config.h"
 | 
					#include "sway/config.h"
 | 
				
			||||||
#include "sway/debug.h"
 | 
					#include "sway/debug.h"
 | 
				
			||||||
#include "sway/desktop/transaction.h"
 | 
					 | 
				
			||||||
#include "sway/server.h"
 | 
					#include "sway/server.h"
 | 
				
			||||||
#include "sway/swaynag.h"
 | 
					#include "sway/swaynag.h"
 | 
				
			||||||
#include "sway/tree/root.h"
 | 
					#include "sway/tree/root.h"
 | 
				
			||||||
| 
						 | 
					@ -370,55 +369,33 @@ int main(int argc, char **argv) {
 | 
				
			||||||
	setenv("WAYLAND_DISPLAY", server.socket, true);
 | 
						setenv("WAYLAND_DISPLAY", server.socket, true);
 | 
				
			||||||
	if (!load_main_config(config_path, false, false)) {
 | 
						if (!load_main_config(config_path, false, false)) {
 | 
				
			||||||
		sway_terminate(EXIT_FAILURE);
 | 
							sway_terminate(EXIT_FAILURE);
 | 
				
			||||||
 | 
							goto shutdown;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (config_path) {
 | 
					 | 
				
			||||||
		free(config_path);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (!terminate_request) {
 | 
					 | 
				
			||||||
	if (!server_start(&server)) {
 | 
						if (!server_start(&server)) {
 | 
				
			||||||
		sway_terminate(EXIT_FAILURE);
 | 
							sway_terminate(EXIT_FAILURE);
 | 
				
			||||||
		}
 | 
							goto shutdown;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	config->active = true;
 | 
						config->active = true;
 | 
				
			||||||
	load_swaybars();
 | 
						load_swaybars();
 | 
				
			||||||
	// Execute commands until there are none left
 | 
						run_deferred_commands();
 | 
				
			||||||
	sway_log(SWAY_DEBUG, "Running deferred commands");
 | 
					 | 
				
			||||||
	while (config->cmd_queue->length) {
 | 
					 | 
				
			||||||
		char *line = config->cmd_queue->items[0];
 | 
					 | 
				
			||||||
		list_t *res_list = execute_command(line, NULL, NULL);
 | 
					 | 
				
			||||||
		for (int i = 0; i < res_list->length; ++i) {
 | 
					 | 
				
			||||||
			struct cmd_results *res = res_list->items[i];
 | 
					 | 
				
			||||||
			if (res->status != CMD_SUCCESS) {
 | 
					 | 
				
			||||||
				sway_log(SWAY_ERROR, "Error on line '%s': %s", line, res->error);
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			free_cmd_results(res);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		list_free(res_list);
 | 
					 | 
				
			||||||
		free(line);
 | 
					 | 
				
			||||||
		list_del(config->cmd_queue, 0);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	transaction_commit_dirty();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (config->swaynag_config_errors.pid > 0) {
 | 
						if (config->swaynag_config_errors.pid > 0) {
 | 
				
			||||||
		swaynag_show(&config->swaynag_config_errors);
 | 
							swaynag_show(&config->swaynag_config_errors);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!terminate_request) {
 | 
					 | 
				
			||||||
	server_run(&server);
 | 
						server_run(&server);
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					shutdown:
 | 
				
			||||||
	sway_log(SWAY_INFO, "Shutting down sway");
 | 
						sway_log(SWAY_INFO, "Shutting down sway");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	server_fini(&server);
 | 
						server_fini(&server);
 | 
				
			||||||
	root_destroy(root);
 | 
						root_destroy(root);
 | 
				
			||||||
	root = NULL;
 | 
						root = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (config) {
 | 
						free(config_path);
 | 
				
			||||||
	free_config(config);
 | 
						free_config(config);
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pango_cairo_font_map_set_default(NULL);
 | 
						pango_cairo_font_map_set_default(NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue