Rename configuration setting SIRIDB_DB_PATH and siridb_db_path
authorJeroen van der Heijden <jeroen@transceptor.technology>
Thu, 19 Nov 2020 12:36:29 +0000 (13:36 +0100)
committerJeroen van der Heijden <jeroen@transceptor.technology>
Thu, 19 Nov 2020 12:36:29 +0000 (13:36 +0100)
include/siri/cfg/cfg.h
include/siri/version.h
siridb.conf
src/siri/cfg/cfg.c
src/siri/evars.c
src/siri/service/account.c
src/siri/service/request.c
src/siri/siri.c

index 725cbf850f535a5b8fb39dfc3eeb0acc088e7c23..a5cfe90f4dfa9767430f11b5cdba8bb0339276e9 100644 (file)
@@ -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];
 };
 
index f1d6505444bd4cf60c267e64cbbb96d4ccd1e0c3..0294a64664f98d37808da70f4a3ec38b9602c210 100644 (file)
@@ -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"
index 731c63742b66d905b7527ab0c1ea4db9507e0a5c..71ed0726c993f1ac17117dd44dea5e306c4c03bd 100644 (file)
@@ -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
index b062db4d6d63163c6aaea4e95de6524746286160..5e3b7961717ff0f2e6a1a26fa93c9a548b96aaeb 100644 (file)
@@ -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)
index 8f9d77630cd0049af362f0c14417c9175dc008be..af2ba50790f1b984adf888ff7ff587b001dea44a 100644 (file)
@@ -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,
index 8a136a11365fbdad40ff12279a056016b890ba29..8738e8a46fcd04fc6e06f08026e8a68780dcf3e9 100644 (file)
@@ -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 */
index 11f4d707c7c10fb3461cfd5bf14385edb4d7d9f7..3a37b2fb15b8fa585d5b453e09371f28d736dda5 100644 (file)
         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);                                             \
                                                                             \
index 257b9c28b0f5ef6978ab865616bc118ce0503d62..fd250e3429c695af9d9e2da9a7f892c1d3cb7475 100644 (file)
@@ -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 */