Override configuration with env variables

This commit is contained in:
augustin64 2023-10-04 17:15:15 +02:00
parent 9cae1fbebb
commit 7d445ee27b
3 changed files with 25 additions and 22 deletions

View File

@ -25,8 +25,17 @@ void sqlAssert(int ret, sqlite3* db, char* file, int line) {
char* get_db_path() {
#ifndef DB_FILE
//! We should check that $HOME/.config already exists even if it should be the case
/*
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 {
char* base_path = ".config/takl.sqlite3";
char* home_dir = getenv("HOME");
@ -36,12 +45,7 @@ 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,13 +1,7 @@
#ifndef DEF_CONFIG_H
#define DEF_CONFIG_H
#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 VERSION "1.3.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

View File

@ -8,7 +8,17 @@
#include "include/struct.h"
char* get_socket_path() {
#ifndef SOCKET_FILE
/*
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 {
char* base_path = "/tmp/takl";
char* username = getenv("USER");
@ -18,12 +28,7 @@ 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
}
}