aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-01-29 13:18:53 -0500
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-01-29 13:18:53 -0500
commitf0fd6119cffd22c1bdf5553cc2a729839840d63e (patch)
tree9c30e11d281adaa634231f91eed98a84860ded1b
parentDocument cursor moving between adjacent outputs (diff)
downloadsway-f0fd6119cffd22c1bdf5553cc2a729839840d63e.tar.gz
sway-f0fd6119cffd22c1bdf5553cc2a729839840d63e.tar.zst
sway-f0fd6119cffd22c1bdf5553cc2a729839840d63e.zip
Cleanup config reading failure error logs
This cleans up the log when sway fails to read a config file. The following changes have been made: - A missing error message has been added to the log when the config file is a directory instead of a regular file - In main, `goto` statements have been added after the `sway_terminate` calls instead of wrapping every block in `if (!terminate_request)` - Unnecessary NULL-checks around calls to free in `main` have been removed - Deferred command execution has been extracted to a separate function and the `Running deferred commands` log message will not be shown when there are no deferred commands.
-rw-r--r--include/sway/config.h5
-rw-r--r--sway/config.c25
-rw-r--r--sway/main.c41
3 files changed, 39 insertions, 32 deletions
diff --git a/include/sway/config.h b/include/sway/config.h
index 8215ff59..d5467a56 100644
--- a/include/sway/config.h
+++ b/include/sway/config.h
@@ -516,6 +516,11 @@ bool read_config(FILE *file, struct sway_config *config,
516 struct swaynag_instance *swaynag); 516 struct swaynag_instance *swaynag);
517 517
518/** 518/**
519 * Run the commands that were deferred when reading the config file.
520 */
521void run_deferred_commands(void);
522
523/**
519 * Adds a warning entry to the swaynag instance used for errors. 524 * Adds a warning entry to the swaynag instance used for errors.
520 */ 525 */
521void config_add_swaynag_warning(char *fmt, ...); 526void config_add_swaynag_warning(char *fmt, ...);
diff --git a/sway/config.c b/sway/config.c
index 145b3be6..7cb27d95 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -20,6 +20,7 @@
20#include "sway/commands.h" 20#include "sway/commands.h"
21#include "sway/config.h" 21#include "sway/config.h"
22#include "sway/criteria.h" 22#include "sway/criteria.h"
23#include "sway/desktop/transaction.h"
23#include "sway/swaynag.h" 24#include "sway/swaynag.h"
24#include "sway/tree/arrange.h" 25#include "sway/tree/arrange.h"
25#include "sway/tree/root.h" 26#include "sway/tree/root.h"
@@ -343,6 +344,7 @@ static bool load_config(const char *path, struct sway_config *config,
343 344
344 struct stat sb; 345 struct stat sb;
345 if (stat(path, &sb) == 0 && S_ISDIR(sb.st_mode)) { 346 if (stat(path, &sb) == 0 && S_ISDIR(sb.st_mode)) {
347 sway_log(SWAY_ERROR, "%s is a directory not a config file", path);
346 return false; 348 return false;
347 } 349 }
348 350
@@ -573,6 +575,29 @@ bool load_include_configs(const char *path, struct sway_config *config,
573 return true; 575 return true;
574} 576}
575 577
578void run_deferred_commands(void) {
579 if (!config->cmd_queue->length) {
580 return;
581 }
582 sway_log(SWAY_DEBUG, "Running deferred commands");
583 while (config->cmd_queue->length) {
584 char *line = config->cmd_queue->items[0];
585 list_t *res_list = execute_command(line, NULL, NULL);
586 for (int i = 0; i < res_list->length; ++i) {
587 struct cmd_results *res = res_list->items[i];
588 if (res->status != CMD_SUCCESS) {
589 sway_log(SWAY_ERROR, "Error on line '%s': %s",
590 line, res->error);
591 }
592 free_cmd_results(res);
593 }
594 list_del(config->cmd_queue, 0);
595 list_free(res_list);
596 free(line);
597 }
598 transaction_commit_dirty();
599}
600
576// get line, with backslash continuation 601// get line, with backslash continuation
577static ssize_t getline_with_cont(char **lineptr, size_t *line_size, FILE *file, 602static ssize_t getline_with_cont(char **lineptr, size_t *line_size, FILE *file,
578 int *nlines) { 603 int *nlines) {
diff --git a/sway/main.c b/sway/main.c
index c824a6fb..a3198af1 100644
--- a/sway/main.c
+++ b/sway/main.c
@@ -16,7 +16,6 @@
16#include "sway/commands.h" 16#include "sway/commands.h"
17#include "sway/config.h" 17#include "sway/config.h"
18#include "sway/debug.h" 18#include "sway/debug.h"
19#include "sway/desktop/transaction.h"
20#include "sway/server.h" 19#include "sway/server.h"
21#include "sway/swaynag.h" 20#include "sway/swaynag.h"
22#include "sway/tree/root.h" 21#include "sway/tree/root.h"
@@ -370,55 +369,33 @@ int main(int argc, char **argv) {
370 setenv("WAYLAND_DISPLAY", server.socket, true); 369 setenv("WAYLAND_DISPLAY", server.socket, true);
371 if (!load_main_config(config_path, false, false)) { 370 if (!load_main_config(config_path, false, false)) {
372 sway_terminate(EXIT_FAILURE); 371 sway_terminate(EXIT_FAILURE);
372 goto shutdown;
373 } 373 }
374 374
375 if (config_path) { 375 if (!server_start(&server)) {
376 free(config_path); 376 sway_terminate(EXIT_FAILURE);
377 } 377 goto shutdown;
378
379 if (!terminate_request) {
380 if (!server_start(&server)) {
381 sway_terminate(EXIT_FAILURE);
382 }
383 } 378 }
384 379
385 config->active = true; 380 config->active = true;
386 load_swaybars(); 381 load_swaybars();
387 // Execute commands until there are none left 382 run_deferred_commands();
388 sway_log(SWAY_DEBUG, "Running deferred commands");
389 while (config->cmd_queue->length) {
390 char *line = config->cmd_queue->items[0];
391 list_t *res_list = execute_command(line, NULL, NULL);
392 for (int i = 0; i < res_list->length; ++i) {
393 struct cmd_results *res = res_list->items[i];
394 if (res->status != CMD_SUCCESS) {
395 sway_log(SWAY_ERROR, "Error on line '%s': %s", line, res->error);
396 }
397 free_cmd_results(res);
398 }
399 list_free(res_list);
400 free(line);
401 list_del(config->cmd_queue, 0);
402 }
403 transaction_commit_dirty();
404 383
405 if (config->swaynag_config_errors.pid > 0) { 384 if (config->swaynag_config_errors.pid > 0) {
406 swaynag_show(&config->swaynag_config_errors); 385 swaynag_show(&config->swaynag_config_errors);
407 } 386 }
408 387
409 if (!terminate_request) { 388 server_run(&server);
410 server_run(&server);
411 }
412 389
390shutdown:
413 sway_log(SWAY_INFO, "Shutting down sway"); 391 sway_log(SWAY_INFO, "Shutting down sway");
414 392
415 server_fini(&server); 393 server_fini(&server);
416 root_destroy(root); 394 root_destroy(root);
417 root = NULL; 395 root = NULL;
418 396
419 if (config) { 397 free(config_path);
420 free_config(config); 398 free_config(config);
421 }
422 399
423 pango_cairo_font_map_set_default(NULL); 400 pango_cairo_font_map_set_default(NULL);
424 401