aboutsummaryrefslogtreecommitdiffstats
path: root/swaylock/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'swaylock/main.c')
-rw-r--r--swaylock/main.c33
1 files changed, 14 insertions, 19 deletions
diff --git a/swaylock/main.c b/swaylock/main.c
index 9aeb4e64..9a4f3b58 100644
--- a/swaylock/main.c
+++ b/swaylock/main.c
@@ -23,7 +23,6 @@
23#include "cairo.h" 23#include "cairo.h"
24#include "log.h" 24#include "log.h"
25#include "loop.h" 25#include "loop.h"
26#include "readline.h"
27#include "stringop.h" 26#include "stringop.h"
28#include "util.h" 27#include "util.h"
29#include "wlr-input-inhibitor-unstable-v1-client-protocol.h" 28#include "wlr-input-inhibitor-unstable-v1-client-protocol.h"
@@ -808,36 +807,32 @@ static int load_config(char *path, struct swaylock_state *state,
808 wlr_log(WLR_ERROR, "Failed to read config. Running without it."); 807 wlr_log(WLR_ERROR, "Failed to read config. Running without it.");
809 return 0; 808 return 0;
810 } 809 }
811 char *line; 810 char *line = NULL;
811 size_t line_size = 0;
812 ssize_t nread;
812 int line_number = 0; 813 int line_number = 0;
813 while (!feof(config)) { 814 int result = 0;
814 line = read_line(config); 815 while ((nread = getline(&line, &line_size, config)) != -1) {
815 if (!line) {
816 continue;
817 }
818
819 line_number++; 816 line_number++;
820 if (line[0] == '#') { 817
821 free(line); 818 if (line[nread - 1] == '\n') {
822 continue; 819 line[--nread] = '\0';
823 } 820 }
824 if (strlen(line) == 0) { 821
825 free(line); 822 if (!*line || line[0] == '#') {
826 continue; 823 continue;
827 } 824 }
828 825
829 wlr_log(WLR_DEBUG, "Config Line #%d: %s", line_number, line); 826 wlr_log(WLR_DEBUG, "Config Line #%d: %s", line_number, line);
830 char flag[strlen(line) + 3]; 827 char flag[nread + 3];
831 sprintf(flag, "--%s", line); 828 sprintf(flag, "--%s", line);
832 char *argv[] = {"swaylock", flag}; 829 char *argv[] = {"swaylock", flag};
833 int result = parse_options(2, argv, state, line_mode, NULL); 830 result = parse_options(2, argv, state, line_mode, NULL);
834 if (result != 0) { 831 if (result != 0) {
835 free(line); 832 break;
836 fclose(config);
837 return result;
838 } 833 }
839 free(line);
840 } 834 }
835 free(line);
841 fclose(config); 836 fclose(config);
842 return 0; 837 return 0;
843} 838}