summaryrefslogtreecommitdiffstats
path: root/sway/commands
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-08-02 21:37:29 -0400
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-08-03 10:37:35 -0400
commita7f7d4a488c8d3b2461122765f9904c8a411a583 (patch)
tree7abee51265a8b9550c62255d0c6649935ee1d6a2 /sway/commands
parentShow swaynag on config errors (diff)
downloadsway-a7f7d4a488c8d3b2461122765f9904c8a411a583.tar.gz
sway-a7f7d4a488c8d3b2461122765f9904c8a411a583.tar.zst
sway-a7f7d4a488c8d3b2461122765f9904c8a411a583.zip
Write to swaynag pipe fd directly on config errors
Diffstat (limited to 'sway/commands')
-rw-r--r--sway/commands/include.c15
-rw-r--r--sway/commands/reload.c15
-rw-r--r--sway/commands/swaynag_command.c20
3 files changed, 24 insertions, 26 deletions
diff --git a/sway/commands/include.c b/sway/commands/include.c
index 72fec7cc..61f383bb 100644
--- a/sway/commands/include.c
+++ b/sway/commands/include.c
@@ -7,19 +7,10 @@ struct cmd_results *cmd_include(int argc, char **argv) {
7 return error; 7 return error;
8 } 8 }
9 9
10 char *errors = NULL; 10 if (!load_include_configs(argv[0], config,
11 if (!load_include_configs(argv[0], config, &errors)) { 11 &config->swaynag_config_errors)) {
12 struct cmd_results *result = cmd_results_new(CMD_INVALID, "include", 12 return cmd_results_new(CMD_INVALID, "include",
13 "Failed to include sub configuration file: %s", argv[0]); 13 "Failed to include sub configuration file: %s", argv[0]);
14 free(errors);
15 return result;
16 }
17
18 if (errors) {
19 struct cmd_results *result = cmd_results_new(CMD_INVALID, "include",
20 "There are errors in the included config\n%s", errors);
21 free(errors);
22 return result;
23 } 14 }
24 15
25 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 16 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
diff --git a/sway/commands/reload.c b/sway/commands/reload.c
index 9bf671d9..f8ca374d 100644
--- a/sway/commands/reload.c
+++ b/sway/commands/reload.c
@@ -1,5 +1,4 @@
1#define _XOPEN_SOURCE 500 1#define _XOPEN_SOURCE 500
2#include <signal.h>
3#include <string.h> 2#include <string.h>
4#include "sway/commands.h" 3#include "sway/commands.h"
5#include "sway/config.h" 4#include "sway/config.h"
@@ -20,9 +19,7 @@ struct cmd_results *cmd_reload(int argc, char **argv) {
20 list_add(bar_ids, strdup(bar->id)); 19 list_add(bar_ids, strdup(bar->id));
21 } 20 }
22 21
23 char *errors = NULL; 22 if (!load_main_config(config->current_config_path, true, false)) {
24 if (!load_main_config(config->current_config_path, true, &errors)) {
25 free(errors);
26 return cmd_results_new(CMD_FAILURE, "reload", 23 return cmd_results_new(CMD_FAILURE, "reload",
27 "Error(s) reloading config."); 24 "Error(s) reloading config.");
28 } 25 }
@@ -47,15 +44,5 @@ struct cmd_results *cmd_reload(int argc, char **argv) {
47 44
48 arrange_windows(&root_container); 45 arrange_windows(&root_container);
49 46
50 if (config->swaynag_pid > 0) {
51 kill(config->swaynag_pid, SIGTERM);
52 config->swaynag_pid = -1;
53 }
54
55 if (errors) {
56 spawn_swaynag_config_errors(config, errors);
57 free(errors);
58 }
59
60 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 47 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
61} 48}
diff --git a/sway/commands/swaynag_command.c b/sway/commands/swaynag_command.c
new file mode 100644
index 00000000..c57a80a6
--- /dev/null
+++ b/sway/commands/swaynag_command.c
@@ -0,0 +1,20 @@
1#include <string.h>
2#include "sway/commands.h"
3#include "log.h"
4#include "stringop.h"
5
6struct cmd_results *cmd_swaynag_command(int argc, char **argv) {
7 struct cmd_results *error = NULL;
8 if ((error = checkarg(argc, "swaynag_command", EXPECTED_AT_LEAST, 1))) {
9 return error;
10 }
11
12 if (config->swaynag_command) {
13 free(config->swaynag_command);
14 }
15 config->swaynag_command = join_args(argv, argc);
16 wlr_log(WLR_DEBUG, "Using custom swaynag command: %s",
17 config->swaynag_command);
18
19 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
20}