Skip to content
Extraits de code Groupes Projets
Vérifiée Valider d6022be9 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

MODULE: Add logs to see why the repo module creation segfaults

parent de7dc623
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!105Refactor and more
...@@ -110,6 +110,10 @@ main(int argc, char *argv[]) ...@@ -110,6 +110,10 @@ main(int argc, char *argv[])
{ /* Module initialization */ { /* Module initialization */
char *module = safe_malloc(sizeof(char) * PATH_MAX); char *module = safe_malloc(sizeof(char) * PATH_MAX);
if (!module) {
LOG_ERROR("GENERAL", "Out of memory");
return 1;
}
database_config_get_text(srv.db, "player", "module", module, PATH_MAX); database_config_get_text(srv.db, "player", "module", module, PATH_MAX);
reg_import(module, &srv.window_mod.reg, &srv.window_mod.handle); reg_import(module, &srv.window_mod.reg, &srv.window_mod.handle);
database_config_get_text(srv.db, "repo", "module", module, PATH_MAX); database_config_get_text(srv.db, "repo", "module", module, PATH_MAX);
......
...@@ -431,7 +431,7 @@ module_repo_new(struct module_repo_internal *repo_, struct queue *queue, volatil ...@@ -431,7 +431,7 @@ module_repo_new(struct module_repo_internal *repo_, struct queue *queue, volatil
10 /* Initial number of elements in the call queue */, 10 /* Initial number of elements in the call queue */,
workers_count /* Number of worker threads */)) { workers_count /* Number of worker threads */)) {
LOG_ERROR("REPO", "Out of memory"); LOG_ERROR("REPO", "Out of memory");
return 1; return false;
} }
/* Copies */ /* Copies */
...@@ -441,9 +441,9 @@ module_repo_new(struct module_repo_internal *repo_, struct queue *queue, volatil ...@@ -441,9 +441,9 @@ module_repo_new(struct module_repo_internal *repo_, struct queue *queue, volatil
!database_config_get_text(db, "repo", "id_json", repo.get_id_json, LKT_LINE_MAX) || !database_config_get_text(db, "repo", "id_json", repo.get_id_json, LKT_LINE_MAX) ||
!database_config_get_text(db, "repo", "id_kara", repo.get_id_file, LKT_LINE_MAX) || !database_config_get_text(db, "repo", "id_kara", repo.get_id_file, LKT_LINE_MAX) ||
!database_config_get_text(db, "repo", "json", repo.get_all_json, LKT_LINE_MAX) ) !database_config_get_text(db, "repo", "json", repo.get_all_json, LKT_LINE_MAX) )
return 1; return false;
memcpy(repo_, &repo, sizeof(struct module_repo_internal)); memcpy(repo_, &repo, sizeof(struct module_repo_internal));
return 0; return true;
} }
/******************** /********************
...@@ -460,8 +460,11 @@ mod_new(va_list *va) ...@@ -460,8 +460,11 @@ mod_new(va_list *va)
struct queue *queue = va_arg(copy, struct queue *); struct queue *queue = va_arg(copy, struct queue *);
volatile sqlite3 *db = va_arg(copy, volatile sqlite3 *); volatile sqlite3 *db = va_arg(copy, volatile sqlite3 *);
if (NULL == *repo) if (NULL != *repo) {
*repo = malloc(sizeof(struct module_repo_internal)); LOG_ERROR("REPO", "Can't init two times the module");
return 1;
}
*repo = malloc(sizeof(struct module_repo_internal));
if (NULL == *repo) { if (NULL == *repo) {
LOG_ERROR("REPO", "Out of memory"); LOG_ERROR("REPO", "Out of memory");
return 1; return 1;
...@@ -470,6 +473,8 @@ mod_new(va_list *va) ...@@ -470,6 +473,8 @@ mod_new(va_list *va)
bool ret = module_repo_new(*repo, queue, db); bool ret = module_repo_new(*repo, queue, db);
lkt_queue_make_available(queue, lkt_event_db_updating); lkt_queue_make_available(queue, lkt_event_db_updating);
va_end(copy); va_end(copy);
if (!ret)
LOG_ERROR("REPO", "Failed to create the module");
return ! ret; return ! ret;
} }
......
...@@ -8,15 +8,21 @@ ...@@ -8,15 +8,21 @@
#include <assert.h> #include <assert.h>
#include <sys/sysinfo.h> #include <sys/sysinfo.h>
#include <sched.h> #include <sched.h>
#include <errno.h>
#include <string.h>
static inline void * static void *
__worker_thread(void *__pool) __worker_thread(void *__pool)
{ {
struct worker_pool *pool = (struct worker_pool *) __pool; struct worker_pool *pool = (struct worker_pool *) __pool;
volatile void *volatile arg; volatile void *volatile arg;
worker_function func; worker_function func;
for (;;) { for (;;) {
assert(!pthread_mutex_lock(&pool->lock)); errno = 0;
if (pthread_mutex_lock(&pool->lock)) {
LOG_ERROR("WORKER", "Failed to lock mutex: %s", strerror(errno));
abort();
}
if (pool->len) { if (pool->len) {
--(pool->len); --(pool->len);
++(pool->thread_working); ++(pool->thread_working);
...@@ -47,7 +53,6 @@ __worker_thread(void *__pool) ...@@ -47,7 +53,6 @@ __worker_thread(void *__pool)
int int
worker_pool_new(struct worker_pool *ret, size_t init_size, size_t thread_count) worker_pool_new(struct worker_pool *ret, size_t init_size, size_t thread_count)
{ {
pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
if (!thread_count) if (!thread_count)
thread_count = get_nprocs_conf(); thread_count = get_nprocs_conf();
struct worker_pool __ret = { struct worker_pool __ret = {
...@@ -57,7 +62,6 @@ worker_pool_new(struct worker_pool *ret, size_t init_size, size_t thread_count) ...@@ -57,7 +62,6 @@ worker_pool_new(struct worker_pool *ret, size_t init_size, size_t thread_count)
.size = init_size, .size = init_size,
.thread_size = thread_count, .thread_size = thread_count,
.len = 0u, .len = 0u,
.lock = mtx,
.exit = 0, .exit = 0,
}; };
if (!__ret.functions || !__ret.args || !__ret.threads) { if (!__ret.functions || !__ret.args || !__ret.threads) {
...@@ -66,8 +70,12 @@ worker_pool_new(struct worker_pool *ret, size_t init_size, size_t thread_count) ...@@ -66,8 +70,12 @@ worker_pool_new(struct worker_pool *ret, size_t init_size, size_t thread_count)
worker_pool_free(&__ret); worker_pool_free(&__ret);
return 1; return 1;
} }
size_t i;
*ret = __ret; *ret = __ret;
if (pthread_mutex_init(&ret->lock, NULL)) {
LOG_ERROR("WORKER", "Failed to init mutex: %s", strerror(errno));
abort();
}
size_t i;
for (i = 0; i < ret->thread_size; ++i) for (i = 0; i < ret->thread_size; ++i)
assert(!pthread_create(&ret->threads[i], NULL, __worker_thread, ret)); assert(!pthread_create(&ret->threads[i], NULL, __worker_thread, ret));
return 0; return 0;
...@@ -76,6 +84,7 @@ worker_pool_new(struct worker_pool *ret, size_t init_size, size_t thread_count) ...@@ -76,6 +84,7 @@ worker_pool_new(struct worker_pool *ret, size_t init_size, size_t thread_count)
void void
worker_pool_free(struct worker_pool *pool) worker_pool_free(struct worker_pool *pool)
{ {
LOG_DEBUG("WORKER", "Freeing worker pool %p", pool);
size_t i; size_t i;
pool->exit = 1; pool->exit = 1;
for (i = 0; i < pool->thread_size; ++i) for (i = 0; i < pool->thread_size; ++i)
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter