diff options
author | Brian Ashworth <bosrsf04@gmail.com> | 2019-01-29 13:18:53 -0500 |
---|---|---|
committer | Brian Ashworth <bosrsf04@gmail.com> | 2019-01-29 13:18:53 -0500 |
commit | f0fd6119cffd22c1bdf5553cc2a729839840d63e (patch) | |
tree | 9c30e11d281adaa634231f91eed98a84860ded1b /sway/main.c | |
parent | Document cursor moving between adjacent outputs (diff) | |
download | sway-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/main.c')
-rw-r--r-- | sway/main.c | 41 |
1 files changed, 9 insertions, 32 deletions
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 | ||
390 | shutdown: | ||
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 | ||