diff --git a/inc/lektor/common.h b/inc/lektor/common.h index 68ff134fc708913b471b416ecd3f4a5a96d8e5bf..5bef07403a52bdc8122c4513ec818e265c552c4a 100644 --- a/inc/lektor/common.h +++ b/inc/lektor/common.h @@ -88,10 +88,11 @@ enum log_level { }; extern enum log_level __log_level; void __lkt_log(enum log_level, const char *section, const char *func, const char *format, ...); +#define LOG_DEBUG(section, ...) __lkt_log(DEBUG, section, __func__, __VA_ARGS__) #define LOG_INFO( section, ...) __lkt_log(INFO, section, __func__, __VA_ARGS__) #define LOG_WARN( section, ...) __lkt_log(WARN, section, __func__, __VA_ARGS__) #define LOG_ERROR(section, ...) __lkt_log(ERROR, section, __func__, __VA_ARGS__) -#define LOG_DEBUG(section, ...) __lkt_log(DEBUG, section, __func__, __VA_ARGS__) +#define LOG_FATAL(...) { __lkt_log(ERROR, "FATAL", __func__, __VA_ARGS__); exit(1); } #define SELF_EXECUTABLE_LINUX "/proc/self/exe" #define SELF_EXECUTABLE_FREEBSD "/proc/curproc/file" diff --git a/src/base/commands.c b/src/base/commands.c index 8a58e442fa3b9cf18d808fec402842233f9df872..8dc78f9a64973491eb63dd574ca4f8fe794fcf47 100644 --- a/src/base/commands.c +++ b/src/base/commands.c @@ -89,8 +89,7 @@ command_kill(struct lkt_state *srv, size_t c, char UNUSED *argv[LKT_MESSAGE_ARGS { RETURN_UNLESS(lkt_client_auth(srv, c, false), "Failed to authentificate user", false); srv->__signal_INT(srv); - LOG_ERROR("FATAL", "The SIGINT handler returned, now exiting"); - exit(EXIT_FAILURE); + LOG_FATAL("The SIGINT handler returned, now exiting"); } bool diff --git a/src/base/config.c b/src/base/config.c index 274b4f1fbc6d05e44c7f058dabf431085b2928ac..3dd1b39d5661c9e9ced8ffa3dea485f78bbcec90 100644 --- a/src/base/config.c +++ b/src/base/config.c @@ -175,10 +175,8 @@ config_default_file(char *dest, size_t len) if (NULL == home || strlen(home) >= len) { LOG_DEBUG("CONFIG", "No env variable XDG_CONFIG_HOME"); home = getenv("HOME"); - if (NULL == home) { - LOG_ERROR("FATAL", "Failed to get home folder for user, will now exit"); - exit(EXIT_FAILURE); - } + if (NULL == home) + 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); diff --git a/src/main/server.c b/src/main/server.c index bc09e26dcb92accca3fb3a31e114f6760f3173e5..310ed274b2dcdf39ba6b3505455f63747e042329 100644 --- a/src/main/server.c +++ b/src/main/server.c @@ -160,11 +160,8 @@ retry_config: config_default_file(conf_file, PATH_MAX); __mkdir(conf_file); /* Create the folder for the file. */ FILE *file_desc = fopen(conf_file, "w+"); - if (NULL == file_desc) { - LOG_ERROR("FATAL", "Failed to open default config file '%s' to initialize it", - conf_file); - exit(EXIT_FAILURE); - } + if (NULL == file_desc) + LOG_FATAL("Failed to open default config file '%s' to initialize it", conf_file); config_default(file_desc); fclose(file_desc); LOG_INFO("INIT", "Default configuration file has been writen to %s", conf_file); diff --git a/src/net/listen.c b/src/net/listen.c index f73458c5d71d78bd6b77e8cc17e3572b9493b0ae..7374433046d13baf48a78954cfef4cbffbe29d1f 100644 --- a/src/net/listen.c +++ b/src/net/listen.c @@ -980,10 +980,8 @@ lkt_listen(struct lkt_state *srv) srv->fds_len = 1; srv->start_date = time(NULL); - if (srv->start_date == (time_t) -1) { - LOG_ERROR("FATAL", "Overflow or error on call to time function"); - exit(EXIT_FAILURE); - } + if (srv->start_date == (time_t) -1) + LOG_FATAL("Overflow or error on call to time function"); /* Listen */ for (;;) {