Override configuration with env variables
This commit is contained in:
parent
9cae1fbebb
commit
7d445ee27b
@ -25,8 +25,17 @@ void sqlAssert(int ret, sqlite3* db, char* file, int line) {
|
|||||||
|
|
||||||
|
|
||||||
char* get_db_path() {
|
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* base_path = ".config/takl.sqlite3";
|
||||||
|
|
||||||
char* home_dir = getenv("HOME");
|
char* home_dir = getenv("HOME");
|
||||||
@ -36,12 +45,7 @@ char* get_db_path() {
|
|||||||
sprintf(db_path, "%s/%s", home_dir, base_path);
|
sprintf(db_path, "%s/%s", home_dir, base_path);
|
||||||
|
|
||||||
return db_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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,13 +1,7 @@
|
|||||||
#ifndef DEF_CONFIG_H
|
#ifndef DEF_CONFIG_H
|
||||||
#define DEF_CONFIG_H
|
#define DEF_CONFIG_H
|
||||||
|
|
||||||
#define VERSION "1.3.0"
|
#define VERSION "1.3.1"
|
||||||
|
|
||||||
// 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 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
|
||||||
|
@ -8,7 +8,17 @@
|
|||||||
#include "include/struct.h"
|
#include "include/struct.h"
|
||||||
|
|
||||||
char* get_socket_path() {
|
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* base_path = "/tmp/takl";
|
||||||
|
|
||||||
char* username = getenv("USER");
|
char* username = getenv("USER");
|
||||||
@ -18,12 +28,7 @@ char* get_socket_path() {
|
|||||||
sprintf(socket_path, "%s.%s", base_path, username);
|
sprintf(socket_path, "%s.%s", base_path, username);
|
||||||
|
|
||||||
return socket_path;
|
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user