aboutsummaryrefslogtreecommitdiffstats
path: root/sway/config.c
diff options
context:
space:
mode:
authorLibravatar M Stoeckl <code@mstoeckl.com>2019-01-20 13:51:12 -0500
committerLibravatar emersion <contact@emersion.fr>2019-01-21 12:59:42 +0100
commit1211a81aad18bbc4d9e8fb9973238ad8e7e1f688 (patch)
tree5c3f60e0219cb8b4a1b7cafb760a871661866e32 /sway/config.c
parentLog libinput_config_status errors (diff)
downloadsway-1211a81aad18bbc4d9e8fb9973238ad8e7e1f688.tar.gz
sway-1211a81aad18bbc4d9e8fb9973238ad8e7e1f688.tar.zst
sway-1211a81aad18bbc4d9e8fb9973238ad8e7e1f688.zip
Replace wlr_log with sway_log
This commit mostly duplicates the wlr_log functions, although with a sway_* prefix. (This is very similar to PR #2009.) However, the logging function no longer needs to be replaceable, so sway_log_init's second argument is used to set the exit callback for sway_abort. wlr_log_init is still invoked in sway/main.c This commit makes it easier to remove the wlroots dependency for the helper programs swaymsg, swaybg, swaybar, and swaynag.
Diffstat (limited to 'sway/config.c')
-rw-r--r--sway/config.c50
1 files changed, 25 insertions, 25 deletions
diff --git a/sway/config.c b/sway/config.c
index d5d36306..145b3be6 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -335,11 +335,11 @@ static char *get_config_path(void) {
335static bool load_config(const char *path, struct sway_config *config, 335static bool load_config(const char *path, struct sway_config *config,
336 struct swaynag_instance *swaynag) { 336 struct swaynag_instance *swaynag) {
337 if (path == NULL) { 337 if (path == NULL) {
338 wlr_log(WLR_ERROR, "Unable to find a config file!"); 338 sway_log(SWAY_ERROR, "Unable to find a config file!");
339 return false; 339 return false;
340 } 340 }
341 341
342 wlr_log(WLR_INFO, "Loading config from %s", path); 342 sway_log(SWAY_INFO, "Loading config from %s", path);
343 343
344 struct stat sb; 344 struct stat sb;
345 if (stat(path, &sb) == 0 && S_ISDIR(sb.st_mode)) { 345 if (stat(path, &sb) == 0 && S_ISDIR(sb.st_mode)) {
@@ -348,7 +348,7 @@ static bool load_config(const char *path, struct sway_config *config,
348 348
349 FILE *f = fopen(path, "r"); 349 FILE *f = fopen(path, "r");
350 if (!f) { 350 if (!f) {
351 wlr_log(WLR_ERROR, "Unable to open %s for reading", path); 351 sway_log(SWAY_ERROR, "Unable to open %s for reading", path);
352 return false; 352 return false;
353 } 353 }
354 354
@@ -356,7 +356,7 @@ static bool load_config(const char *path, struct sway_config *config,
356 fclose(f); 356 fclose(f);
357 357
358 if (!config_load_success) { 358 if (!config_load_success) {
359 wlr_log(WLR_ERROR, "Error(s) loading config!"); 359 sway_log(SWAY_ERROR, "Error(s) loading config!");
360 } 360 }
361 361
362 return true; 362 return true;
@@ -379,7 +379,7 @@ bool load_main_config(const char *file, bool is_active, bool validating) {
379 config_defaults(config); 379 config_defaults(config);
380 config->validating = validating; 380 config->validating = validating;
381 if (is_active) { 381 if (is_active) {
382 wlr_log(WLR_DEBUG, "Performing configuration file %s", 382 sway_log(SWAY_DEBUG, "Performing configuration file %s",
383 validating ? "validation" : "reload"); 383 validating ? "validation" : "reload");
384 config->reloading = true; 384 config->reloading = true;
385 config->active = true; 385 config->active = true;
@@ -403,7 +403,7 @@ bool load_main_config(const char *file, bool is_active, bool validating) {
403 /* 403 /*
404 DIR *dir = opendir(SYSCONFDIR "/sway/security.d"); 404 DIR *dir = opendir(SYSCONFDIR "/sway/security.d");
405 if (!dir) { 405 if (!dir) {
406 wlr_log(WLR_ERROR, 406 sway_log(SWAY_ERROR,
407 "%s does not exist, sway will have no security configuration" 407 "%s does not exist, sway will have no security configuration"
408 " and will probably be broken", SYSCONFDIR "/sway/security.d"); 408 " and will probably be broken", SYSCONFDIR "/sway/security.d");
409 } else { 409 } else {
@@ -432,7 +432,7 @@ bool load_main_config(const char *file, bool is_active, bool validating) {
432 if (stat(_path, &s) || s.st_uid != 0 || s.st_gid != 0 || 432 if (stat(_path, &s) || s.st_uid != 0 || s.st_gid != 0 ||
433 (((s.st_mode & 0777) != 0644) && 433 (((s.st_mode & 0777) != 0644) &&
434 (s.st_mode & 0777) != 0444)) { 434 (s.st_mode & 0777) != 0444)) {
435 wlr_log(WLR_ERROR, 435 sway_log(SWAY_ERROR,
436 "Refusing to load %s - it must be owned by root " 436 "Refusing to load %s - it must be owned by root "
437 "and mode 644 or 444", _path); 437 "and mode 644 or 444", _path);
438 success = false; 438 success = false;
@@ -488,7 +488,7 @@ static bool load_include_config(const char *path, const char *parent_dir,
488 len = len + strlen(parent_dir) + 2; 488 len = len + strlen(parent_dir) + 2;
489 full_path = malloc(len * sizeof(char)); 489 full_path = malloc(len * sizeof(char));
490 if (!full_path) { 490 if (!full_path) {
491 wlr_log(WLR_ERROR, 491 sway_log(SWAY_ERROR,
492 "Unable to allocate full path to included config"); 492 "Unable to allocate full path to included config");
493 return false; 493 return false;
494 } 494 }
@@ -501,7 +501,7 @@ static bool load_include_config(const char *path, const char *parent_dir,
501 free(full_path); 501 free(full_path);
502 502
503 if (real_path == NULL) { 503 if (real_path == NULL) {
504 wlr_log(WLR_DEBUG, "%s not found.", path); 504 sway_log(SWAY_DEBUG, "%s not found.", path);
505 return false; 505 return false;
506 } 506 }
507 507
@@ -510,7 +510,7 @@ static bool load_include_config(const char *path, const char *parent_dir,
510 for (j = 0; j < config->config_chain->length; ++j) { 510 for (j = 0; j < config->config_chain->length; ++j) {
511 char *old_path = config->config_chain->items[j]; 511 char *old_path = config->config_chain->items[j];
512 if (strcmp(real_path, old_path) == 0) { 512 if (strcmp(real_path, old_path) == 0) {
513 wlr_log(WLR_DEBUG, 513 sway_log(SWAY_DEBUG,
514 "%s already included once, won't be included again.", 514 "%s already included once, won't be included again.",
515 real_path); 515 real_path);
516 free(real_path); 516 free(real_path);
@@ -565,7 +565,7 @@ bool load_include_configs(const char *path, struct sway_config *config,
565 // restore wd 565 // restore wd
566 if (chdir(wd) < 0) { 566 if (chdir(wd) < 0) {
567 free(wd); 567 free(wd);
568 wlr_log(WLR_ERROR, "failed to restore working directory"); 568 sway_log(SWAY_ERROR, "failed to restore working directory");
569 return false; 569 return false;
570 } 570 }
571 571
@@ -630,7 +630,7 @@ static char *expand_line(const char *block, const char *line, bool add_brace) {
630 + (add_brace ? 2 : 0) + 1; 630 + (add_brace ? 2 : 0) + 1;
631 char *expanded = calloc(1, size); 631 char *expanded = calloc(1, size);
632 if (!expanded) { 632 if (!expanded) {
633 wlr_log(WLR_ERROR, "Cannot allocate expanded line buffer"); 633 sway_log(SWAY_ERROR, "Cannot allocate expanded line buffer");
634 return NULL; 634 return NULL;
635 } 635 }
636 snprintf(expanded, size, "%s%s%s%s", block ? block : "", 636 snprintf(expanded, size, "%s%s%s%s", block ? block : "",
@@ -649,7 +649,7 @@ bool read_config(FILE *file, struct sway_config *config,
649 int ret_seek = fseek(file, 0, SEEK_END); 649 int ret_seek = fseek(file, 0, SEEK_END);
650 long ret_tell = ftell(file); 650 long ret_tell = ftell(file);
651 if (ret_seek == -1 || ret_tell == -1) { 651 if (ret_seek == -1 || ret_tell == -1) {
652 wlr_log(WLR_ERROR, "Unable to get size of config file"); 652 sway_log(SWAY_ERROR, "Unable to get size of config file");
653 return false; 653 return false;
654 } 654 }
655 config_size = ret_tell; 655 config_size = ret_tell;
@@ -657,7 +657,7 @@ bool read_config(FILE *file, struct sway_config *config,
657 657
658 config->current_config = this_config = calloc(1, config_size + 1); 658 config->current_config = this_config = calloc(1, config_size + 1);
659 if (this_config == NULL) { 659 if (this_config == NULL) {
660 wlr_log(WLR_ERROR, "Unable to allocate buffer for config contents"); 660 sway_log(SWAY_ERROR, "Unable to allocate buffer for config contents");
661 return false; 661 return false;
662 } 662 }
663 } 663 }
@@ -673,7 +673,7 @@ bool read_config(FILE *file, struct sway_config *config,
673 while ((nread = getline_with_cont(&line, &line_size, file, &nlines)) != -1) { 673 while ((nread = getline_with_cont(&line, &line_size, file, &nlines)) != -1) {
674 if (reading_main_config) { 674 if (reading_main_config) {
675 if (read + nread > config_size) { 675 if (read + nread > config_size) {
676 wlr_log(WLR_ERROR, "Config file changed during reading"); 676 sway_log(SWAY_ERROR, "Config file changed during reading");
677 success = false; 677 success = false;
678 break; 678 break;
679 } 679 }
@@ -687,7 +687,7 @@ bool read_config(FILE *file, struct sway_config *config,
687 } 687 }
688 688
689 line_number += nlines; 689 line_number += nlines;
690 wlr_log(WLR_DEBUG, "Read line %d: %s", line_number, line); 690 sway_log(SWAY_DEBUG, "Read line %d: %s", line_number, line);
691 691
692 strip_whitespace(line); 692 strip_whitespace(line);
693 if (!*line || line[0] == '#') { 693 if (!*line || line[0] == '#') {
@@ -698,7 +698,7 @@ bool read_config(FILE *file, struct sway_config *config,
698 brace_detected = detect_brace(file); 698 brace_detected = detect_brace(file);
699 if (brace_detected > 0) { 699 if (brace_detected > 0) {
700 line_number += brace_detected; 700 line_number += brace_detected;
701 wlr_log(WLR_DEBUG, "Detected open brace on line %d", line_number); 701 sway_log(SWAY_DEBUG, "Detected open brace on line %d", line_number);
702 } 702 }
703 } 703 }
704 char *block = stack->length ? stack->items[0] : NULL; 704 char *block = stack->length ? stack->items[0] : NULL;
@@ -720,7 +720,7 @@ bool read_config(FILE *file, struct sway_config *config,
720 switch(res->status) { 720 switch(res->status) {
721 case CMD_FAILURE: 721 case CMD_FAILURE:
722 case CMD_INVALID: 722 case CMD_INVALID:
723 wlr_log(WLR_ERROR, "Error on line %i '%s': %s (%s)", line_number, 723 sway_log(SWAY_ERROR, "Error on line %i '%s': %s (%s)", line_number,
724 line, res->error, config->current_config_path); 724 line, res->error, config->current_config_path);
725 if (!config->validating) { 725 if (!config->validating) {
726 swaynag_log(config->swaynag_command, swaynag, 726 swaynag_log(config->swaynag_command, swaynag,
@@ -731,17 +731,17 @@ bool read_config(FILE *file, struct sway_config *config,
731 break; 731 break;
732 732
733 case CMD_DEFER: 733 case CMD_DEFER:
734 wlr_log(WLR_DEBUG, "Deferring command `%s'", line); 734 sway_log(SWAY_DEBUG, "Deferring command `%s'", line);
735 list_add(config->cmd_queue, strdup(expanded)); 735 list_add(config->cmd_queue, strdup(expanded));
736 break; 736 break;
737 737
738 case CMD_BLOCK_COMMANDS: 738 case CMD_BLOCK_COMMANDS:
739 wlr_log(WLR_DEBUG, "Entering commands block"); 739 sway_log(SWAY_DEBUG, "Entering commands block");
740 list_insert(stack, 0, "<commands>"); 740 list_insert(stack, 0, "<commands>");
741 break; 741 break;
742 742
743 case CMD_BLOCK: 743 case CMD_BLOCK:
744 wlr_log(WLR_DEBUG, "Entering block '%s'", new_block); 744 sway_log(SWAY_DEBUG, "Entering block '%s'", new_block);
745 list_insert(stack, 0, strdup(new_block)); 745 list_insert(stack, 0, strdup(new_block));
746 if (strcmp(new_block, "bar") == 0) { 746 if (strcmp(new_block, "bar") == 0) {
747 config->current_bar = NULL; 747 config->current_bar = NULL;
@@ -750,7 +750,7 @@ bool read_config(FILE *file, struct sway_config *config,
750 750
751 case CMD_BLOCK_END: 751 case CMD_BLOCK_END:
752 if (!block) { 752 if (!block) {
753 wlr_log(WLR_DEBUG, "Unmatched '}' on line %i", line_number); 753 sway_log(SWAY_DEBUG, "Unmatched '}' on line %i", line_number);
754 success = false; 754 success = false;
755 break; 755 break;
756 } 756 }
@@ -758,7 +758,7 @@ bool read_config(FILE *file, struct sway_config *config,
758 config->current_bar = NULL; 758 config->current_bar = NULL;
759 } 759 }
760 760
761 wlr_log(WLR_DEBUG, "Exiting block '%s'", block); 761 sway_log(SWAY_DEBUG, "Exiting block '%s'", block);
762 list_del(stack, 0); 762 list_del(stack, 0);
763 free(block); 763 free(block);
764 memset(&config->handler_context, 0, 764 memset(&config->handler_context, 0,
@@ -786,7 +786,7 @@ void config_add_swaynag_warning(char *fmt, ...) {
786 786
787 char *temp = malloc(length + 1); 787 char *temp = malloc(length + 1);
788 if (!temp) { 788 if (!temp) {
789 wlr_log(WLR_ERROR, "Failed to allocate buffer for warning."); 789 sway_log(SWAY_ERROR, "Failed to allocate buffer for warning.");
790 return; 790 return;
791 } 791 }
792 792
@@ -828,7 +828,7 @@ char *do_var_replacement(char *str) {
828 int vvlen = strlen(var->value); 828 int vvlen = strlen(var->value);
829 char *newstr = malloc(strlen(str) - vnlen + vvlen + 1); 829 char *newstr = malloc(strlen(str) - vnlen + vvlen + 1);
830 if (!newstr) { 830 if (!newstr) {
831 wlr_log(WLR_ERROR, 831 sway_log(SWAY_ERROR,
832 "Unable to allocate replacement " 832 "Unable to allocate replacement "
833 "during variable expansion"); 833 "during variable expansion");
834 break; 834 break;