From cb6a279f69b143f8c2e0545b9d43567568101cda Mon Sep 17 00:00:00 2001 From: Kubat <mael.martin31@gmail.com> Date: Wed, 14 Dec 2022 21:53:10 +0100 Subject: [PATCH] FIX: Try to handle correctly the config detection if XDG_CONFIG_HOME is defined in the env... --- CHANGELOG.md | 1 + src/base/config.c | 25 +++++++++++++++---------- src/main/lkt.c | 12 +++++++++--- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a076b214..9eed8d37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - Add: the regex used to populate the database from disk is now modifiable from the config file, the keys are `database/{types,categories,languages}`. Those fields must only contain alpha characters and commas - Add: re-use more informations from databases when upgrading the database because minimal version where added to the different fields in the table descriptions - Add: new field `repo_timestamp` which is the timestamp of the kara from the repo. This field is defaulted to the `cached_mtime` at upgrade time if needed +- Fix: Correctly reading the `XDG_CONFIG_HOME` variable if present in the env... - Fix: fix incorrect parsing of lists of commands with multiple arguments: the parser could overrun the correct command buffer and insert a '\0' between the next command and its furst argument - Fix: fix issue #100 -> the `database_queue_add_id` won't add ids that doesn't exist - Fix: be explicit about truncated commands, when a command is truncated, all the bytes after the end of the new string and before the end of the old string are not set to '\0' for safety diff --git a/src/base/config.c b/src/base/config.c index 824a5da3..495c1b94 100644 --- a/src/base/config.c +++ b/src/base/config.c @@ -199,16 +199,20 @@ config_default_file(char *dest, size_t len) /* First try the XDG_CONFIG_HOME variable, else the default location HOME/.config. */ memset(dest, 0, len * sizeof(char)); char *home = getenv("XDG_CONFIG_HOME"); - if (NULL == home || strlen(home) >= len) { - LOG_DEBUG("CONFIG", "No env variable XDG_CONFIG_HOME"); + if ((NULL == home) || (strlen(home) >= len)) { + LOG_DEBUG("CONFIG", "No env variable XDG_CONFIG_HOME, try to use HOME"); home = getenv("HOME"); - if (NULL == home) + if ((NULL == home) || (strlen(home) >= len)) { LOG_FATAL("Failed to get home folder for user, will now exit"); - safe_strncpy(dest, home, len); - strncat(dest, "/.config/lektor/lektor.ini", len - 1); - LOG_DEBUG("CONFIG", "Use '%s' insted of XDG_CONFIG_HOME", home); - } else - strncat(dest, "/lektor/lektor.ini", len - 1); + } + LOG_DEBUG("CONFIG", "Using HOME: %s", home); + } else { + LOG_DEBUG("CONFIG", "Using XDG_CONFIG_HOME: %s", home); + } + safe_strncpy(dest, home, len); + strncat(dest, "/.config/lektor/lektor.ini", len - 1); + LOG_DEBUG("CONFIG", "Use '%s' insted of XDG_CONFIG_HOME", home); + strncat(dest, "/lektor/lektor.ini", len - 1); } PRIVATE_FUNCTION int @@ -347,11 +351,12 @@ retry_config: config_default_file(conf_file, conf_len); ___mkdir(conf_file); /* Create the folder for the file. */ - errno = 0; + errno = 0; FILE *file_desc = fopen(conf_file, "w+"); if (file_desc != NULL) { LOG_ERROR("INIT", "Failed to open default config file and initialize it"); - LOG_ERROR("INTI", "Conf file is %s, errno is %d: %s", conf_file, errno, strerror(errno)); + LOG_ERROR("INTI", "Conf file is %s, errno is %d: %s", conf_file, errno, + strerror(errno)); return 1; } config_default(file_desc); diff --git a/src/main/lkt.c b/src/main/lkt.c index 020bf39e..af5ef3f7 100644 --- a/src/main/lkt.c +++ b/src/main/lkt.c @@ -459,8 +459,11 @@ rescan_or_update__(struct cmd_args *args, const char *cmd) exit(EXIT_SUCCESS); } -#define ___just_send_with_password(func, cmd) \ - PRIVATE_FUNCTION EXIT_FUNCTION func(struct cmd_args *args) { rescan_or_update__(args, cmd); } \ +#define ___just_send_with_password(func, cmd) \ + PRIVATE_FUNCTION EXIT_FUNCTION func(struct cmd_args *args) \ + { \ + rescan_or_update__(args, cmd); \ + } \ // clang-format off ___just_send_with_password(rescan__, "rescan"); ___just_send_with_password(update__, "update"); @@ -1207,7 +1210,10 @@ redo: } #define search_with_cmd(func, cmd) /* I don't want to write always the same things */ \ - PRIVATE_FUNCTION EXIT_FUNCTION func(struct cmd_args *args) { search_with_cmd__(args, #cmd); } + PRIVATE_FUNCTION EXIT_FUNCTION func(struct cmd_args *args) \ + { \ + search_with_cmd__(args, #cmd); \ + } // clang-format off search_with_cmd(search_db__, search); search_with_cmd(search_count__, count); -- GitLab