diff --git a/inc/common/macro.h b/inc/common/macro.h index da56e358042a2cbb3ce8579e1ac7fffdf0ef58d9..3bd755ba5fb7792c08c3532dc360ad1e558892f3 100644 --- a/inc/common/macro.h +++ b/inc/common/macro.h @@ -24,12 +24,12 @@ #define RETURN_IF(cond, msg, ret) \ if (cond) { \ - LOG_ERROR("%s", msg); \ + LOG_ERROR_SCT("", "%s", msg); \ return ret; \ } #define GOTO_IF(cond, msg, label) \ if (cond) { \ - LOG_ERROR("%s", msg); \ + LOG_ERROR_SCT("", "%s", msg); \ goto label; \ } @@ -59,10 +59,6 @@ #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__) /* Defines for lektor */ 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/config.c b/src/config.c index 62cb508507c5b17f4a99b73f71ea2fb593d6317e..b1bb5d5876042f8441a49ccb9055ff1e726252db 100644 --- a/src/config.c +++ b/src/config.c @@ -142,7 +142,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_SCT("CONFIG", "Trying %s", conf); if (!access(conf, R_OK | F_OK)) goto found; } @@ -164,7 +164,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_SCT("CONFIG", "Trying %s", conf); if (!access(conf, R_OK | F_OK)) goto found; @@ -172,30 +172,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_SCT("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_SCT("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_SCT("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_SCT("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_SCT("CONFIG", "Using file %s", conf); return 0; } diff --git a/src/database/open.c b/src/database/open.c index 9e06bc940daee6fb6a13f0142f02b2edefe5d02d..d02707861514172dc17560c8adf18ce2ec9ba279 100644 --- a/src/database/open.c +++ b/src/database/open.c @@ -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_SCT("DB", "The database path '%s' is invalid", dbpath); return false; } @@ -221,12 +221,12 @@ 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_SCT("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_SCT("DB", "The database '%s' is already attached", name); return false; } @@ -247,12 +247,12 @@ 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_SCT("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_SCT("DB", "The database '%s' is not attached", name); return false; } diff --git a/src/database/playlist.c b/src/database/playlist.c index 1c80ced4d5c6d505a98cbcc4c8b11e23d80bbdde..7bcda41a3947e53df1c17c0f659c8ae79efcf680 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_SCT("DB", "The playlist name '%s' is invalid", name); 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_SCT("DB", "The playlist name '%s' is invalid", name); goto error; } diff --git a/src/database/update.c b/src/database/update.c index 3a7f539a912da2cdc65102647b7937b1607eebf5..94ee3ad2205d64e9b0b91fb04114dd7cfd0a1e0d 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_SCT("UPDATE", "Failed to get mdt for the kara '%s'", filename); return false; } @@ -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_SCT("UPADTE", "Passed directory '%s'", kara_dir); database_updated(db); closedir(d); return true; diff --git a/src/main/lkt.c b/src/main/lkt.c index 06349601d63e7ebbea8e53ea7348292d86b8b063..1794962d537c3dd399fad42c0ae55fcc6192b782 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_SCT("LKT", "%s", msg); exit(EXIT_FAILURE); } } +#define fail(msg) { LOG_ERROR_SCT("LKT", "%s", msg); exit(EXIT_FAILURE); } #define exit_with_status(sock, buff) { \ read_socket(sock, buff, 2); \ diff --git a/src/mkv/write.c b/src/mkv/write.c index 66dab3b44bf920edc66132cc26df0097c14e0a5b..a3a3975f77a0fc05eb3176071e74f3d9a84395f8 100644 --- a/src/mkv/write.c +++ b/src/mkv/write.c @@ -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_SCT("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_SCT("WRITER", "Failed to write to temporary file: %s", + metadafilepath); 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_SCT("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_SCT("WRITER", "Failed to execute regex: %s", msgbuf); goto error; } @@ -202,8 +204,8 @@ 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, - strerror(errno)); + LOG_ERROR_SCT("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_SCT("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..0169dfe2a77b00d10fc22a79714716ba8822c02c 100644 --- a/src/module/module_sdl2.c +++ b/src/module/module_sdl2.c @@ -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/repo.c b/src/module/repo.c index 5c08094c52665406058196bf86a1760fcf7822a1..adcf07d15b48ac6d7cd22ce34413f2077f4fbbad 100644 --- a/src/module/repo.c +++ b/src/module/repo.c @@ -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, - json_object_get_string(field)); + LOG_ERROR_SCT("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_SCT("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); @@ -251,7 +251,7 @@ __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); + LOG_ERROR_SCT("REPO", "File '%s' already exists", path); else if (errno == EEXIST && override) { if (unlink(path)) { @@ -265,7 +265,7 @@ retest: } else - LOG_ERROR("Could not open file '%s'", path); + LOG_ERROR_SCT("REPO", "Could not open file '%s'", path); return 1; } @@ -302,7 +302,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_SCT("REPO", "%s", "Failed to get kara metadata from kurisu"); return 1; } @@ -317,7 +317,7 @@ repo_download_id_sync(struct lkt_repo *const repo, const uint64_t id, 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_SCT("REPO", "%s", "Failed to add kara to database"); return 1; } diff --git a/src/mthread/mthread_cond.c b/src/mthread/mthread_cond.c index ba25bae0edf1343cd114e6d31ffb5e2ca502fc04..7857572b32f74c21e673c8980e9e76bdefde6133 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_SCT("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_SCT("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_SCT("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_SCT("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_SCT("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_SCT("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..41073ead62254b53e1fc73ed17d523a79a73da85 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_SCT("MTHREAD", "Key %u not found", __key); goto end; } if (it->destr) { - LOG_INFO("Call function on data at %p", (void *) it->spec); + LOG_INFO_SCT("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_SCT("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_SCT("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_SCT("MTHREAD", "Key %u not found", __key); goto end; } diff --git a/src/mthread/mthread_mutex.c b/src/mthread/mthread_mutex.c index b9ee9843b5fbcf17fe7e0c35827cf2e9ea0e8b90..3170bb647122501ef88340c08b280f8191c4275d 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_SCT("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_SCT("MTHREAD", "%s", "MUTEX busy"); retval = EBUSY; end: diff --git a/src/reg.c b/src/reg.c index 0f847f9bdc15fd9d3ca2ae4e986b6674c47423a9..b8ca40d06469916ac819acea3bea36f3cf221c86 100644 --- a/src/reg.c +++ b/src/reg.c @@ -29,7 +29,8 @@ reg_pick(const char *file, void **handle, const char *symbol) *handle = dlopen(file, RTLD_NOW); if (NULL == *handle) { - LOG_ERROR("libdl error in dlopen on file '%s': %s", file, dlerror()); + LOG_ERROR_SCT("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_SCT("REG", "libdl error in dlsym on file '%s': %s\n", + file, error); return NULL; } diff --git a/src/uri.c b/src/uri.c index 20c9119cf2cbe4194d872130cf1b993fc735e45b..471e2a56995c0131f635a7f252cbc386e80dbe0b 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_SCT("URI", "type %d may not be supported by kurisu, " + "generate an error", uri->type); return 1; }