log socket path
This commit is contained in:
parent
7d445ee27b
commit
6c8c2f7192
18
src/daemon.c
18
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* inotify_check_changes(void* sk_path) {
|
||||||
(void)arg;
|
char* socket_path = (char*)sk_path;
|
||||||
char buffer[EVENT_BUF_LEN];
|
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)
|
while (1) { // Regarde si /tmp/takl.$USER a changé (donc si la BDD a changé et doit être rechargée)
|
||||||
int fd = inotify_init();
|
int fd = inotify_init();
|
||||||
@ -67,14 +66,11 @@ void* inotify_check_changes(void* arg) {
|
|||||||
inotify_rm_watch(fd, wd);
|
inotify_rm_watch(fd, wd);
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
free(socket_path);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int existing_takl_daemon() {
|
int existing_takl_daemon(char* socket_path) {
|
||||||
char* socket_path = get_socket_path();
|
|
||||||
|
|
||||||
if (!access(socket_path, F_OK)) { // tmp file exists
|
if (!access(socket_path, F_OK)) { // tmp file exists
|
||||||
FILE* fp = fopen(socket_path, "r+");
|
FILE* fp = fopen(socket_path, "r+");
|
||||||
int daemon_pid;
|
int daemon_pid;
|
||||||
@ -90,15 +86,16 @@ int existing_takl_daemon() {
|
|||||||
fprintf(fp, "%d", getpid());
|
fprintf(fp, "%d", getpid());
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
free(socket_path);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
bool notified_no_change = false;
|
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");
|
log_info("TaKl " VERSION " -- Daemon started");
|
||||||
} else {
|
} else {
|
||||||
log_info("TaKl Daemon déjà en cours d'exécution. Arrêt");
|
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);
|
tasks = get_task_list(false, false);
|
||||||
|
|
||||||
pthread_t inotify_id = 0; // Lancement d'inotify dans un autre fil
|
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) {
|
while (1) {
|
||||||
pthread_mutex_lock(&tasks_lock);
|
pthread_mutex_lock(&tasks_lock);
|
||||||
@ -169,5 +166,6 @@ int main() {
|
|||||||
pthread_join(inotify_id, NULL);
|
pthread_join(inotify_id, NULL);
|
||||||
|
|
||||||
free_task_list(tasks);
|
free_task_list(tasks);
|
||||||
|
free(socket_path);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef DEF_CONFIG_H
|
#ifndef DEF_CONFIG_H
|
||||||
#define 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 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
|
#define NEW_TASK_ID_MAX_RETRIES 10000 // number of retries before giving up
|
||||||
|
Loading…
Reference in New Issue
Block a user