summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c26
1 files changed, 12 insertions, 14 deletions
diff --git a/main.c b/main.c
index 5c21817..60f1a96 100644
--- a/main.c
+++ b/main.c
@@ -882,18 +882,9 @@ static char *get_config_path(void) {
SYSCONFDIR "/swaylock/config",
};
- if (!getenv("XDG_CONFIG_HOME")) {
- char *home = getenv("HOME");
- char *config_home = malloc(strlen(home) + strlen("/.config") + 1);
- if (!config_home) {
- swaylock_log(LOG_ERROR, "Unable to allocate $HOME/.config");
- } else {
- strcpy(config_home, home);
- strcat(config_home, "/.config");
- setenv("XDG_CONFIG_HOME", config_home, 1);
- swaylock_log(LOG_DEBUG, "Set XDG_CONFIG_HOME to %s", config_home);
- free(config_home);
- }
+ char *config_home = getenv("XDG_CONFIG_HOME");
+ if (!config_home || config_home[0] == '\0') {
+ config_paths[1] = "$HOME/.config/swaylock/config";
}
wordexp_t p;
@@ -936,10 +927,17 @@ static int load_config(char *path, struct swaylock_state *state,
}
swaylock_log(LOG_DEBUG, "Config Line #%d: %s", line_number, line);
- char flag[nread + 3];
+ char *flag = malloc(nread + 3);
+ if (flag == NULL) {
+ free(line);
+ free(config);
+ swaylock_log(LOG_ERROR, "Failed to allocate memory");
+ return 0;
+ }
sprintf(flag, "--%s", line);
char *argv[] = {"swaylock", flag};
result = parse_options(2, argv, state, line_mode, NULL);
+ free(flag);
if (result != 0) {
break;
}
@@ -970,7 +968,7 @@ static void comm_in(int fd, short mask, void *data) {
int main(int argc, char **argv) {
swaylock_log_init(LOG_ERROR);
- initialize_pw_backend();
+ initialize_pw_backend(argc, argv);
enum line_mode line_mode = LM_LINE;
state.args = (struct swaylock_args){