From a060a4ba0804d30f9d038585b55ecdaac1d2eec4 Mon Sep 17 00:00:00 2001 From: Jeroen van der Heijden Date: Thu, 19 Nov 2020 13:36:29 +0100 Subject: [PATCH] Rename configuration setting SIRIDB_DB_PATH and siridb_db_path --- include/siri/cfg/cfg.h | 2 +- include/siri/version.h | 4 ++-- siridb.conf | 2 +- src/siri/cfg/cfg.c | 28 +++++++++++++++++-------- src/siri/evars.c | 9 ++++++-- src/siri/service/account.c | 8 ++++---- src/siri/service/request.c | 4 ++-- src/siri/siri.c | 42 +++++++++++++++++++------------------- 8 files changed, 57 insertions(+), 42 deletions(-) diff --git a/include/siri/cfg/cfg.h b/include/siri/cfg/cfg.h index 725cbf85..a5cfe90f 100644 --- a/include/siri/cfg/cfg.h +++ b/include/siri/cfg/cfg.h @@ -43,7 +43,7 @@ struct siri_cfg_s char * bind_client_addr; char * bind_backend_addr; char server_address[SIRI_CFG_MAX_LEN_ADDRESS]; - char default_db_path[XPATH_MAX]; + char db_path[XPATH_MAX]; char pipe_client_name[XPATH_MAX]; }; diff --git a/include/siri/version.h b/include/siri/version.h index f1d65054..0294a646 100644 --- a/include/siri/version.h +++ b/include/siri/version.h @@ -6,7 +6,7 @@ #define SIRIDB_VERSION_MAJOR 2 #define SIRIDB_VERSION_MINOR 0 -#define SIRIDB_VERSION_PATCH 42 +#define SIRIDB_VERSION_PATCH 43 /* * Use SIRIDB_VERSION_PRE_RELEASE for alpha release versions. @@ -15,7 +15,7 @@ * Note that debian alpha packages should use versions like this: * 2.0.34-0alpha0 */ -#define SIRIDB_VERSION_PRE_RELEASE "" +#define SIRIDB_VERSION_PRE_RELEASE "-alpha-0" #ifndef NDEBUG #define SIRIDB_VERSION_BUILD_RELEASE "+debug" diff --git a/siridb.conf b/siridb.conf index 731c6374..71ed0726 100644 --- a/siridb.conf +++ b/siridb.conf @@ -38,7 +38,7 @@ ip_support = ALL # # SiriDB will load databases from, and create databases in this location. # -default_db_path = /var/lib/siridb +db_path = /var/lib/siridb # # SiriDB will run an optimize task each X seconds. A value of 0 (zero) disables diff --git a/src/siri/cfg/cfg.c b/src/siri/cfg/cfg.c index b062db4d..5e3b7961 100644 --- a/src/siri/cfg/cfg.c +++ b/src/siri/cfg/cfg.c @@ -28,7 +28,7 @@ static siri_cfg_t siri_cfg = { .shard_compression=0, .shard_auto_duration=0, .server_address="localhost", - .default_db_path="", + .db_path="", .pipe_support=0, .pipe_client_name="siridb_client.sock", .buffer_sync_interval=0, @@ -50,7 +50,7 @@ static void SIRI_CFG_read_addr( const char * option_name, char ** dest); static void SIRI_CFG_read_pipe_client_name(cfgparser_t * cfgparser); -static void SIRI_CFG_read_default_db_path(cfgparser_t * cfgparser); +static void SIRI_CFG_read_db_path(cfgparser_t * cfgparser); static void SIRI_CFG_read_max_open_files(cfgparser_t * cfgparser); static void SIRI_CFG_read_ip_support(cfgparser_t * cfgparser); static void SIRI_CFG_read_shard_compression(cfgparser_t * cfgparser); @@ -128,7 +128,7 @@ void siri_cfg_init(siri_t * siri) &tmp); siri_cfg.http_api_port = (uint16_t) tmp; - SIRI_CFG_read_default_db_path(cfgparser); + SIRI_CFG_read_db_path(cfgparser); SIRI_CFG_read_max_open_files(cfgparser); SIRI_CFG_read_ip_support(cfgparser); SIRI_CFG_read_shard_compression(cfgparser); @@ -449,7 +449,7 @@ static void SIRI_CFG_read_pipe_client_name(cfgparser_t * cfgparser) strcpy(siri_cfg.pipe_client_name, option->val->string); } -static void SIRI_CFG_read_default_db_path(cfgparser_t * cfgparser) +static void SIRI_CFG_read_db_path(cfgparser_t * cfgparser) { cfgparser_option_t * option; cfgparser_return_t rc; @@ -457,17 +457,27 @@ static void SIRI_CFG_read_default_db_path(cfgparser_t * cfgparser) &option, cfgparser, "siridb", - "default_db_path"); + "db_path"); if (rc != CFGPARSER_SUCCESS) { - return; + /* Fall-back using the old configuration name */ + rc = cfgparser_get_option( + &option, + cfgparser, + "siridb", + "default_db_path"); + + if (rc != CFGPARSER_SUCCESS) + { + return; + } } if (option->tp != CFGPARSER_TP_STRING) { log_warning( - "Error reading 'default_db_path' in '%s': %s.", + "Error reading 'db_path' in '%s': %s.", siri.args->config, "error: expecting a string value"); return; @@ -476,13 +486,13 @@ static void SIRI_CFG_read_default_db_path(cfgparser_t * cfgparser) if (strlen(option->val->string) >= XPATH_MAX) { log_warning( - "Error reading 'default_db_path' in '%s': %s.", + "Error reading 'db_path' in '%s': %s.", siri.args->config, "error: path too long"); return; } - strncpy(siri_cfg.default_db_path, option->val->string, XPATH_MAX); + strncpy(siri_cfg.db_path, option->val->string, XPATH_MAX); } static void SIRI_CFG_read_max_open_files(cfgparser_t * cfgparser) diff --git a/src/siri/evars.c b/src/siri/evars.c index 8f9d7763..af2ba507 100644 --- a/src/siri/evars.c +++ b/src/siri/evars.c @@ -143,10 +143,15 @@ void siri_evars_parse(siri_t * siri) evars__bool( "SIRIDB_ENABLE_SHARD_AUTO_DURATION", &siri->cfg->shard_auto_duration); + evars__to_strn( + "SIRIDB_DB_PATH", + siri->cfg->db_path, + sizeof(siri->cfg->db_path)); + /* Read old environment variable for backwards compatibility */ evars__to_strn( "SIRIDB_DEFAULT_DB_PATH", - siri->cfg->default_db_path, - sizeof(siri->cfg->default_db_path)); + siri->cfg->db_path, + sizeof(siri->cfg->db_path)); evars__u32_mm( "SIRIDB_BUFFER_SYNC_INTERVAL", &siri->cfg->buffer_sync_interval, diff --git a/src/siri/service/account.c b/src/siri/service/account.c index 8a136a11..8738e8a4 100644 --- a/src/siri/service/account.c +++ b/src/siri/service/account.c @@ -36,7 +36,7 @@ int siri_service_account_init(siri_t * siri) int rc = 0; /* get service accounts file name */ - char fn[strlen(siri->cfg->default_db_path) + strlen(FILENAME) + 1]; + char fn[strlen(siri->cfg->db_path) + strlen(FILENAME) + 1]; /* initialize linked list */ siri->accounts = llist_new(); @@ -46,7 +46,7 @@ int siri_service_account_init(siri_t * siri) } /* make filename */ - sprintf(fn, "%s%s", siri->cfg->default_db_path, FILENAME); + sprintf(fn, "%s%s", siri->cfg->db_path, FILENAME); if (!xpath_file_exist(fn)) { @@ -386,10 +386,10 @@ int siri_service_account_save(siri_t * siri, char * err_msg) qp_fpacker_t * fpacker; /* get service accounts file name */ - char fn[strlen(siri->cfg->default_db_path) + strlen(FILENAME) + 1]; + char fn[strlen(siri->cfg->db_path) + strlen(FILENAME) + 1]; /* make filename */ - sprintf(fn, "%s%s", siri->cfg->default_db_path, FILENAME); + sprintf(fn, "%s%s", siri->cfg->db_path, FILENAME); if ( /* open a new account file */ diff --git a/src/siri/service/request.c b/src/siri/service/request.c index 11f4d707..3a37b2fb 100644 --- a/src/siri/service/request.c +++ b/src/siri/service/request.c @@ -77,11 +77,11 @@ return CPROTO_ERR_SERVICE; \ } \ \ - dbpath_len = strlen(siri.cfg->default_db_path) + qp_dbname.len + 2; \ + dbpath_len = strlen(siri.cfg->db_path) + qp_dbname.len + 2; \ char dbpath[dbpath_len]; \ sprintf(dbpath, \ "%s%.*s/", \ - siri.cfg->default_db_path, \ + siri.cfg->db_path, \ (int) qp_dbname.len, \ qp_dbname.via.raw); \ \ diff --git a/src/siri/siri.c b/src/siri/siri.c index 257b9c28..fd250e34 100644 --- a/src/siri/siri.c +++ b/src/siri/siri.c @@ -135,44 +135,44 @@ int make_database_directory(void) memset(tmppath, 0, XPATH_MAX); - if (*siri.cfg->default_db_path == '\0') + if (*siri.cfg->db_path == '\0') { if (!homedir || !sysuser || strcmp(sysuser, "root") == 0) { - strcpy(siri.cfg->default_db_path, "/var/lib/siridb/"); + strcpy(siri.cfg->db_path, "/var/lib/siridb/"); } else { - snprintf(siri.cfg->default_db_path, XPATH_MAX, "%s%s.siridb/", + snprintf(siri.cfg->db_path, XPATH_MAX, "%s%s.siridb/", homedir, homedir[strlen(homedir)-1] == '/' ? "" : "/"); } } - if (!xpath_is_dir(siri.cfg->default_db_path)) + if (!xpath_is_dir(siri.cfg->db_path)) { log_warning("Database directory not found, creating directory '%s'.", - siri.cfg->default_db_path); - if (mkdir(siri.cfg->default_db_path, 0700) == -1) + siri.cfg->db_path); + if (mkdir(siri.cfg->db_path, 0700) == -1) { log_error("Cannot create directory '%s'.", - siri.cfg->default_db_path); + siri.cfg->db_path); return -1; } } - if (realpath(siri.cfg->default_db_path, tmppath) == NULL) + if (realpath(siri.cfg->db_path, tmppath) == NULL) { log_warning( "Could not resolve default database path: %s", - siri.cfg->default_db_path); + siri.cfg->db_path); } else { - memcpy(siri.cfg->default_db_path, tmppath, sizeof(tmppath)); + memcpy(siri.cfg->db_path, tmppath, sizeof(tmppath)); } - len = strlen(siri.cfg->default_db_path); + len = strlen(siri.cfg->db_path); if (len >= XPATH_MAX - 2) { @@ -185,10 +185,10 @@ int make_database_directory(void) } /* add trailing slash (/) if its not already there */ - if (siri.cfg->default_db_path[len - 1] != '/') + if (siri.cfg->db_path[len - 1] != '/') { - siri.cfg->default_db_path[len] = '/'; - siri.cfg->default_db_path[len+1] = '\0'; + siri.cfg->db_path[len] = '/'; + siri.cfg->db_path[len+1] = '\0'; } return 0; @@ -385,22 +385,22 @@ static int SIRI_load_databases(void) struct dirent * dbpath; char * buffer; - if (!xpath_is_dir(siri.cfg->default_db_path)) + if (!xpath_is_dir(siri.cfg->db_path)) { log_warning("Database directory not found, creating directory '%s'.", - siri.cfg->default_db_path); - if (mkdir(siri.cfg->default_db_path, 0700) == -1) + siri.cfg->db_path); + if (mkdir(siri.cfg->db_path, 0700) == -1) { log_error("Cannot create directory '%s'.", - siri.cfg->default_db_path); + siri.cfg->db_path); return -1; } } - if ((db_container_path = opendir(siri.cfg->default_db_path)) == NULL) + if ((db_container_path = opendir(siri.cfg->db_path)) == NULL) { log_error("Cannot open database directory '%s'.", - siri.cfg->default_db_path); + siri.cfg->db_path); return -1; } @@ -417,7 +417,7 @@ static int SIRI_load_databases(void) if (asprintf( &buffer, "%s%s/", - siri.cfg->default_db_path, + siri.cfg->db_path, dbpath->d_name) < 0) { /* allocation error occurred */ -- 2.30.2