diff --git a/src/daemon.c b/src/daemon.c index e9177fc..ef8515a 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -35,10 +35,9 @@ pthread_mutex_t tasks_lock = PTHREAD_MUTEX_INITIALIZER; // locks tasks and has_c -void* inotify_check_changes(void* arg) { - (void)arg; +void* inotify_check_changes(void* sk_path) { + char* socket_path = (char*)sk_path; char buffer[EVENT_BUF_LEN]; - char* socket_path = get_socket_path(); while (1) { // Regarde si /tmp/takl.$USER a changé (donc si la BDD a changé et doit être rechargée) int fd = inotify_init(); @@ -67,14 +66,11 @@ void* inotify_check_changes(void* arg) { inotify_rm_watch(fd, wd); close(fd); } - free(socket_path); return NULL; } -int existing_takl_daemon() { - char* socket_path = get_socket_path(); - +int existing_takl_daemon(char* socket_path) { if (!access(socket_path, F_OK)) { // tmp file exists FILE* fp = fopen(socket_path, "r+"); int daemon_pid; @@ -90,15 +86,16 @@ int existing_takl_daemon() { fprintf(fp, "%d", getpid()); fclose(fp); - free(socket_path); return false; } int main() { bool notified_no_change = false; + char* socket_path = get_socket_path(); + log_debug("Socket path:%s", socket_path); - if (!existing_takl_daemon()) { + if (!existing_takl_daemon(socket_path)) { log_info("TaKl " VERSION " -- Daemon started"); } else { log_info("TaKl Daemon déjà en cours d'exécution. Arrêt"); @@ -108,7 +105,7 @@ int main() { tasks = get_task_list(false, false); pthread_t inotify_id = 0; // Lancement d'inotify dans un autre fil - pthread_create(&inotify_id, NULL, inotify_check_changes, NULL); + pthread_create(&inotify_id, NULL, inotify_check_changes, (void*)socket_path); while (1) { pthread_mutex_lock(&tasks_lock); @@ -169,5 +166,6 @@ int main() { pthread_join(inotify_id, NULL); free_task_list(tasks); + free(socket_path); return 0; } \ No newline at end of file diff --git a/src/main/include/config.h b/src/main/include/config.h index 9d5ea76..40c3ada 100644 --- a/src/main/include/config.h +++ b/src/main/include/config.h @@ -1,7 +1,7 @@ #ifndef DEF_CONFIG_H #define DEF_CONFIG_H -#define VERSION "1.3.1" +#define VERSION "1.3.2" #define MAX_TASK_ID 10000 // max is set to MAX_TASK_ID-1 #define NEW_TASK_ID_MAX_RETRIES 10000 // number of retries before giving up