diff --git a/inc/common/macro.h b/inc/common/macro.h index da56e358042a2cbb3ce8579e1ac7fffdf0ef58d9..99e756c10b7dc822b57e7852296c5d1944394d7a 100644 --- a/inc/common/macro.h +++ b/inc/common/macro.h @@ -22,47 +22,50 @@ #define MIN(a, b) ((a) > (b) ? (b) : (a)) #endif /* MIN */ -#define RETURN_IF(cond, msg, ret) \ - if (cond) { \ - LOG_ERROR("%s", msg); \ - return ret; \ +#define RETURN_IF(cond, msg, ret) \ + if (cond) { \ + LOG_ERROR("", "%s", msg); \ + return ret; \ } -#define GOTO_IF(cond, msg, label) \ - if (cond) { \ - LOG_ERROR("%s", msg); \ - goto label; \ +#define GOTO_IF(cond, msg, label) \ + if (cond) { \ + LOG_ERROR("", "%s", msg); \ + goto label; \ } #define GOTO_UNLESS(cond, msg, label) GOTO_IF(!(cond), msg, label) #define RETURN_UNLESS(cond, msg, ret) RETURN_IF(!(cond), msg, ret) #define NOTHING /* Usefull to return nothing. */ -#define STRTOL(ret, str, endptr, err_flag) \ -{ \ - err_flag = 0; \ - errno = 0; \ - ret = str == NULL ? 0 : strtol(str, &(endptr), 0); \ - err_flag = errno != 0 || endptr == str; \ +#define STRTOL(ret, str, endptr, err_flag) \ +{ \ + err_flag = 0; \ + errno = 0; \ + ret = str == NULL ? 0 : strtol(str, &(endptr), 0); \ + err_flag = errno != 0 || endptr == str; \ } -#define ERROR 1 -#define WARN 2 -#define INFO 3 -#define DEBUG 4 -#define LOG(format, level, section, ...) \ - fprintf(stderr, " %c %s%s: " format "\n", \ - level == ERROR ? '!' : level == WARN ? '*' : level == INFO ? '.' : ' ', \ - sizeof(section) > sizeof("") ? ("[" section "] ") : "", \ - __func__, \ - __VA_ARGS__) -#define LOG_INFO_SCT(section, format, ...) LOG(format, INFO, section, __VA_ARGS__) -#define LOG_WARN_SCT(section, format, ...) LOG(format, WARN, section, __VA_ARGS__) -#define LOG_ERROR_SCT(section, format, ...) LOG(format, ERROR, section, __VA_ARGS__) -#define LOG_DEBUG_SCT(section, format, ...) LOG(format, DEBUG, section, __VA_ARGS__) -#define LOG_INFO(format, ...) LOG_INFO_SCT("", format, __VA_ARGS__) -#define LOG_WARN(format, ...) LOG_WARN_SCT("", format, __VA_ARGS__) -#define LOG_ERROR(format, ...) LOG_DEBUG_SCT("", format, __VA_ARGS__) -#define LOG_DEBUG(format, ...) LOG_DEBUG_SCT("", format, __VA_ARGS__) +extern int log_level; +enum log_level { + ERROR = 1, + WARN = 2, + INFO = 3, + DEBUG = 4, +}; + +#define LOG(format, level, section, ...) \ + { \ + if (level <= log_level) \ + fprintf(stderr, " %c %s%s: " format "\n", \ + level == ERROR ? '!' : level == WARN ? '*' : level == INFO ? '.' : ' ', \ + sizeof(section) > sizeof("") ? ("[" section "] ") : "", \ + __func__, \ + __VA_ARGS__); \ + } +#define LOG_INFO(section, format, ...) LOG(format, INFO, section, __VA_ARGS__) +#define LOG_WARN(section, format, ...) LOG(format, WARN, section, __VA_ARGS__) +#define LOG_ERROR(section, format, ...) LOG(format, ERROR, section, __VA_ARGS__) +#define LOG_DEBUG(section, format, ...) LOG(format, DEBUG, section, __VA_ARGS__) /* Defines for lektor */ @@ -129,43 +132,43 @@ typedef volatile enum { #define SQLITE_PREPARE(db, stmt, SQL, goto_label) \ if (sqlite3_prepare_v2((sqlite3 *) db, SQL, -1, &(stmt), 0) != SQLITE_OK) { \ - LOG_ERROR_SCT("DB", "Failed to prepare statement: %s", \ + LOG_ERROR("DB", "Failed to prepare statement: %s", \ sqlite3_errmsg((sqlite3 *) db)); \ goto goto_label; \ } #define SQLITE_EXEC(db, SQL, goto_label) \ if (sqlite3_exec((sqlite3 *) db, SQL, NULL, NULL, NULL) != SQLITE_OK) { \ - LOG_ERROR_SCT("DB", "Failed to exec statement: %s", \ + LOG_ERROR("DB", "Failed to exec statement: %s", \ sqlite3_errmsg((sqlite3 *) db)); \ goto goto_label; \ } -#define SQLITE_BIND_TEXT(db, stmt, pos, text, error) \ - if (sqlite3_bind_text(stmt, pos, text, -1, 0) != SQLITE_OK) { \ - LOG_ERROR_SCT("DB", "Failed to bind text %s at pos %d: %s", \ - text, pos, sqlite3_errmsg((sqlite3 *) db)); \ - goto error; \ +#define SQLITE_BIND_TEXT(db, stmt, pos, text, error) \ + if (sqlite3_bind_text(stmt, pos, text, -1, 0) != SQLITE_OK) { \ + LOG_ERROR("DB", "Failed to bind text %s at pos %d: %s", \ + text, pos, sqlite3_errmsg((sqlite3 *) db)); \ + goto error; \ } -#define SQLITE_BIND_INT(db, stmt, pos, integer, error) \ - if (sqlite3_bind_int(stmt, pos, integer) != SQLITE_OK) { \ - LOG_ERROR_SCT("DB", "Failed to bind int %d at pos %d: %s", \ - integer, pos, sqlite3_errmsg((sqlite3 *) db)); \ - goto error; \ +#define SQLITE_BIND_INT(db, stmt, pos, integer, error) \ + if (sqlite3_bind_int(stmt, pos, integer) != SQLITE_OK) { \ + LOG_ERROR("DB", "Failed to bind int %d at pos %d: %s", \ + integer, pos, sqlite3_errmsg((sqlite3 *) db));\ + goto error; \ } -#define SQLITE_STEP(db, stmt, code, error) \ - if (sqlite3_step(stmt) != code) { \ - LOG_ERROR_SCT("DB", "Failed to step: %s", \ - sqlite3_errmsg((sqlite3 *) db)); \ - goto error; \ +#define SQLITE_STEP(db, stmt, code, error) \ + if (sqlite3_step(stmt) != code) { \ + LOG_ERROR("DB", "Failed to step: %s", \ + sqlite3_errmsg((sqlite3 *) db)); \ + goto error; \ } #define SQLITE_STEP_ROW(db, stmt, error) SQLITE_STEP(db, stmt, SQLITE_ROW, error) #define SQLITE_STEP_DONE(db, stmt, error) SQLITE_STEP(db, stmt, SQLITE_DONE, error) -#define SQLITE_DO_ROLLBACK(db) \ +#define SQLITE_DO_ROLLBACK(db) \ sqlite3_exec((sqlite3 *) db, "ROLLBACK TRANSACTION;\n", NULL, NULL, NULL); #define STR_MATCH(str1, str2) (! strcasecmp(str1, str2)) diff --git a/inc/lektor/window.h b/inc/lektor/window.h index 05acc72917fc40239486831289075d60fd738935..462f9fa7a5fc052fc896c6a7453d57307c6164a2 100644 --- a/inc/lektor/window.h +++ b/inc/lektor/window.h @@ -18,9 +18,9 @@ struct lkt_win { struct lkt_state *srv; /* The server, must be set before the new call */ /* Create and free the window */ - bool (*new)(struct lkt_win *win); /* Create a window or only the mpv context */ - void (*close)(struct lkt_win *win); /* Close the mpv context, not the window */ - void (*free)(struct lkt_win *win); /* Entirelly liberate all the resources */ + bool (*new)(struct lkt_win *win); /* Create a window or only the mpv context */ + void (*close)(struct lkt_win *win); /* Close the mpv context, not the window */ + void (*free)(struct lkt_win *win); /* Entirelly liberate all the resources */ /* Playback control */ bool (*toggle_pause)(struct lkt_win *win); @@ -32,5 +32,6 @@ struct lkt_win { bool (*get_elapsed)(struct lkt_win *win, int *elapsed_sec); /* Handle loop event */ - bool (*handle_events)(struct lkt_win *win, volatile sqlite3 *db, mpd_idle_flag *mpd_idle_events); + bool (*handle_events)(struct lkt_win *win, volatile sqlite3 *db, + mpd_idle_flag *mpd_idle_events); }; diff --git a/src/cmd.c b/src/cmd.c index d1a1893d9374a3ecb11bd03c775f93491f574e63..4f19b19519eafe19127bb3c2dc7245c35e0ebd85 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -67,14 +67,14 @@ not_found: it->call(&arguments); } - LOG_ERROR_SCT("COMMAND", "Command '%s' could not be found", argv[0]); + LOG_ERROR("COMMAND", "Command '%s' could not be found", argv[0]); exit(EXIT_FAILURE); help: help__(); not_exclusive: - LOG_ERROR_SCT("COMMAND", "Failed to determine option, '%s' not exclusive", - argv[0]); + LOG_ERROR("COMMAND", "Failed to determine option, '%s' not exclusive", + argv[0]); exit(EXIT_FAILURE); } diff --git a/src/commands.c b/src/commands.c index d2db41c8adccebea328565ec7007798edc2e0c18..a4b34dba0172ee2f7eb35c07706c8e64f748f4b2 100644 --- a/src/commands.c +++ b/src/commands.c @@ -26,7 +26,7 @@ command_restart(struct lkt_state *srv, size_t c) struct lkt_queue_state sta = {0}; RETURN_UNLESS(lkt_client_auth(srv, c, false), "Failed to authentificate user", false); if (!executable_name) { - LOG_ERROR_SCT("GENERAL", "%s", "Can't restart if the executable path was not found at start-up"); + LOG_ERROR("GENERAL", "%s", "Can't restart if the executable path was not found at start-up"); return false; } close(srv->fds[0].fd); @@ -41,13 +41,13 @@ command_restart(struct lkt_state *srv, size_t c) env_set(LKT_ENV_CURRENT, pos); free(pos); } else - LOG_WARN_SCT("GENERAL", "Failed to malloc, don't set %s to %d", - LKT_ENV_CURRENT, sta.current); + LOG_WARN("GENERAL", "Failed to malloc, don't set %s to %d", + LKT_ENV_CURRENT, sta.current); } else env_set(LKT_ENV_CURRENT, "NULL"); database_close_all(); execv(executable_name, (char *const *) argv); - LOG_ERROR_SCT("GENERAL", "%s", "Failed to exec lektor or OS not supported"); + LOG_ERROR("GENERAL", "%s", "Failed to exec lektor or OS not supported"); return false; } @@ -88,7 +88,7 @@ inline bool command_kill(struct lkt_state *srv, size_t c) { RETURN_UNLESS(lkt_client_auth(srv, c, false), "Failed to authentificate user", false); - LOG_INFO_SCT("GENERAL", "%s", "Stopping lektord"); + LOG_INFO("GENERAL", "%s", "Stopping lektord"); close(srv->fds[0].fd); lkt_queue_free(&srv->queue); database_close_all(); @@ -105,7 +105,7 @@ command_currentsong(struct lkt_state *srv, size_t c) memset(&kara, 0, sizeof(struct kara_metadata)); if (!database_queue_current_kara(srv->db, &kara, NULL)) - LOG_ERROR_SCT("COMMAND", "%s", "Failed to get information about the current kara"); + LOG_ERROR("COMMAND", "%s", "Failed to get information about the current kara"); out = lkt_message_new(); idx = safe_snprintf(out->data, LKT_MESSAGE_MAX, @@ -259,7 +259,7 @@ command_add(volatile sqlite3 *db, struct lkt_win *win, char *args[LKT_MESSAGE_AR ret = database_queue_add_uri(db, &uri, priority); lkt_uri_free(&uri); if (!ret) - LOG_ERROR_SCT("COMMAND", "Failed to add with priority %d in queue", priority); + LOG_ERROR("COMMAND", "Failed to add with priority %d in queue", priority); return ret; } @@ -307,13 +307,13 @@ command_delid(volatile sqlite3 *db, struct lkt_win *win, char *id_str, mpd_idle_ if (id == (long) uri) { if (database_queue_skip_current(db, filepath)) { if (!win->load_file(win, filepath)) { - LOG_ERROR_SCT("COMMAND", "Failed to skip current kara to delete id %ld", id); + LOG_ERROR("COMMAND", "Failed to skip current kara to delete id %ld", id); return false; } } else { - LOG_WARN_SCT("COMMAND", "Failed to skip current kara to delete id %ld, stop playback", id); + LOG_WARN("COMMAND", "Failed to skip current kara to delete id %ld, stop playback", id); win->close(win); } } @@ -390,7 +390,7 @@ command_idle(struct lkt_state *srv, size_t c, struct lkt_command *cmd) if (!once) lkt_client_add_mask(srv, c, MPD_IDLE_ALL); - LOG_INFO_SCT("COMMAND", "Idle mask for client number %ld is 0x%X", c, lkt_client_get_mask(srv, c)); + LOG_INFO("COMMAND", "Idle mask for client number %ld is 0x%X", c, lkt_client_get_mask(srv, c)); return true; } @@ -484,7 +484,7 @@ command_find(struct lkt_state *srv, size_t c, char *cmd_args[LKT_MESSAGE_ARGS_MA if (count) lkt_set_continuation(srv, c, continuation + count); else - LOG_WARN_SCT("COMMAND", "%s", "Nothing found"); + LOG_WARN("COMMAND", "%s", "Nothing found"); return true; } @@ -527,7 +527,7 @@ command_set_playback_option(struct lkt_state *srv, size_t c, enum lkt_playback_o break; case lkt_playback_option_volume: ret = database_config_queue(srv->db, "volume", val); - LOG_INFO_SCT("COMMAND", "Set volume to %ld", val); + LOG_INFO("COMMAND", "Set volume to %ld", val); ret &= win->set_volume(win, val); srv->mpd_idle_events |= MPD_IDLE_MIXER; break; @@ -565,12 +565,12 @@ command_plt_add(volatile sqlite3 *db, char *args[LKT_MESSAGE_ARGS_MAX], mpd_idle else { if (!lkt_uri_from(&uri, args[1])) { - LOG_ERROR_SCT("COMMAND", "%s", "Failed to get uri"); + LOG_ERROR("COMMAND", "%s", "Failed to get uri"); goto end_plt_add_uri; } else if (!database_plt_add_uri(db, args[0], &uri)) { - LOG_ERROR_SCT("COMMAND", "Failed to add uri '%s' to playlist", args[1]); + LOG_ERROR("COMMAND", "Failed to add uri '%s' to playlist", args[1]); goto end_plt_add_uri; } @@ -628,7 +628,7 @@ command_plt_export(volatile sqlite3 *db, char *args[LKT_MESSAGE_ARGS_MAX], mpd_i RETURN_UNLESS(database_attach(db, args[0], args[1]), "Failed to attach database", false); RETURN_UNLESS(database_plt_export(db, args[0]), "Failed to export playlist", false); RETURN_UNLESS(database_detach(db, args[0]), "Failed to detach database", false); - LOG_INFO_SCT("COMMAND", "Exported playlist %s with path '%s'", args[0], args[1]); + LOG_INFO("COMMAND", "Exported playlist %s with path '%s'", args[0], args[1]); *watch_mask_ptr |= MPD_IDLE_PLAYLIST; return true; } @@ -640,7 +640,7 @@ command_plt_import(volatile sqlite3 *db, char *args[LKT_MESSAGE_ARGS_MAX], mpd_i RETURN_UNLESS(database_attach(db, args[0], args[1]), "Failed to attach database", false); RETURN_UNLESS(database_plt_import(db, args[0]), "Failed to import playlist", false); RETURN_UNLESS(database_detach(db, args[0]), "Failed to detach playlist", false); - LOG_INFO_SCT("COMMAND", "Imported playlist %s with path '%s'", args[0], args[1]); + LOG_INFO("COMMAND", "Imported playlist %s with path '%s'", args[0], args[1]); *watch_mask_ptr |= MPD_IDLE_PLAYLIST; return true; } @@ -701,7 +701,7 @@ command_queue_list(struct lkt_state *srv, size_t c, char *args[LKT_MESSAGE_ARGS_ tmp_switch = to; to = from; from = tmp_switch; - LOG_INFO_SCT("COMMAND", "Switch range values wrong order, now %d:%d", from, to); + LOG_INFO("COMMAND", "Switch range values wrong order, now %d:%d", from, to); } goto is_a_range; @@ -717,11 +717,11 @@ only_one: /* The command is used with a range specifier. */ is_a_range: if (to - from + 1 < lkt_remaining_msg(srv, c) - 2) { - LOG_INFO_SCT("COMMAND", "Got range %d:%d, no continuation needed", from, to); + LOG_INFO("COMMAND", "Got range %d:%d, no continuation needed", from, to); lkt_set_continuation(srv, c, 0); return database_queue_list(srv->db, from, to, &callback); } else { - LOG_INFO_SCT("COMMAND", "Got range %d:%d, continuation needed", from, to); + LOG_INFO("COMMAND", "Got range %d:%d, continuation needed", from, to); to = from + lkt_remaining_msg(srv, c) - 3; lkt_set_continuation(srv, c, to + 1); return database_queue_list(srv->db, from, to, &callback); @@ -761,13 +761,13 @@ sticker_send(struct lkt_state *srv, size_t c, char *name, char *type, int id, in bool command_sticker_create(struct lkt_state *srv, size_t c, char *argv[LKT_MESSAGE_ARGS_MAX]) { - LOG_INFO_SCT("COMMAND", "Client %ld is using the sticker create command", c); + LOG_INFO("COMMAND", "Client %ld is using the sticker create command", c); RETURN_UNLESS(argv[0], "Invalid argument", false); if (!database_sticker_create(srv->db, argv[0])) { - LOG_ERROR_SCT("COMMAND", "Failed to create sticker '%s'", argv[0]); + LOG_ERROR("COMMAND", "Failed to create sticker '%s'", argv[0]); return false; } - LOG_INFO_SCT("COMMAND", "Created sticker '%s'", argv[0]); + LOG_INFO("COMMAND", "Created sticker '%s'", argv[0]); return true; } @@ -780,7 +780,7 @@ command_sticker_set(struct lkt_state *srv, size_t c, char *argv[LKT_MESSAGE_ARGS STRTOL(uri, argv[1], endptr, err1); STRTOL(value, argv[3], endptr, err2); RETURN_IF(err1 || err2, "STRTOL failed", false); - LOG_INFO_SCT("COMMAND", "Client %ld is using the sticker set command", c); + LOG_INFO("COMMAND", "Client %ld is using the sticker set command", c); RETURN_UNLESS(database_sticker_set(srv->db, argv[0], argv[2], uri, value), "Failed to get sticker", false); srv->mpd_idle_events |= MPD_IDLE_STICKER; return true; @@ -789,7 +789,7 @@ command_sticker_set(struct lkt_state *srv, size_t c, char *argv[LKT_MESSAGE_ARGS bool command_sticker_get(struct lkt_state *srv, size_t c, char *argv[LKT_MESSAGE_ARGS_MAX]) { - LOG_INFO_SCT("COMMAND", "Client %ld is using the sticker get command", c); + LOG_INFO("COMMAND", "Client %ld is using the sticker get command", c); struct lkt_search callback = { .srv = srv, .c = c, @@ -840,14 +840,14 @@ command_sticker_get(struct lkt_state *srv, size_t c, char *argv[LKT_MESSAGE_ARGS return true; unknown: - LOG_ERROR_SCT("COMMAND", "%s", "Specified command is invalid or unknown"); + LOG_ERROR("COMMAND", "%s", "Specified command is invalid or unknown"); return false; } bool command_sticker_delete(struct lkt_state *srv, size_t c, char *argv[LKT_MESSAGE_ARGS_MAX]) { - LOG_INFO_SCT("COMMAND", "Client %ld is using the sticker delete command", c); + LOG_INFO("COMMAND", "Client %ld is using the sticker delete command", c); RETURN_UNLESS(argv[0] && argv[1] && argv[2], "Invalid argument", false); int uri = atoi(argv[1]); srv->mpd_idle_events |= MPD_IDLE_STICKER; @@ -857,7 +857,7 @@ command_sticker_delete(struct lkt_state *srv, size_t c, char *argv[LKT_MESSAGE_A bool command_sticker_destroy(struct lkt_state *srv, size_t c, char *argv[LKT_MESSAGE_ARGS_MAX]) { - LOG_INFO_SCT("COMMAND", "Client %ld is using the sticker destroy command", c); + LOG_INFO("COMMAND", "Client %ld is using the sticker destroy command", c); RETURN_UNLESS(argv[0], "Invalid argument", false); return database_sticker_delete(srv->db, argv[0]); } diff --git a/src/common.c b/src/common.c index 77cade8430718724a2bf9a4090d90515886b1848..cc7dd77b7bc4b3fae7c0afd2112db61c8c9de9c0 100644 --- a/src/common.c +++ b/src/common.c @@ -8,11 +8,13 @@ #include <stdarg.h> #include <sys/stat.h> +int log_level = 0; /* None by default */ + void __not_implemented(const char *func, char *file, int line) { - LOG_ERROR_SCT("GENERAL", "Function %s in file %s at line %d not " - "implemented", func, file, line); + LOG_ERROR("GENERAL", "Function %s in file %s at line %d not " + "implemented", func, file, line); abort(); } @@ -146,8 +148,8 @@ safe_malloc(size_t size) void *tmp; tmp = malloc(size); if (!tmp) { - LOG_ERROR_SCT("GENERAL", "Out of memory, can't alloc " - "'%ld' Bytes", size); + LOG_ERROR("GENERAL", "Out of memory, can't alloc " + "'%ld' Bytes", size); exit(1); } return tmp; diff --git a/src/config.c b/src/config.c index 62cb508507c5b17f4a99b73f71ea2fb593d6317e..647bb9e0e3b9b70771164a943c1a567a424bf66c 100644 --- a/src/config.c +++ b/src/config.c @@ -6,6 +6,7 @@ #include <lektor/net.h> #include <lektor/reg.h> +#include <strings.h> #include <stdlib.h> #include <errno.h> #include <string.h> @@ -46,6 +47,34 @@ handler(volatile sqlite3 *user, const char *section, const char *name, return 0; } +static inline void +__set_log_level(const char *name, const char *level) +{ + if (!STR_MATCH(name, "log")) { + LOG_WARN("CONFIG", "Invalid option '%s[:=]%s' with no section", + name, level); + return; + } + + if (!level[0]) { + LOG_WARN("CONFIG", "%s", "Invalid empty 'log' option"); + return; + } + + if (STR_MATCH(level, "error")) + log_level = ERROR; + else if (STR_MATCH(level, "warn") || STR_MATCH(level, "warning")) + log_level = WARN; + else if (STR_MATCH(level, "info")) + log_level = INFO; + else if (STR_MATCH(level, "debug")) + log_level = DEBUG; + else + log_level = strtol(level, NULL, 0); + + LOG_INFO("CONFIG", "Log level set to %d", log_level); +} + static inline int ini_parse(const char *path, volatile sqlite3 *db) { @@ -54,10 +83,13 @@ ini_parse(const char *path, volatile sqlite3 *db) int error = 0, linenum = 0, len; FILE *file = fopen(path, "r"); if (!file) { - LOG_ERROR_SCT("PARSER", "Failed to open config file '%s'", path); + LOG_ERROR("PARSER", "Failed to open config file '%s'", path); return 1; } + memset(section, 0, INI_MAX_SECTION_LEN); + memset(line, 0, INI_MAX_LINE_LEN); + /* Parse the file */ while (NULL != fgets(line, INI_MAX_LINE_LEN, file)) { ++linenum; @@ -80,8 +112,8 @@ ini_parse(const char *path, volatile sqlite3 *db) else { error = 1; - LOG_ERROR_SCT("PARSER", "Invalid section name at line '%d'", - linenum); + LOG_ERROR("PARSER", "Invalid section name at line '%d'", + linenum); } } @@ -102,19 +134,24 @@ ini_parse(const char *path, volatile sqlite3 *db) value = skip(value); strip(value); - /* Handle the SECTION, NAME[:=]VALUE */ - if (handler(db, section, name, value)) { - error = 1; - LOG_ERROR_SCT("PARSER", "Failed to '[handle] %s, " + /* Handle the SECTION, NAME[:=]VALUE + The only option that has no SECTION is the log level: + log[:=]ERROR|WARN|INFO|DEBUG|\d+ */ + if (section[0]) { + if (handler(db, section, name, value)) { + error = 1; + LOG_ERROR("PARSER", "Failed to '[handle] %s, " "%s{:,=}%s' at line '%d'", section, name, value, linenum); - } + } + } else + __set_log_level(name, value); } else { error = 1; - LOG_ERROR_SCT("PARSER", "Invalid name[:=]value pair at " - "line '%d'", linenum); + LOG_ERROR("PARSER", "Invalid name[:=]value pair at " + "line '%d'", linenum); } } } @@ -122,8 +159,8 @@ ini_parse(const char *path, volatile sqlite3 *db) /* End of the function */ fclose(file); if (error) - LOG_ERROR_SCT("PARSER", "An error occured while parsing the " - "file '%s'", path); + LOG_ERROR("PARSER", "An error occured while parsing the " + "file '%s'", path); return error; } @@ -142,7 +179,7 @@ config_detect_file(char *conf, size_t conf_len) /* Try the current working dir config file. */ if (getcwd(conf, conf_len - 1) != NULL) { strncat(conf, "/lektor.ini", conf_len - 1); - LOG_INFO("Trying %s", conf); + LOG_INFO("CONFIG", "Trying %s", conf); if (!access(conf, R_OK | F_OK)) goto found; } @@ -164,7 +201,7 @@ config_detect_file(char *conf, size_t conf_len) memcpy(conf, home, (strlen(home) + 1) * sizeof(char)); strncat(conf, "/.config/lektor/lektor.ini", conf_len - 1); skip_this_strcat: - LOG_INFO("Trying %s", conf); + LOG_INFO("CONFIG", "Trying %s", conf); if (!access(conf, R_OK | F_OK)) goto found; @@ -172,30 +209,31 @@ no_config_directory: /* Try the '/opt/lektor' file. */ memcpy(conf, "/opt/lektor/lektor.ini", sizeof("/opt/lektor/lektor.ini")); - LOG_INFO("Trying %s", conf); + LOG_INFO("CONFIG", "Trying %s", conf); if (!access(conf, R_OK | F_OK)) goto found; /* Try the '/usr/local/etc/lektor.ini' file. */ memcpy(conf, "/usr/local/etc/lektor.ini", sizeof("/usr/local/etc/lektor.ini")); - LOG_INFO("Trying %s", conf); + LOG_INFO("CONFIG", "Trying %s", conf); if (!access(conf, R_OK | F_OK)) goto found; /* Try the '/etc/lektor.ini' file. */ memcpy(conf, "/etc/lektor.ini", sizeof("/etc/lektor.ini")); - LOG_INFO("Trying %s", conf); + LOG_INFO("CONFIG", "Trying %s", conf); if (!access(conf, R_OK | F_OK)) goto found; /* Error */ - LOG_ERROR("An error occured with file %s: %s", conf, strerror(errno)); + LOG_ERROR("CONFIG", "An error occured with file %s: %s", + conf, strerror(errno)); if (is_malloc) free(conf); return 1; found: - LOG_INFO("Using file %s", conf); + LOG_INFO("CONFIG", "Using file %s", conf); return 0; } @@ -203,18 +241,18 @@ int config_new(volatile sqlite3 *db, const char *conf) { if (ini_parse(conf, db)) { - LOG_ERROR_SCT("CONFIG", "Failed to parse file %s", conf); + LOG_ERROR("CONFIG", "Failed to parse file %s", conf); goto error; } if (!database_validate_conf(db)) { - LOG_ERROR_SCT("CONFIG", "Configuration file %s is incomplete", conf); + LOG_ERROR("CONFIG", "Configuration file %s is incomplete", conf); goto error; } return 0; error: - LOG_ERROR_SCT("CONFIG", "%s", "Errors detected, here is a default config"); + LOG_ERROR("CONFIG", "%s", "Errors detected, here is a default config"); config_default(stdout); return 1; } diff --git a/src/database/config.c b/src/database/config.c index 098377b2abd0cf7b80b51fb37b1211d9417cddf9..ae0a1f9bbe7e8b45facbdbd3caf5c59ed7e16d61 100644 --- a/src/database/config.c +++ b/src/database/config.c @@ -27,8 +27,8 @@ database_config_set(volatile sqlite3 *db, const char *section, const char *key, code = sqlite3_step(stmt); if (code != SQLITE_OK && code != SQLITE_DONE) { - LOG_ERROR_SCT("DB", "Failed to insert or replace: %s", - sqlite3_errmsg((sqlite3 *) db)); + LOG_ERROR("DB", "Failed to insert or replace: %s", + sqlite3_errmsg((sqlite3 *) db)); goto error; } @@ -167,7 +167,7 @@ database_validate_conf(volatile sqlite3 *db) #define value_opt(name, value) #define value(name, value) \ if (!database_config_exists(db, section, name)) { \ - LOG_ERROR_SCT("CONFIG", "Missing option \""name"\" in section \"%s\"",\ + LOG_ERROR("CONFIG", "Missing option \""name"\" in section \"%s\"",\ section); \ return false; \ } diff --git a/src/database/find.c b/src/database/find.c index 41a1eac5e2fa9977417111591a8d73c1095cead5..ef8f475ae41df4990e29f008833d2bedeb8db70a 100644 --- a/src/database/find.c +++ b/src/database/find.c @@ -117,8 +117,8 @@ database_search_iter(struct lkt_search *item) goto end; if (code != SQLITE_ROW) { - LOG_ERROR_SCT("DB", "Step failed, expected a ROW or a DONE: %s", - sqlite3_errmsg((sqlite3 *) item->db)); + LOG_ERROR("DB", "Step failed, expected a ROW or a DONE: %s", + sqlite3_errmsg((sqlite3 *) item->db)); goto end; } @@ -139,7 +139,7 @@ database_search_iter(struct lkt_search *item) (item->srv, item->c, sql_row, type, id, code); case lkt_search_playlist: default: - LOG_WARN_SCT("DB", "Search type %d is not implemented", item->type); + LOG_WARN("DB", "Search type %d is not implemented", item->type); goto end; } diff --git a/src/database/open.c b/src/database/open.c index 9e06bc940daee6fb6a13f0142f02b2edefe5d02d..f82bbc7bef7ab111aaf349ae4400f4b6ae04a151 100644 --- a/src/database/open.c +++ b/src/database/open.c @@ -31,16 +31,16 @@ __dec(volatile sqlite3 *db, const char *name) safe_snprintf(SQL, LKT_MAX_SQLITE_STATEMENT, "UPDATE %s.misc SET opened = 0;", name); SQLITE_EXEC(db, SQL, error); - LOG_INFO_SCT("DB", "Dec open count on db '%s'", name); + LOG_INFO("DB", "Dec open count on db '%s'", name); return; error: - LOG_ERROR_SCT("DB", "%s", "Faield to close database"); + LOG_ERROR("DB", "%s", "Faield to close database"); } void database_close_all(void) { - LOG_INFO_SCT("GARBAGE", "%s", "Closing all db"); + LOG_INFO("GARBAGE", "%s", "Closing all db"); if (pthread_mutex_trylock(&mtx)) return; struct named_db *item; @@ -50,7 +50,7 @@ database_close_all(void) free((void *) item->name); free(item); } - LOG_INFO_SCT("GARBAGE", "%s", "All db closed"); + LOG_INFO("GARBAGE", "%s", "All db closed"); stack_free(&db_stack); } @@ -75,7 +75,7 @@ __inc(volatile sqlite3 *db, const char *name, bool check) exit(EXIT_FAILURE); return; error: - LOG_ERROR_SCT("DB", "%s", "Database already in use"); + LOG_ERROR("DB", "%s", "Database already in use"); if (check) exit(EXIT_FAILURE); __dec(db, name); @@ -117,7 +117,7 @@ __attach(volatile sqlite3 *db, const char *name, const char *path) safe_snprintf(SQL_ATTACH, LKT_MAX_SQLITE_STATEMENT, SQL_ATTACH_TEMPLATE, path, name); SQLITE_EXEC(db, SQL_ATTACH, err_no_attach); - LOG_INFO_SCT("DB", "Attached database '%s' with path '%s'", name, path); + LOG_INFO("DB", "Attached database '%s' with path '%s'", name, path); ret = true; err_no_attach: return ret; @@ -133,7 +133,7 @@ __detach(volatile sqlite3 *db, const char *name) safe_snprintf(SQL_DETACH, LKT_MAX_SQLITE_STATEMENT, SQL_DETACH_TEMPLATE, name); SQLITE_EXEC(db, SQL_DETACH, err_no_detach); - LOG_INFO_SCT("DB", "Detached database '%s'", name); + LOG_INFO("DB", "Detached database '%s'", name); ret = true; err_no_detach: return ret; @@ -155,7 +155,7 @@ __check_schema(volatile sqlite3 *db) if (9 != sqlite3_column_int(stmt, 0)) return true; error: - LOG_ERROR_SCT("DB", "%s", "Schema is invalid: missing tables"); + LOG_ERROR("DB", "%s", "Schema is invalid: missing tables"); return false; } @@ -181,7 +181,7 @@ database_open(volatile sqlite3 *db, const char *dbpath, bool check) { bool retry = false; if (is_sql_str_invalid(dbpath)) { - LOG_ERROR("The database path '%s' is invalid", dbpath); + LOG_ERROR("DB", "The database path '%s' is invalid", dbpath); return false; } @@ -197,18 +197,18 @@ retry: /* Need init */ init: if (retry) { - LOG_ERROR_SCT("DB", "Retry to init database '%s', this is an error", - dbpath); + LOG_ERROR("DB", "Retry to init database '%s', this is an error", + dbpath); return false; } retry = true; - LOG_WARN_SCT("DB", "Database '%s' is not correctly initialized, init it", - dbpath); + LOG_WARN("DB", "Database '%s' is not correctly initialized, init it", + dbpath); __detach(db, PROTECTED_DATABASE) ; if (database_init(dbpath)) goto retry; else { - LOG_ERROR_SCT("DB", "Failed to init database '%s'", dbpath); + LOG_ERROR("DB", "Failed to init database '%s'", dbpath); return false; } } @@ -221,22 +221,22 @@ database_attach(volatile sqlite3 *db, const char *name, const char *dbpath) "database with the same name", false); if (is_sql_str_invalid(name)) { - LOG_ERROR("The database name '%s' is invalid", name); + LOG_ERROR("DB", "The database name '%s' is invalid", name); return false; } if (__is_attached(db, name)) { - LOG_ERROR("The database '%s' is already attached", name); + LOG_ERROR("DB", "The database '%s' is already attached", name); return false; } if (!__attach(db, name, dbpath)) { - LOG_ERROR_SCT("DB", "Failed to attach database named '%s' with " - "path '%s'", name, dbpath); + LOG_ERROR("DB", "Failed to attach database named '%s' with " + "path '%s'", name, dbpath); return false; } - LOG_INFO_SCT("DB", "Database '%s' attached", name); + LOG_INFO("DB", "Database '%s' attached", name); return true; } @@ -247,21 +247,21 @@ database_detach(volatile sqlite3 *db, const char *name) PROTECTED_DATABASE " is protected, can't detach it", false); if (is_sql_str_invalid(name)) { - LOG_ERROR("The database name '%s' is invalid", name); + LOG_ERROR("DB", "The database name '%s' is invalid", name); return false; } if (!__is_attached(db, name)) { - LOG_ERROR("The database '%s' is not attached", name); + LOG_ERROR("DB", "The database '%s' is not attached", name); return false; } if (!__detach(db, name)) { - LOG_ERROR_SCT("DB", "Failed to detach database named %s", name); + LOG_ERROR("DB", "Failed to detach database named %s", name); return false; } - LOG_INFO_SCT("DB", "Database '%s' detached", name); + LOG_INFO("DB", "Database '%s' detached", name); return true; } @@ -272,11 +272,11 @@ database_init(const char *dbpath) if (SQLITE_OK != sqlite3_open(dbpath, &db)) goto error; SQLITE_EXEC(db, (const char *) ___src_database_disk_sql, error); - LOG_INFO_SCT("DB", "Initialized the 'disk' database successfully, " - "path was '%s'", dbpath); + LOG_INFO("DB", "Initialized the 'disk' database successfully, " + "path was '%s'", dbpath); return true; error: - LOG_ERROR_SCT("DB", "Failed to init the 'disk' database, path was '%s'", - dbpath); + LOG_ERROR("DB", "Failed to init the 'disk' database, path was '%s'", + dbpath); return false; } diff --git a/src/database/playlist.c b/src/database/playlist.c index 1c80ced4d5c6d505a98cbcc4c8b11e23d80bbdde..61b0abf7acf810024fdbc143643c27b31b0b3ce3 100644 --- a/src/database/playlist.c +++ b/src/database/playlist.c @@ -106,7 +106,7 @@ database_plt_export(volatile sqlite3 *db, const char *name) sqlite3_stmt *stmt = NULL; if (is_sql_str_invalid(name)) { - LOG_ERROR("The playlist name '%s' is invalid", name); + LOG_ERROR("DB", "The playlist name '%s' is invalid", name); goto error; } @@ -119,8 +119,8 @@ database_plt_export(volatile sqlite3 *db, const char *name) code = sqlite3_step(stmt); if (code != SQLITE_DONE && code != SQLITE_OK) { - LOG_ERROR_SCT("DB", "Failed to create schema: %s", - sqlite3_errmsg((sqlite3 *) db)); + LOG_ERROR("DB", "Failed to create schema: %s", + sqlite3_errmsg((sqlite3 *) db)); goto error; } @@ -142,7 +142,7 @@ database_plt_import(volatile sqlite3 *db, const char *name) char SQL_STMT[LKT_MAX_SQLITE_STATEMENT], ret = false; if (is_sql_str_invalid(name)) { - LOG_ERROR("The playlist name '%s' is invalid", name); + LOG_ERROR("DB", "The playlist name '%s' is invalid", name); goto error; } diff --git a/src/database/queue.c b/src/database/queue.c index ed6ddc6f5882527407c52c9fd4d858bfa2b0eec3..a6f9e36b0ea9d7674c666192b180d15de648f752 100644 --- a/src/database/queue.c +++ b/src/database/queue.c @@ -115,12 +115,12 @@ error: return ret; } -#define reorder(db, prio, error) \ - if (prio > 1) { \ - if (__queue_reorder(db)) \ - LOG_INFO_SCT("DB", "%s", "Queue has been reordered"); \ - else \ - goto error; \ +#define reorder(db, prio, error) \ + if (prio > 1) { \ + if (__queue_reorder(db)) { \ + LOG_INFO("DB", "%s", "Queue has been reordered"); \ + } else \ + goto error; \ } static bool @@ -282,8 +282,8 @@ database_queue_add_uri(volatile sqlite3 *db, struct lkt_uri *uri, int priority) case uri_playlist: return database_queue_add_plt(db, (char *) uri->value, priority); default: - LOG_WARN_SCT("DB", "Add to queue for uri of type %d is not" - " implemented", uri->type); + LOG_WARN("DB", "Add to queue for uri of type %d is not" + " implemented", uri->type); return false; } } @@ -343,19 +343,19 @@ database_queue_next(volatile sqlite3 *db, char filepath[PATH_MAX]) if (filepath != NULL) strncpy(filepath, sqlite3_column_chars(stmt, 0), PATH_MAX); else { - LOG_ERROR_SCT("DB", "Failed to get file, id was %d", id); + LOG_ERROR("DB", "Failed to get file, id was %d", id); goto error; } } else if (code == SQLITE_DONE) { - LOG_ERROR_SCT("DB", "%s", "Failed to get next"); + LOG_ERROR("DB", "%s", "Failed to get next"); goto error; } else { - LOG_ERROR_SCT("DB", "Failed to fetch next kara: %s", - sqlite3_errmsg((sqlite3 *) db)); + LOG_ERROR("DB", "Failed to fetch next kara: %s", + sqlite3_errmsg((sqlite3 *) db)); goto error; } @@ -407,19 +407,19 @@ database_queue_prev(volatile sqlite3 *db, char filepath[PATH_MAX]) if (filepath != NULL) strncpy(filepath, sqlite3_column_chars(stmt, 0), PATH_MAX); else { - LOG_ERROR_SCT("DB", "Failed to get file, position was %d", id); + LOG_ERROR("DB", "Failed to get file, position was %d", id); goto error; } } else if (code == SQLITE_DONE) { - LOG_ERROR_SCT("DB", "%s", "Failed to get previous"); + LOG_ERROR("DB", "%s", "Failed to get previous"); goto error; } else { - LOG_ERROR_SCT("DB", "Failed to fetch prev kara: %s", - sqlite3_errmsg((sqlite3 *) db)); + LOG_ERROR("DB", "Failed to fetch prev kara: %s", + sqlite3_errmsg((sqlite3 *) db)); goto error; } @@ -455,7 +455,7 @@ database_queue_move(volatile sqlite3 *db, int from, int to) code = sqlite3_step(stmt); if (code != SQLITE_ROW && code != SQLITE_DONE && code != SQLITE_OK) { - LOG_ERROR_SCT("DB", "%s", "Move failed"); + LOG_ERROR("DB", "%s", "Move failed"); goto error; } @@ -481,8 +481,8 @@ database_queue_play(volatile sqlite3 *db, int pos) code = sqlite3_step(stmt); if (code != SQLITE_OK && code != SQLITE_DONE) { - LOG_ERROR_SCT("DB", "Failed to update queue_state: %s", - sqlite3_errmsg((sqlite3 *) db)); + LOG_ERROR("DB", "Failed to update queue_state: %s", + sqlite3_errmsg((sqlite3 *) db)); goto error; } @@ -499,7 +499,7 @@ database_queue_set_current_index(volatile sqlite3 *db, int idx) char SQL_GET[LKT_MAX_SQLITE_STATEMENT]; if (idx <= 0) { - LOG_ERROR_SCT("DB", "An idx of %d is invalid, must be >= 0", idx); + LOG_ERROR("DB", "An idx of %d is invalid, must be >= 0", idx); return false; } @@ -535,8 +535,8 @@ database_queue_get_current_file(volatile sqlite3 *db, char filepath[PATH_MAX]) } else { - LOG_ERROR_SCT("DB", "Failed to fetch prev kara: %s", - sqlite3_errmsg((sqlite3 *) db)); + LOG_ERROR("DB", "Failed to fetch prev kara: %s", + sqlite3_errmsg((sqlite3 *) db)); goto error; } @@ -650,7 +650,7 @@ database_queue_list(volatile sqlite3 *db, size_t from, size_t to, goto done; else { - LOG_ERROR_SCT("DB", "Failed: %s", sqlite3_errmsg((sqlite3 *) db)); + LOG_ERROR("DB", "Failed: %s", sqlite3_errmsg((sqlite3 *) db)); break; } } diff --git a/src/database/stickers.c b/src/database/stickers.c index dc37fcbe44765bdc194665a04cdb5d9d4b5b43e3..bc3bb3dc8dc6be66342a10429534380c2c40d650 100644 --- a/src/database/stickers.c +++ b/src/database/stickers.c @@ -66,7 +66,7 @@ database_sticker_set(volatile sqlite3 *db, const char *type, const char *name, int ret = false; if (__check_type(type)) { - LOG_ERROR_SCT("DB", "Type '%s' is invalid", type); + LOG_ERROR("DB", "Type '%s' is invalid", type); return false; } @@ -97,7 +97,7 @@ database_sticker_delete_specify(volatile sqlite3 *db, const char *type, sqlite3_stmt *stmt; int ret = false; if (__check_type(type)) { - LOG_ERROR_SCT("DB", "Type '%s' is invalid", type); + LOG_ERROR("DB", "Type '%s' is invalid", type); return false; } diff --git a/src/database/update.c b/src/database/update.c index 3a7f539a912da2cdc65102647b7937b1607eebf5..d2fe7e5f4a288e3824617e4f0ee3b1278694565b 100644 --- a/src/database/update.c +++ b/src/database/update.c @@ -60,7 +60,7 @@ __database_add_kara(volatile sqlite3 *db, const char *filename) /* Metadata */ if (kara_metadata_read(&data, filename) != 0) { - LOG_ERROR("Failed to get mdt for the kara '%s'", filename); + LOG_ERROR("UPDATE", "Failed to get mdt for the kara '%s'", filename); return false; } @@ -76,7 +76,7 @@ __database_add_kara(volatile sqlite3 *db, const char *filename) STRTOL(kara_id, id, token, id_len); if (!id_len && STR_MATCH(&token[1], "mkv")) { /* Use the found id, most of the time, normally */ - LOG_INFO_SCT("DB", "Found id '%ld' in kara '%s'", kara_id, filename); + LOG_INFO("DB", "Found id '%ld' in kara '%s'", kara_id, filename); SQLITE_PREPARE(db, stmt, SQL_STMT_WITH_ID, error); SQLITE_BIND_INT(db, stmt, 10, (int) kara_id, error); } else { @@ -94,8 +94,8 @@ __database_add_kara(volatile sqlite3 *db, const char *filename) (sqlite3_bind_text(stmt, 8, data.author_name, -1, 0) != SQLITE_OK) || (sqlite3_bind_int (stmt, 9, data.song_number) != SQLITE_OK) ) { - LOG_ERROR_SCT("DB", "Failed to bind for kara %s: %s", filename, - sqlite3_errmsg((sqlite3 *) db)); + LOG_ERROR("DB", "Failed to bind for kara %s: %s", filename, + sqlite3_errmsg((sqlite3 *) db)); goto error; } SQLITE_STEP_DONE(db, stmt, error); @@ -125,7 +125,7 @@ database_update_set_available(volatile sqlite3 *db, int id) return true; error: sqlite3_finalize(stmt); - LOG_ERROR_SCT("DB", "Failed to set kara %d available", id); + LOG_ERROR("DB", "Failed to set kara %d available", id); return false; } @@ -164,7 +164,7 @@ database_update_add(volatile sqlite3 *db, const char *kara_path, (sqlite3_bind_int (stmt, 10, id) != SQLITE_OK) || (sqlite3_bind_int (stmt, 11, avail) != SQLITE_OK) ) { - LOG_ERROR_SCT("DB", "Failed to bind argument for kara %s: %s", kara_path, sqlite3_errmsg((sqlite3 *) db)); + LOG_ERROR("DB", "Failed to bind argument for kara %s: %s", kara_path, sqlite3_errmsg((sqlite3 *) db)); goto error; } @@ -185,8 +185,8 @@ database_update(volatile sqlite3 *db, const char *kara_dir, int check_timestamp) memset(path, 0, PATH_MAX * sizeof(char)); if (!(d = opendir(kara_dir))) { - LOG_ERROR_SCT("DB", "Failed to open directory '%s': %s", kara_dir, - strerror(errno)); + LOG_ERROR("DB", "Failed to open directory '%s': %s", kara_dir, + strerror(errno)); return false; } @@ -198,8 +198,8 @@ database_update(volatile sqlite3 *db, const char *kara_dir, int check_timestamp) if (dir->d_type == DT_REG) { database_get_update(db, &db_timestamp, NULL, NULL); if (check_timestamp && get_mtime(path) < db_timestamp) { - LOG_INFO_SCT("DB", "Skip update of kara '%s' be cause of " - "timestamps", path); + LOG_INFO("DB", "Skip update of kara '%s' be cause of " + "timestamps", path); continue; } __database_add_kara(db, path); @@ -212,7 +212,7 @@ database_update(volatile sqlite3 *db, const char *kara_dir, int check_timestamp) database_update(db, path, check_timestamp); } - LOG_INFO("Passed directory '%s'", kara_dir); + LOG_INFO("UPADTE", "Passed directory '%s'", kara_dir); database_updated(db); closedir(d); return true; @@ -264,8 +264,8 @@ database_get_update(volatile sqlite3 *db, long *timestamp, *current = sqlite3_column_int(stmt, 2); return; error: - LOG_WARN_SCT("DB", "Failed to get informations about the last update: %s", - sqlite3_errmsg((sqlite3 *) db)); + LOG_WARN("DB", "Failed to get informations about the last update: %s", + sqlite3_errmsg((sqlite3 *) db)); } void @@ -282,7 +282,7 @@ database_update_del(volatile sqlite3 *db, int id) SQLITE_PREPARE(db, stmt, SQL, error); SQLITE_BIND_INT(db, stmt, 1, id, error); SQLITE_STEP_DONE(db, stmt, error); - LOG_WARN_SCT("DB", "Deleted kara with id '%d' from database", id); + LOG_WARN("DB", "Deleted kara with id '%d' from database", id); error: return; } diff --git a/src/database/user.c b/src/database/user.c index c39bd88ca1c0735beec2adccbef5b9ae1909e4a4..1aa06bdb68f3acd328ed4b034cf469a3ef97b52f 100644 --- a/src/database/user.c +++ b/src/database/user.c @@ -14,8 +14,8 @@ database_user_authentificate(volatile sqlite3 *db, const char *password) SQLITE_PREPARE(db, stmt, SQL_STMT, error); SQLITE_BIND_TEXT(db, stmt, 1, password, error); SQLITE_STEP_ROW(db, stmt, error); - LOG_INFO_SCT("DB", "User authentification for '%s'", - sqlite3_column_text(stmt, 0)); + LOG_INFO("DB", "User authentification for '%s'", + sqlite3_column_text(stmt, 0)); ret = true; error: sqlite3_finalize(stmt); @@ -33,7 +33,7 @@ database_user_add(volatile sqlite3 *db, const char *username, const char *passwo SQLITE_BIND_TEXT(db, stmt, 1, username, error); SQLITE_BIND_TEXT(db, stmt, 2, password, error); SQLITE_STEP_DONE(db, stmt, error); - LOG_INFO_SCT("DB", "User '%s' successfully added", username); + LOG_INFO("DB", "User '%s' successfully added", username); ret = true; error: sqlite3_finalize(stmt); diff --git a/src/main/lkt.c b/src/main/lkt.c index 06349601d63e7ebbea8e53ea7348292d86b8b063..cc044f05a918122590e5dcac07e4e10e3c97e282 100644 --- a/src/main/lkt.c +++ b/src/main/lkt.c @@ -27,8 +27,8 @@ #include <limits.h> #define LKT_KEY_VALUE_SEP ": \n\t\0" -#define fail_if(cond, msg) { if (cond) { LOG_ERROR("%s", msg); exit(EXIT_FAILURE); } } -#define fail(msg) { LOG_ERROR("%s", msg); exit(EXIT_FAILURE); } +#define fail_if(cond, msg) { if (cond) { LOG_ERROR("LKT", "%s", msg); exit(EXIT_FAILURE); } } +#define fail(msg) { LOG_ERROR("LKT", "%s", msg); exit(EXIT_FAILURE); } #define exit_with_status(sock, buff) { \ read_socket(sock, buff, 2); \ @@ -903,7 +903,7 @@ static struct lkt_cmd_opt options_[] = { static void sigpipe__(int sig) { - LOG_ERROR_SCT("GENERAL", "Exit because of signal sigpipe (%d)", sig); + LOG_ERROR("GENERAL", "Exit because of signal sigpipe (%d)", sig); exit(EXIT_FAILURE); } @@ -941,6 +941,7 @@ parse_args(args_t *args, int argc, const char **argv) int main(int argc, const char **argv) { + log_level = ERROR; executable_name = "lkt"; assert(NULL != setlocale(LC_ALL, "en_US.UTF-8")); /* BECAUSE! */ assert(!signal(SIGPIPE, sigpipe__)); diff --git a/src/main/server.c b/src/main/server.c index 29ff8e20e029f50753716296f4585e2fe13fa5c6..5f760ed573a062778686b636141b51fc6845cd22 100644 --- a/src/main/server.c +++ b/src/main/server.c @@ -66,16 +66,12 @@ main(int argc, char *argv[]) } normal_launch: - LOG_INFO_SCT("GENERAL", "Lektor launched by user %s (shell: %s, home: %s)", - pw->pw_name, pw->pw_shell, pw->pw_dir); - if (env_get(LKT_ENV_RESTART)) - LOG_INFO_SCT("GENERAL", "%s", "Lektord has been restarted"); reg_set(server_reg); mthread_init(); pthread_create(&th, NULL, mthread_main, NULL); if (read_self_exe(exe, PATH_MAX)) - LOG_WARN_SCT("GENERAL", "%s", "Failed to read self executable path, " - "restart may not work"); + LOG_WARN("GENERAL", "%s", "Failed to read self executable path, " + "restart may not work"); executable_name = exe; /* Init the server */ @@ -85,23 +81,23 @@ normal_launch: .kara_prefix = kara_dir, }; if (lkt_queue_new(&srv.queue)) { - LOG_ERROR_SCT("INIT", "%s", "Faield to create server queue"); + LOG_ERROR("INIT", "%s", "Faield to create server queue"); exit(EXIT_FAILURE); } /* Initialize the system. */ if (!database_new(&srv.db)) { - LOG_ERROR_SCT("INIT", "%s", "Failed to init memory db"); + LOG_ERROR("INIT", "%s", "Failed to init memory db"); exit(EXIT_FAILURE); } if (conf_file[0] == '\0' && config_detect_file(conf_file, PATH_MAX)) { - LOG_ERROR_SCT("INIT", "%s", "Failed to find a config file"); + LOG_ERROR("INIT", "%s", "Failed to find a config file"); exit(EXIT_FAILURE); } if (config_new(srv.db, conf_file)) { - LOG_ERROR_SCT("INIT", "%s", "Failed to read the config"); + LOG_ERROR("INIT", "%s", "Failed to read the config"); exit(EXIT_FAILURE); } free(conf_file); @@ -132,10 +128,14 @@ normal_launch: /* Not working -> race condition with player module */ char *env_current = env_get(LKT_ENV_CURRENT); if (env_current && env_current[0] && !STR_MATCH(env_current, "NULL")) { - LOG_INFO_SCT("INIT", "Restart playback from %s", env_current); + LOG_INFO("INIT", "Restart playback from %s", env_current); lkt_queue_send(&srv.queue, lkt_event_play_pos, (void *) (size_t) strtol(env_current, NULL, 0)); } + LOG_INFO("GENERAL", "Lektor was %s, user: %s, shell: %s, home: %s", + env_get(LKT_ENV_RESTART) ? "restarted" : "started", + pw->pw_name, pw->pw_shell, pw->pw_dir); + lkt_listen(&srv); return EXIT_FAILURE; } diff --git a/src/mkv/utils.c b/src/mkv/utils.c index 2e21974189e2420e0a99cf04eff2b5fd00974e8f..cb9fb643b76e0dab4d9d52af1c159dc25d2461d6 100644 --- a/src/mkv/utils.c +++ b/src/mkv/utils.c @@ -16,7 +16,7 @@ mdtcat(struct kara_metadata *mdt, char **ret) long_length(mdt->song_number); *ret = malloc(sizeof(char) * size); if (!*ret) { - LOG_ERROR_SCT("MKV", "%s", "Out of memory"); + LOG_ERROR("MKV", "%s", "Out of memory"); return; } diff --git a/src/mkv/write.c b/src/mkv/write.c index 66dab3b44bf920edc66132cc26df0097c14e0a5b..0999ac11fb4cec4a481554c5585541cd85f3b37a 100644 --- a/src/mkv/write.c +++ b/src/mkv/write.c @@ -66,14 +66,14 @@ mkvpropedit__(const char *const args[]) if ((pid = fork()) == 0) { if ((fd = open("/dev/null", O_WRONLY | O_TRUNC)) < 0) { - LOG_ERROR_SCT("FORK", "%s", "Can't to open /dev/null " - "in O_WRONLY O_TRUNC"); + LOG_ERROR("FORK", "%s", "Can't to open /dev/null " + "in O_WRONLY O_TRUNC"); return false; } if (dup2(fd, 1) < 0) { - LOG_ERROR_SCT("FORK", "%s", "Failed to duplicate " - "/dev/null to stdout"); + LOG_ERROR("FORK", "%s", "Failed to duplicate " + "/dev/null to stdout"); return false; } @@ -82,21 +82,21 @@ mkvpropedit__(const char *const args[]) } else if (pid < 0) { - LOG_ERROR_SCT("FORK", "Failed to fork: %s\n", strerror(errno)); + LOG_ERROR("FORK", "Failed to fork: %s\n", strerror(errno)); return false; } else { do { if (waitpid(pid, &wstatus, WUNTRACED | WCONTINUED) == -1) { - LOG_ERROR_SCT("FORK", "Failed to wait children: %s", - strerror(errno)); + LOG_ERROR("FORK", "Failed to wait children: %s", + strerror(errno)); return false; } } while (!WIFEXITED(wstatus) && !WIFSIGNALED(wstatus)); if ((status = WEXITSTATUS(wstatus))) { - LOG_ERROR_SCT("FORK", "Children failed with status %d", status); + LOG_ERROR("FORK", "Children failed with status %d", status); return false; } } @@ -118,14 +118,16 @@ kara_metadata_write(struct kara_metadata *mdt, const char *filename, strncat(tmpfilepath, "all:/tmp/lektor.metadata.XXXXXX", PATH_MAX - 1); if ((fd = mkstemp(metadafilepath)) < 0) { - LOG_ERROR("Failed to create temporary file: %s", strerror(errno)); + LOG_ERROR("WRITER", "Failed to create temporary file: %s", + strerror(errno)); goto error; } if (dprintf(fd, METADATA_TEMPLATE, mdt->source_name, mdt->song_name, mdt->category, mdt->language, mdt->author_name, mdt->song_type, mdt->song_number) < 0) { - LOG_ERROR("Failed to write to temporary file: %s", metadafilepath); + LOG_ERROR("WRITER", "Failed to write to temporary file: %s", + metadafilepath); goto error; } @@ -156,7 +158,7 @@ metadata_from_path(char *const mkvfile, struct kara_metadata *meta) "(.+) - (OP|ED|IS|AMV|VOCA|PV|MV|LIVE)([[:digit:]]*) - (.+)\\.mkv$"; if (!regex_init && regcomp(®ex, rgx, REG_EXTENDED)) { - LOG_ERROR_SCT("MPV", "%s", "Failed to compile regex"); + LOG_ERROR("MPV", "%s", "Failed to compile regex"); goto error; } @@ -174,11 +176,11 @@ metadata_from_path(char *const mkvfile, struct kara_metadata *meta) memcpy(msgbuf, mkvfile + pmatch[7].rm_so, pmatch[7].rm_eo - pmatch[7].rm_so); memcpy(meta->song_name, mkvfile + pmatch[8].rm_so, pmatch[8].rm_eo - pmatch[8].rm_so); } else if (REG_NOMATCH == reti) { - LOG_ERROR("No match for: %s", mkvfile); + LOG_ERROR("WRITER", "No match for: %s", mkvfile); goto error; } else { regerror(reti, ®ex, msgbuf, sizeof(msgbuf)); - LOG_ERROR("Failed to execute regex: %s", msgbuf); + LOG_ERROR("WRITER", "Failed to execute regex: %s", msgbuf); goto error; } @@ -202,7 +204,7 @@ metadata_set_directory(const char *kara_dir, const char *mkvpropedit) memset(path, 0, PATH_MAX * sizeof(char)); if (!(d = opendir(kara_dir))) { - LOG_ERROR("Failed to open directory '%s': %s", kara_dir, + LOG_ERROR("WRITER", "Failed to open directory '%s': %s", kara_dir, strerror(errno)); return 1; } @@ -222,7 +224,7 @@ metadata_set_directory(const char *kara_dir, const char *mkvpropedit) metadata_set_directory(path, mkvpropedit); } - LOG_INFO("Passed directory '%s'", kara_dir); + LOG_INFO("WRITER", "Passed directory '%s'", kara_dir); closedir(d); return false; } diff --git a/src/module/module_sdl2.c b/src/module/module_sdl2.c index 120ce9680049c67fbfb8cbe5eb9ca60c16131cd0..faa121c1cb841b147a873f168ed6b4d8ea49a4fb 100644 --- a/src/module/module_sdl2.c +++ b/src/module/module_sdl2.c @@ -92,7 +92,7 @@ init_mpv_gl__(mpv_handle *mpv, mpv_render_context **mpv_gl, wakeup_on_mpv_events = SDL_RegisterEvents(1); if (wakeup_on_mpv_render_update == (Uint32) - 1 || wakeup_on_mpv_events == (Uint32) - 1) { - LOG_ERROR_SCT("WINDOW", "%s", "Failed to register event"); + LOG_ERROR("WINDOW", "%s", "Failed to register event"); return 1; } @@ -154,7 +154,7 @@ sdl_thread__(struct poller_thread_arg *arg) while (!sdl2->launched) sched_yield(); - LOG_INFO_SCT("WINDOW", "%s", "Started SDL thread"); + LOG_INFO("WINDOW", "%s", "Started SDL thread"); loop: SDL_WaitEvent(&event); @@ -226,7 +226,7 @@ loop: (uint64_t) str, cmd); } } else - LOG_ERROR_SCT("WINDOW", "Not handled text '%s'", event.text.text); + LOG_ERROR("WINDOW", "Not handled text '%s'", event.text.text); break; default: @@ -355,6 +355,7 @@ module_sdl2_free(struct lkt_win *const win) sdl2->launched = 2; while (sdl2->launched) sched_yield(); + poller_join(&sdl2->self, NULL); } bool diff --git a/src/module/module_x11.c b/src/module/module_x11.c index 9c10b1f480e556035f16fbd84ee1662eb5bd2390..14d7a5adb4ec10abdaef920e03c30b8dcbf67029 100644 --- a/src/module/module_x11.c +++ b/src/module/module_x11.c @@ -154,7 +154,7 @@ lx11_handle(struct module_x11_window *win) // Key press if (event.type == KeyRelease) { - LOG_INFO_SCT("WINDOW", "Release key: 0x%x", event.xkey.keycode); + LOG_INFO("WINDOW", "Release key: 0x%x", event.xkey.keycode); if (event.xkey.keycode == 0x47) XClearWindow(win->master_display, win->master_win); } @@ -190,7 +190,7 @@ module_x11_new(struct lkt_win *const win) memset(x11_win, 0, sizeof(struct module_x11_window)); RETURN_UNLESS(x11_win, "Out of memory", false); RETURN_UNLESS(lx11_new(x11_win), "Can't create X11 window", false); - LOG_INFO_SCT("WINDOW", "%s", "Created the X11 window"); + LOG_INFO("WINDOW", "%s", "Created the X11 window"); } if (x11_win->mpv == NULL) { diff --git a/src/module/mpv.c b/src/module/mpv.c index 3eceb8cf5af9be6534fbd120567b5a40bc130b7c..06763230a2e673f62054c8b7238d0dd48d633167 100644 --- a/src/module/mpv.c +++ b/src/module/mpv.c @@ -18,7 +18,7 @@ lmpv_free(mpv_handle **ctx) mpv_command(*ctx, cmd); mpv_destroy(*ctx); *ctx = NULL; - LOG_INFO_SCT("WINDOW", "%s", "The mpv context was destroyed"); + LOG_INFO("WINDOW", "%s", "The mpv context was destroyed"); } mpv_handle * @@ -31,13 +31,13 @@ lmpv_prepare(volatile sqlite3 *db) #define MPV_SET_OPTION(opt, value) \ if ((status = mpv_set_option_string(ctx, opt, value)) < 0) { \ - LOG_ERROR_SCT("WINDOW", "Failed to set %s to %s: %s", \ + LOG_ERROR("WINDOW", "Failed to set %s to %s: %s", \ opt, value, mpv_error_string(status)); \ return NULL; \ } #define MPV_SET_FROM_INI(opt, section, key) \ if (!database_config_get_text(db, section, key, _opt, INI_MAX_LINE_LEN)) { \ - LOG_WARN_SCT("WINDOW", "%s", "Failed to get option " \ + LOG_WARN("WINDOW", "%s", "Failed to get option " \ key " in section " section); \ return ctx; \ } \ @@ -74,21 +74,21 @@ lmpv_new(unsigned long int wid, volatile sqlite3 *db) int status; if ((status = mpv_set_property(ctx, "wid", MPV_FORMAT_INT64, &wid)) < 0) { - LOG_ERROR_SCT("WINDOW", "Failed to set wid: %s", mpv_error_string(status)); + LOG_ERROR("WINDOW", "Failed to set wid: %s", mpv_error_string(status)); goto error; } if ((status = mpv_initialize(ctx)) < 0) { - LOG_ERROR_SCT("WINDOW", "Failed to init mpv: %s", mpv_error_string(status)); + LOG_ERROR("WINDOW", "Failed to init mpv: %s", mpv_error_string(status)); goto error; } if (!lmpv_observe_properties(ctx)) { - LOG_ERROR_SCT("WINDOW", "%s", "Failed to observe properties"); + LOG_ERROR("WINDOW", "%s", "Failed to observe properties"); goto error; } - LOG_INFO_SCT("WINDOW", "%s", "Create mpv context"); + LOG_INFO("WINDOW", "%s", "Create mpv context"); return ctx; error: lmpv_free(&ctx); @@ -105,7 +105,7 @@ lmpv_set_volume(mpv_handle *ctx, int vol) safe_snprintf(str, 4, "%d", vol); const char *cmd[] = {"set", "ao-volume", str, NULL}; if ((status = mpv_command_async(ctx, 0, cmd)) < 0) { - LOG_ERROR_SCT("WINDOW", "Failed to execute command: %s", mpv_error_string(status)); + LOG_ERROR("WINDOW", "Failed to execute command: %s", mpv_error_string(status)); return 1; } return 0; @@ -120,11 +120,11 @@ lmpv_load_file(mpv_handle *ctx, const char *file) const char *cmd2[] = { "set", "pause", "0", NULL }; int status; if ((status = mpv_command_async(ctx, 0, cmd1)) < 0) { - LOG_ERROR_SCT("WINDOW", "Failed to add '%s': %s", file, mpv_error_string(status)); + LOG_ERROR("WINDOW", "Failed to add '%s': %s", file, mpv_error_string(status)); return 1; } if ((status = mpv_command_async(ctx, 0, cmd2)) < 0) { - LOG_ERROR_SCT("WINDOW", "Failed to set state to play: %s", mpv_error_string(status)); + LOG_ERROR("WINDOW", "Failed to set state to play: %s", mpv_error_string(status)); return 1; } return 0; @@ -137,7 +137,7 @@ lmpv_toggle_pause(mpv_handle *ctx) const char *cmd[] = {"cycle", "pause", "up", NULL}; int status; if ((status = mpv_command_async(ctx, 0, cmd)) < 0) { - LOG_ERROR_SCT("WINDOW", "Failed issus command: %s", mpv_error_string(status)); + LOG_ERROR("WINDOW", "Failed issus command: %s", mpv_error_string(status)); return 1; } return 0; @@ -214,7 +214,7 @@ loop: break; default: - LOG_WARN_SCT("WINDOW", "Unhandled mpv event '%s'", mpv_event_name(event->event_id)); + LOG_WARN("WINDOW", "Unhandled mpv event '%s'", mpv_event_name(event->event_id)); break; } goto loop; /* A loop without indentation. */ diff --git a/src/module/repo.c b/src/module/repo.c index 5c08094c52665406058196bf86a1760fcf7822a1..f9b139114cbe82a2eee073fc2112a7aa2f5d4bcc 100644 --- a/src/module/repo.c +++ b/src/module/repo.c @@ -169,8 +169,8 @@ __json_sync(struct lkt_repo *const repo, struct json_object **json) res = curl_easy_perform(curl_handle); if (res != CURLE_OK) { - LOG_ERROR_SCT("CURL", "curl_easy_perform failed: %s", - curl_easy_strerror(res)); + LOG_ERROR("CURL", "curl_easy_perform failed: %s", + curl_easy_strerror(res)); free(file.mem); goto err; } @@ -206,8 +206,8 @@ repo_get_id(struct lkt_repo *const repo, const uint64_t id, curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0"); if (CURLE_OK != (res = curl_easy_perform(curl_handle))) { - LOG_ERROR_SCT("CURL", "curl_easy_perform failed: %s", - curl_easy_strerror(res)); + LOG_ERROR("CURL", "curl_easy_perform failed: %s", + curl_easy_strerror(res)); free(file.mem); curl_easy_cleanup(curl_handle); return 1; @@ -219,12 +219,12 @@ repo_get_id(struct lkt_repo *const repo, const uint64_t id, jobj = json_tokener_parse(file.mem); if (json_object_object_get_ex(jobj, "message", &field)) { - LOG_ERROR("Kara with id %lu not found, message is: %s", id, + LOG_ERROR("REPO", "Kara with id %lu not found, message is: %s", id, json_object_get_string(field)); goto err; } - LOG_INFO("Got kara with id %lu", id); + LOG_INFO("REPO", "Got kara with id %lu", id); err |= safe_json_get_string(jobj, "song_name", mdt->song_name, LEKTOR_TAG_MAX); err |= safe_json_get_string(jobj, "source_name", mdt->source_name, LEKTOR_TAG_MAX); err |= safe_json_get_string(jobj, "category", mdt->category, LEKTOR_TAG_MAX); @@ -250,12 +250,14 @@ __download_kara(const char *url, const char *path, int override) retest: if (fd < 0) { - if (errno == EEXIST && ! override) - LOG_ERROR("File '%s' already exists", path); + if (errno == EEXIST && ! override) { + LOG_ERROR("REPO", "File '%s' already exists", path); + return 1; + } else if (errno == EEXIST && override) { if (unlink(path)) { - LOG_ERROR_SCT("REPO", "Failed to unlink file '%s'", path); + LOG_ERROR("REPO", "Failed to unlink file '%s'", path); return 1; } @@ -264,10 +266,10 @@ retest: goto retest; } - else - LOG_ERROR("Could not open file '%s'", path); - - return 1; + else { + LOG_ERROR("REPO", "Could not open file '%s'", path); + return 1; + } } struct file file = { @@ -282,8 +284,8 @@ retest: curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0"); if (CURLE_OK != (ret = curl_easy_perform(curl_handle))) { - LOG_ERROR_SCT("CURL", "curl_easy_perform failed: %s", - curl_easy_strerror(ret)); + LOG_ERROR("CURL", "curl_easy_perform failed: %s", + curl_easy_strerror(ret)); goto err; } @@ -302,7 +304,7 @@ repo_download_id_sync(struct lkt_repo *const repo, const uint64_t id, char url[URL_MAX_LEN]; if (repo_get_id(repo, id, mdt_ret ? mdt_ret : &mdt)) { - LOG_ERROR("%s", "Failed to get kara metadata from kurisu"); + LOG_ERROR("REPO", "%s", "Failed to get kara metadata from kurisu"); return 1; } @@ -310,14 +312,14 @@ repo_download_id_sync(struct lkt_repo *const repo, const uint64_t id, safe_snprintf(url, URL_MAX_LEN, repo->get_id_file, id); if (__download_kara(url, kara_path, false)) { - LOG_ERROR_SCT("REPO", "Failed to download kara '%s' with url '%s'", - kara_path, url); + LOG_ERROR("REPO", "Failed to download kara '%s' with url '%s'", + kara_path, url); return 1; } if (repo->db && !database_update_add((sqlite3 *) repo->db, kara_path, mdt_ret ? mdt_ret : &mdt, id, true)) { - LOG_ERROR("%s", "Failed to add kara to database"); + LOG_ERROR("REPO", "%s", "Failed to add kara to database"); return 1; } @@ -345,7 +347,7 @@ __handle_got_json(volatile sqlite3 *db, struct lkt_repo *repo, mkvpropedit, PATH_MAX - 1), "Can't get the mkvpropedit executable path", NOTHING); - LOG_INFO_SCT("REPO", "Starting to process json for repo %s", repo->name); + LOG_INFO("REPO", "Starting to process json for repo %s", repo->name); for (i = 0; i < len; ++i) { kara_json = json_object_array_get_idx(json, i); err = 0; @@ -374,7 +376,7 @@ __handle_got_json(volatile sqlite3 *db, struct lkt_repo *repo, err |= safe_json_get_string(kara_json, "author_name", kara.mdt.author_name, LEKTOR_TAG_MAX); err |= safe_json_get_string(kara_json, "song_type", kara.mdt.song_type, LEKTOR_TAG_MAX); if (err || safe_json_get_int32(kara_json, "song_number", &kara.mdt.song_number)) { - LOG_WARN_SCT("REPO", "Json is invalid for kara '%ld', skip it", kara.id); + LOG_WARN("REPO", "Json is invalid for kara '%ld', skip it", kara.id); continue; } @@ -387,16 +389,16 @@ __handle_got_json(volatile sqlite3 *db, struct lkt_repo *repo, ! kara_metadata_equals(&kara.mdt, kara.filename)) { database_update_touch(db, kara.id); database_update_set_available(db, kara.id); - LOG_INFO_SCT("REPO", "Ignore kara '%ld' with path '%s'", - kara.id, kara.filename); + LOG_INFO("REPO", "Ignore kara '%ld' with path '%s'", + kara.id, kara.filename); continue; } current_id = 0; database_queue_current_kara(db, NULL, ¤t_id); if (current_id == (int) kara.id) { - LOG_WARN_SCT("REPO", "Update currently playing kara %d, skip it", - current_id); + LOG_WARN("REPO", "Update currently playing kara %d, skip it", + current_id); char *current_path = safe_malloc(PATH_MAX * sizeof(char)); database_queue_skip_current(db, current_path); srv->win.load_file(&srv->win, current_path); @@ -404,33 +406,33 @@ __handle_got_json(volatile sqlite3 *db, struct lkt_repo *repo, } if (!database_update_add(db, kara.filename, &kara.mdt, kara.id, false)) { - LOG_ERROR_SCT("REPO", "Could not add unavailable kara %ld to db", - kara.id); + LOG_ERROR("REPO", "Could not add unavailable kara %ld to db", + kara.id); continue; } safe_snprintf(url, URL_MAX_LEN, repo->get_id_file, kara.id); if (__download_kara(url, kara.filename, true)) { - LOG_WARN_SCT("REPO", "Could not download kara %ld at path '%s'", - kara.id, kara.filename); + LOG_WARN("REPO", "Could not download kara %ld at path '%s'", + kara.id, kara.filename); continue; } if (kara_metadata_write(&kara.mdt, kara.filename, mkvpropedit)) { - LOG_WARN_SCT("REPO", "Could not write metadata to kara '%ld' with " - "path '%s'", kara.id, kara.filename); + LOG_WARN("REPO", "Could not write metadata to kara '%ld' with " + "path '%s'", kara.id, kara.filename); continue; } if (!database_update_set_available(db, kara.id)) { - LOG_WARN_SCT("REPO", "Could not set kara %ld available", kara.id); + LOG_WARN("REPO", "Could not set kara %ld available", kara.id); continue; } database_stamp(db); - LOG_INFO_SCT("REPO", "Added kara %ld from repo %s, filepath is %s", - kara.id, repo->name, kara.filename); + LOG_INFO("REPO", "Added kara %ld from repo %s, filepath is %s", + kara.id, repo->name, kara.filename); } } @@ -454,14 +456,14 @@ __repo_get_all_id_async(void *arg) { struct json_object *json; struct lkt_repo *const repo = arg; - LOG_INFO_SCT("REPO", "Download kara list from %s (%s), directory is %s", - repo->name, repo->get_all_json, repo->kara_dir); + LOG_INFO("REPO", "Download kara list from %s (%s), directory is %s", + repo->name, repo->get_all_json, repo->kara_dir); __json_sync(repo, &json); __handle_got_json(repo->db, repo, json); - LOG_INFO_SCT("REPO", "%s", "Finished to download and insert kara list"); + LOG_INFO("REPO", "%s", "Finished to download and insert kara list"); json_object_put(json); __handle_deleted_kara(repo->db); - LOG_INFO_SCT("REPO", "%s", "Finished to deal with deleted kara"); + LOG_INFO("REPO", "%s", "Finished to deal with deleted kara"); database_updated(repo->db); return NULL; } diff --git a/src/mthread/mthread.c b/src/mthread/mthread.c index 561a779a0674e356bc535f02615f4201c91c54f2..3cd1d0ac2227e4deb4b93e90967dad36f471e787 100644 --- a/src/mthread/mthread.c +++ b/src/mthread/mthread.c @@ -185,7 +185,7 @@ mthread_idle_task(void *arg) done = 0; } } - LOG_INFO_SCT("SCHEDULER", "Virtual processor %d started", vp->rank); + LOG_INFO("SCHEDULER", "Virtual processor %d started", vp->rank); while (1) __mthread_yield(vp); not_implemented(); @@ -256,14 +256,14 @@ static void mthread_start_thread(void *arg) { struct mthread_s *mctx = (struct mthread_s *)arg; - LOG_INFO_SCT("THREAD", "Thread %p started", arg); + LOG_INFO("THREAD", "Thread %p started", arg); mthread_virtual_processor_t *vp = mthread_get_vp(); __mthread_yield(vp); mctx->res = mctx->__start_routine(mctx->arg); mctx->status = ZOMBIE; - LOG_INFO_SCT("THREAD", "Thread %p ended (%d)", arg, vp->rank); + LOG_INFO("THREAD", "Thread %p ended (%d)", arg, vp->rank); if (mctx->detached) { - LOG_INFO_SCT("THREAD", "Thread %p (vp: %d) was detached, join it", arg, vp->rank); + LOG_INFO("THREAD", "Thread %p (vp: %d) was detached, join it", arg, vp->rank); mthread_join(mctx, NULL); } vp = mthread_get_vp(); @@ -277,7 +277,7 @@ __mthread_lib_init(long i) { mthread_init_lib(i); virtual_processors[0].state = 1; - LOG_INFO_SCT("THREAD", "%s", "library started"); + LOG_INFO("THREAD", "%s", "library started"); } void @@ -318,7 +318,7 @@ mthread_create(mthread_t *__threadp, const mthread_attr_t __attr, void *(*__star mctx->detached = DETACHED_FREE; } - LOG_INFO_SCT("THREAD INIT", "Create thread %p", (void *) mctx); + LOG_INFO("THREAD INIT", "Create thread %p", (void *) mctx); mctx->arg = __arg; mctx->__start_routine = __start_routine; mthread_mctx_set(mctx, mthread_start_thread, stack, MTHREAD_DEFAULT_STACK, mctx); @@ -352,7 +352,7 @@ mthread_exit(void *__retval) struct mthread_s *mctx = (struct mthread_s *) vp->current; mctx->res = __retval; mctx->status = ZOMBIE; - LOG_INFO_SCT("THREAD END", "Thread %p exited", (void *) mctx); + LOG_INFO("THREAD END", "Thread %p exited", (void *) mctx); __mthread_yield(vp); } @@ -362,7 +362,7 @@ mthread_exit(void *__retval) int mthread_join(mthread_t __th, void **__thread_return) { - LOG_INFO_SCT("THREAD END", "Join thread %p", (void *) __th); + LOG_INFO("THREAD END", "Join thread %p", (void *) __th); while (__th->status != ZOMBIE) mthread_yield(); @@ -371,7 +371,7 @@ mthread_join(mthread_t __th, void **__thread_return) *__thread_return = (void *)__th->res; __mthread_clear_keys(&__th); - LOG_INFO_SCT("THREAD END", "Thread %p joined", (void *) __th); + LOG_INFO("THREAD END", "Thread %p joined", (void *) __th); mthread_insert_last(__th, &(joined_list)); return 0; } @@ -380,6 +380,6 @@ void mthread_yield() { mthread_virtual_processor_t *vp = mthread_get_vp(); - LOG_INFO_SCT("THREAD YIELD", "Thread %p yield", (void *) vp->current); + LOG_INFO("THREAD YIELD", "Thread %p yield", (void *) vp->current); __mthread_yield(vp); } diff --git a/src/mthread/mthread_cond.c b/src/mthread/mthread_cond.c index ba25bae0edf1343cd114e6d31ffb5e2ca502fc04..1956f4420e5c3bbae4a10546c247369b9e9d3c01 100644 --- a/src/mthread/mthread_cond.c +++ b/src/mthread/mthread_cond.c @@ -16,7 +16,7 @@ mthread_cond_init(mthread_cond_t *__cond, const mthread_condattr_t *__cond_attr) __cond->lock = 0; __cond->list = safe_malloc(sizeof(struct mthread_list_s)); memset(__cond->list, 0, sizeof(struct mthread_list_s)); - LOG_INFO("%s", "Successfully created a condition"); + LOG_INFO("MTHREAD", "%s", "Successfully created a condition"); return 0; } @@ -43,10 +43,12 @@ mthread_cond_signal(mthread_cond_t *__cond) vp = mthread_get_vp(); first->status = RUNNING; mthread_insert_last(first, &(vp->ready_list)); - LOG_INFO("Wake up the thread %p from the thread %p", (void *) first, (void *) self); + LOG_INFO("MTHREAD", "Wake up the thread %p from the thread %p", + (void *) first, (void *) self); ret = 0; } else - LOG_INFO("No thread to wake up found from the thread %p", (void *) self); + LOG_INFO("MTHREAD", "No thread to wake up found from the thread %p", + (void *) self); mthread_spinlock_unlock(&__cond->lock); return ret; @@ -64,7 +66,8 @@ mthread_cond_broadcast(mthread_cond_t *__cond) first = mthread_remove_first(__cond->list); vp = mthread_get_vp(); first->status = RUNNING; - LOG_INFO("Wake up the thread %p from the thread %p", (void *) first, (void *) self); + LOG_INFO("MTHREAD", "Wake up the thread %p from the thread %p", + (void *) first, (void *) self); mthread_insert_last(first, &(vp->ready_list)); } @@ -84,13 +87,15 @@ mthread_cond_wait(mthread_cond_t *__cond, mthread_mutex_t *__mutex) self->status = BLOCKED; mthread_mutex_unlock(__mutex); - LOG_ERROR("Waiting in condition for thread %p", (void *) self); + LOG_ERROR("MTHREAD", "Waiting in condition for thread %p", + (void *) self); vp->p = &__cond->lock; mthread_yield(); mthread_mutex_lock(__mutex); - LOG_ERROR("Waike up in condition for thread %p", (void *) self); + LOG_ERROR("MTHREAD", "Waike up in condition for thread %p", + (void *) self); return 0; } diff --git a/src/mthread/mthread_key.c b/src/mthread/mthread_key.c index bfd5403cee699c1de3a06a60af0024d317ab73be..96d650ddc7cb9eaf7b7923c894be5fbc84445a9d 100644 --- a/src/mthread/mthread_key.c +++ b/src/mthread/mthread_key.c @@ -43,16 +43,10 @@ mthread_key_create(mthread_key_t *__key, void (*__destr_function) (void *)) first_avail_key++; if (key_table) { - LOG_INFO("Enqueue cell %d into global key list, old head is %d", - new_cell->key, key_table->key); new_cell->next = key_table; key_table = new_cell; - LOG_INFO("New head is %d, next is %d", - key_table->key, key_table->next->key); - } else { - LOG_INFO("%s", "Set base cell for global key list"); + } else key_table = new_cell; - } /* Register key into the thread. */ @@ -61,7 +55,6 @@ mthread_key_create(mthread_key_t *__key, void (*__destr_function) (void *)) keys->list = (mthread_key_t *) safe_malloc(INIT_KEYS_LIST * sizeof(mthread_key_t)); keys->first_avail = 0; keys->size = INIT_KEYS_LIST; - LOG_INFO("%s", "Create the key list for thread"); } if (keys->size == keys->first_avail) { @@ -70,7 +63,6 @@ mthread_key_create(mthread_key_t *__key, void (*__destr_function) (void *)) GOTO_UNLESS(new, "Could not increase the size of the key list", end); keys->size += INIT_KEYS_LIST; keys->list = new; - LOG_INFO("%s", "Increase the size of the key list"); } /* Register the key into the thread. */ @@ -79,7 +71,6 @@ mthread_key_create(mthread_key_t *__key, void (*__destr_function) (void *)) /* Returns. */ *__key = new_cell->key; - LOG_INFO("Created key %d", *__key); end: mthread_spinlock_unlock(&lock); return errno; @@ -101,12 +92,13 @@ mthread_key_delete(mthread_key_t __key) if (!it) { errno = EINVAL; - LOG_ERROR("Key %u not found", __key); + LOG_ERROR("MTHREAD", "Key %u not found", __key); goto end; } if (it->destr) { - LOG_INFO("Call function on data at %p", (void *) it->spec); + LOG_INFO("MTHREAD", "Call function on data at %p", + (void *) it->spec); it->destr((void *) it->spec); } @@ -118,7 +110,7 @@ mthread_key_delete(mthread_key_t __key) key_table = it->next; free(it); - LOG_INFO("Deleted key %u successfully", __key); + LOG_INFO("MTHREAD", "Deleted key %u successfully", __key); /* End of the function, simply returns. */ end: mthread_spinlock_unlock(&lock); @@ -137,12 +129,11 @@ mthread_setspecific(mthread_key_t __key, const void *__pointer) if (!it) { errno = EINVAL; - LOG_ERROR("Key %u not found", __key); + LOG_ERROR("MTHREAD", "Key %u not found", __key); goto end; } it->spec = __pointer; - LOG_INFO("Key %u set to %p", __key, __pointer); /* End of the function, simply returns. */ end: mthread_spinlock_unlock(&lock); @@ -162,7 +153,7 @@ mthread_getspecific(mthread_key_t __key) if (!it) { errno = EINVAL; - LOG_ERROR("Key %u not found", __key); + LOG_ERROR("MTHREAD", "Key %u not found", __key); goto end; } diff --git a/src/mthread/mthread_mutex.c b/src/mthread/mthread_mutex.c index b9ee9843b5fbcf17fe7e0c35827cf2e9ea0e8b90..beb344bae6282d57d80d78c82aa8efbed26864f8 100644 --- a/src/mthread/mthread_mutex.c +++ b/src/mthread/mthread_mutex.c @@ -18,7 +18,7 @@ mthread_mutex_init(mthread_mutex_t *__mutex, const mthread_mutexattr_t *__mutex_ __mutex->list->last = NULL; __mutex->nb_thread = 0; __mutex->lock = 0; - LOG_INFO("%s", "MUTEX initialized"); + LOG_INFO("MTHREAD", "%s", "MUTEX initialized"); return 0; } @@ -58,7 +58,7 @@ mthread_mutex_trylock(mthread_mutex_t *__mutex) } mthread_spinlock_unlock(&__mutex->lock); - LOG_WARN("%s", "MUTEX busy"); + LOG_WARN("MTHREAD", "%s", "MUTEX busy"); retval = EBUSY; end: diff --git a/src/net/listen.c b/src/net/listen.c index 332edcb229a82606b6354ad2e181ab00fc7037f2..daad13d8ace43a705fab6f62d904f8fca86c571f 100644 --- a/src/net/listen.c +++ b/src/net/listen.c @@ -126,13 +126,11 @@ static void send_status(struct lkt_state *srv, size_t c, int status, const char *cmd_name) { if (!status) { - LOG_INFO_SCT("COMMAND", "Command '%s'", cmd_name); + LOG_INFO("COMMAND", "Command '%s'", cmd_name); send_ok(srv, c); } else { - if (status == 2) - LOG_INFO_SCT("COMMAND", "Unknown command '%s'", cmd_name); - else - LOG_INFO_SCT("COMMAND", "Command failed '%s'", cmd_name); + LOG_INFO("COMMAND", "Command '%s' %s", cmd_name, + status == 2 ? "is unknown" : "has failed"); send_ack(srv, c, cmd_name); } } @@ -288,8 +286,8 @@ handle_simple_command(struct lkt_state *srv, size_t c, struct lkt_command cmd) continuation = lkt_get_continuation(srv, c); if (continuation > 0) { - LOG_INFO_SCT("NETWORK", "Client should continue from '%d'", - continuation); + LOG_INFO("NETWORK", "Client should continue from '%d'", + continuation); send_continue(srv, c, continuation); } send_status(srv, c, err, cmd.name); @@ -337,7 +335,7 @@ handle_command(struct lkt_state *srv, size_t i, struct lkt_command cmd) else err = handle_simple_command(srv, i, cmd); - LOG_INFO_SCT("COMMAND", "Command result '%s' -> %d", cmd.name, err); + LOG_INFO("COMMAND", "Command result '%s' -> %d", cmd.name, err); return err; } @@ -409,8 +407,8 @@ handle_outgoing_data(struct lkt_state *srv, size_t c) return 0; } if (errno == EPIPE) { - LOG_WARN_SCT("NETWORK", "Client %ld is out, free all its " - "messages", c); + LOG_WARN("NETWORK", "Client %ld is out, free all its " + "messages", c); handle_disconnected_client(srv, i); } return -1; @@ -480,23 +478,17 @@ failure: freeaddrinfo(available); if (fd < 0) { - if (host) - LOG_ERROR_SCT("NETWORK", "Failed to bind to %s:%s", host, port); - else - LOG_ERROR_SCT("NETWORK", "Failed to bind to port %s", port); + LOG_ERROR("NETWORK", "Failed to bind to %s:%s", + host ? host : "0.0.0.0", port); return -1; } if (listen(fd, LKT_BACKLOG) < 0) { - LOG_ERROR_SCT("NETWORK", "Failed to listen: %s", strerror(errno)); + LOG_ERROR("NETWORK", "Failed to listen: %s", strerror(errno)); return -1; } - if (host) - LOG_INFO_SCT("NETWORK", "Listening on %s:%s", host, port); - else - LOG_INFO_SCT("NETWORK", "Listening on port %s", port); - + LOG_INFO("NETWORK", "Listening on %s:%s", host ? host : "0.0.0.0", port); return fd; } @@ -520,8 +512,8 @@ accept_all(int listen_fd, struct pollfd *fds, size_t fds_max, size_t *fds_len) } if (*fds_len == fds_max) { - LOG_ERROR_SCT("NETWORK", "Maximum number '%ld' of file descriptors" - " reached", fds_max); + LOG_ERROR("NETWORK", "Maximum number '%ld' of file descriptors" + " reached", fds_max); break; } @@ -537,7 +529,7 @@ accept_all(int listen_fd, struct pollfd *fds, size_t fds_max, size_t *fds_len) char *host = inet_ntoa(peer_addr.sin_addr); uint16_t port = htons(peer_addr.sin_port); - LOG_WARN_SCT("NETWORK", "New connection from %s:%d", host, port); + LOG_WARN("NETWORK", "New connection from %s:%d", host, port); fds->fd = fd; fds->events = POLLIN; @@ -585,7 +577,7 @@ handle_network_events(struct lkt_state *srv) srv->fds[i].fd = -1; srv->fds[i].revents &= ~ (POLLHUP | POLLERR); handle_disconnected_client(srv, i); - LOG_WARN_SCT("NETWORK", "Client %ld is out", i); + LOG_WARN("NETWORK", "Client %ld is out", i); continue; } if (srv->fds[i].revents & POLLIN) { @@ -611,7 +603,7 @@ handle_network_events(struct lkt_state *srv) if (srv->fds[i].fd > 0) continue; - LOG_WARN_SCT("NETWORK", "Connection closed by client %ld", i); + LOG_WARN("NETWORK", "Connection closed by client %ld", i); srv->fds[i] = srv->fds[srv->fds_len - 1]; srv->clients[i - 1] = srv->clients[srv->fds_len - 2]; srv->fds_len--; @@ -676,8 +668,8 @@ handle_idle_events(struct lkt_state *srv) strncat(msg->data, "message ", LKT_MESSAGE_MAX - 1); msg->data_len = strlen(msg->data); - LOG_INFO_SCT("COMMAND", "Sending '%s' (len: %ld) to client %ld", - msg->data, msg->data_len, i); + LOG_INFO("COMMAND", "Sending '%s' (len: %ld) to client %ld", + msg->data, msg->data_len, i); msg->data[msg->data_len - 1] = '\n'; msg->data[msg->data_len] = '\0'; lkt_state_send(srv, i, msg); diff --git a/src/reg.c b/src/reg.c index 0f847f9bdc15fd9d3ca2ae4e986b6674c47423a9..c0ba8596d723b93959d92bd01734357811f23a6c 100644 --- a/src/reg.c +++ b/src/reg.c @@ -24,12 +24,13 @@ reg_pick(const char *file, void **handle, const char *symbol) goto use_reg; /* Use dlsym */ - LOG_INFO_SCT("REG", "Using dlfcn to find %s", symbol); + LOG_INFO("REG", "Using dlfcn to find %s", symbol); char *error; *handle = dlopen(file, RTLD_NOW); if (NULL == *handle) { - LOG_ERROR("libdl error in dlopen on file '%s': %s", file, dlerror()); + LOG_ERROR("REG", "libdl error in dlopen on file '%s': %s", + file, dlerror()); return NULL; } @@ -37,7 +38,8 @@ reg_pick(const char *file, void **handle, const char *symbol) void *sym = dlsym(*handle, symbol); if ((error = dlerror()) != NULL) { - LOG_ERROR("libdl error in dlsym on file '%s': %s\n", file, error); + LOG_ERROR("REG", "libdl error in dlsym on file '%s': %s\n", + file, error); return NULL; } @@ -45,7 +47,7 @@ reg_pick(const char *file, void **handle, const char *symbol) /* Read the reg */ use_reg: - LOG_INFO_SCT("REG", "Using the reg structure to find %s", symbol); + LOG_INFO("REG", "Using the reg structure to find %s", symbol); for (i = 0; reg[i].name && reg[i].func; ++i) if (STR_MATCH(reg[i].name, symbol)) return *(void **) ®[i].func; @@ -75,8 +77,8 @@ load_so(const char *const mod_path, const char *const mod_init, void *mod, if (module_set_function) return module_set_function(mod, srv, handle); else { - LOG_ERROR_SCT("LOAD", "Failed to find init symbol %s " - "in file %s", mod_init, mod_path); + LOG_ERROR("LOAD", "Failed to find init symbol %s " + "in file %s", mod_init, mod_path); return 1; } } @@ -88,14 +90,14 @@ load_module_by_name(struct lkt_state *srv, const char *name, void *mod) /* When, don't mind if its not here */ if (!database_config_get_text(srv->db, name, "path", mod_path, PATH_MAX)) { - LOG_WARN_SCT("CONFIG", "No setting 'path' in section '%s'", name); + LOG_WARN("CONFIG", "No setting 'path' in section '%s'", name); mod_path[0] = '\0'; } if (!database_config_get_text(srv->db, name, "load_function", mod_load, INI_MAX_LINE_LEN)) { - LOG_ERROR_SCT("CONFIG", "Module named %s is incomplete or " - "is not defined in config file", name); + LOG_ERROR("CONFIG", "Module named %s is incomplete or " + "is not defined in config file", name); return 1; } diff --git a/src/thread.c b/src/thread.c index 6c888d9a1f394f35697e1387bb87025a0a230a84..b63f0fb49820fc59529ec1b9e5eef3ba105a27aa 100644 --- a/src/thread.c +++ b/src/thread.c @@ -46,15 +46,15 @@ poller_new(struct poller_thread *th, void *(*func)(struct poller_thread_arg *), __args->arg->self = th; if (pthread_create(&(th->th), NULL, __start, __args)) { - LOG_ERROR_SCT("THREAD", "%s", "Failed to create a poller thread"); + LOG_ERROR("THREAD", "%s", "Failed to create a poller thread"); return 1; } - LOG_INFO_SCT("THREAD", "%s", "Create a new poller thread"); + LOG_INFO("THREAD", "%s", "Create a new poller thread"); return 0; out_of_memory: - LOG_ERROR_SCT("MEMORY", "%s", "Out of memory"); + LOG_ERROR("MEMORY", "%s", "Out of memory"); stack_free(&th_.input); stack_free(&th_.output); return 1; @@ -66,11 +66,11 @@ poller_join(struct poller_thread *th, void **ret) int sta = pthread_join(th->th, ret); if (sta) - LOG_ERROR_SCT("THREAD", "%s", "Failed to join thread"); + LOG_ERROR("THREAD", "%s", "Failed to join thread"); stack_free(&th->input); stack_free(&th->output); - LOG_WARN_SCT("THREAD", "%s", "Thread joined"); + LOG_WARN("THREAD", "%s", "Thread joined"); memset(th, 0, sizeof(struct poller_thread)); return sta; diff --git a/src/uri.c b/src/uri.c index 20c9119cf2cbe4194d872130cf1b993fc735e45b..82731d39d278d3db4c284b945f3a89800b118340 100644 --- a/src/uri.c +++ b/src/uri.c @@ -113,8 +113,8 @@ __lkt_to_str(struct lkt_uri *uri, char *ret, size_t len) safe_snprintf(ret, len, "search=%s", (char *) uri->value); break; default: - LOG_ERROR("URI type %d may not be supported by kurisu, generate " - "an error", uri->type); + LOG_ERROR("URI", "type %d may not be supported by kurisu, " + "generate an error", uri->type); return 1; }