Compare commits

..

No commits in common. "6c8c2f719296040950d0083af81dfc89eb32dd19" and "9cae1fbebb2fbc37563214de9a306add6a79f4e9" have entirely different histories.

4 changed files with 32 additions and 33 deletions

View File

@ -35,9 +35,10 @@ pthread_mutex_t tasks_lock = PTHREAD_MUTEX_INITIALIZER; // locks tasks and has_c
void* inotify_check_changes(void* sk_path) {
char* socket_path = (char*)sk_path;
void* inotify_check_changes(void* arg) {
(void)arg;
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();
@ -66,11 +67,14 @@ void* inotify_check_changes(void* sk_path) {
inotify_rm_watch(fd, wd);
close(fd);
}
free(socket_path);
return NULL;
}
int existing_takl_daemon(char* socket_path) {
int existing_takl_daemon() {
char* socket_path = get_socket_path();
if (!access(socket_path, F_OK)) { // tmp file exists
FILE* fp = fopen(socket_path, "r+");
int daemon_pid;
@ -86,16 +90,15 @@ int existing_takl_daemon(char* socket_path) {
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(socket_path)) {
if (!existing_takl_daemon()) {
log_info("TaKl " VERSION " -- Daemon started");
} else {
log_info("TaKl Daemon déjà en cours d'exécution. Arrêt");
@ -105,7 +108,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, (void*)socket_path);
pthread_create(&inotify_id, NULL, inotify_check_changes, NULL);
while (1) {
pthread_mutex_lock(&tasks_lock);
@ -166,6 +169,5 @@ int main() {
pthread_join(inotify_id, NULL);
free_task_list(tasks);
free(socket_path);
return 0;
}

View File

@ -25,17 +25,8 @@ void sqlAssert(int ret, sqlite3* db, char* file, int line) {
char* get_db_path() {
/*
Checks if $TAKL_DB env variable is set
else, the DB is located at $HOME/.config/takl.sqlite3
*/
char* env_db_path = getenv("TAKL_DB");
if (env_db_path) {
char* db_path = malloc(sizeof(char)*(strlen(env_db_path)+1));
strcpy(db_path, env_db_path);
return db_path;
} else {
#ifndef DB_FILE
//! We should check that $HOME/.config already exists even if it should be the case
char* base_path = ".config/takl.sqlite3";
char* home_dir = getenv("HOME");
@ -45,7 +36,12 @@ char* get_db_path() {
sprintf(db_path, "%s/%s", home_dir, base_path);
return db_path;
}
#else
char* db_path = malloc(sizeof(char)*(strlen(DB_FILE)+1));
memcpy(db_path, DB_FILE, sizeof(char)*(strlen(DB_FILE)+1));
return db_path;
#endif
}

View File

@ -1,7 +1,13 @@
#ifndef DEF_CONFIG_H
#define DEF_CONFIG_H
#define VERSION "1.3.2"
#define VERSION "1.3.0"
// By default, $HOME/.config/takl.sqlite3 is used. You can change this behaviour here
//#define DB_FILE "takl.sqlite3"
// By default, /tmp/takl.$USER is used. You can change this behaviour here
//#define SOCKET_FILE "takl.sock"
#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

View File

@ -8,17 +8,7 @@
#include "include/struct.h"
char* get_socket_path() {
/*
Checks if $TAKL_SOCKET env variable is set
else, the socket is located at /tmp/takl
*/
char* env_socket_path = getenv("TAKL_SOCKET");
if (env_socket_path) {
char* socket_path = malloc(sizeof(char)*(strlen(env_socket_path)+1));
strcpy(socket_path, env_socket_path);
return socket_path;
} else {
#ifndef SOCKET_FILE
char* base_path = "/tmp/takl";
char* username = getenv("USER");
@ -28,7 +18,12 @@ char* get_socket_path() {
sprintf(socket_path, "%s.%s", base_path, username);
return socket_path;
}
#else
char* socket_path = malloc(sizeof(char)*(strlen(SOCKET_FILE)+1));
memcpy(socket_path, SOCKET_FILE, sizeof(char)*(strlen(SOCKET_FILE)+1));
return socket_path;
#endif
}