aboutsummaryrefslogtreecommitdiffstats
path: root/sway/config.c
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 /sway/config.c
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.
Diffstat (limited to 'sway/config.c')
-rw-r--r--sway/config.c25
1 files changed, 25 insertions, 0 deletions
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) {