]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
config: Store config directory variable internally
authorOlliver Schinagl <oliver@schinagl.nl>
Sat, 10 Jun 2023 13:20:25 +0000 (15:20 +0200)
committerFlole998 <Flole998@users.noreply.github.com>
Fri, 16 Jun 2023 11:11:41 +0000 (13:11 +0200)
Currently `config_boot` 'abuses' the path-pointer and stores its own
internal path if needed. While this is _technically_ fine, it prevents
us from a) making `path` a const argument, b) makes things a little
harder to read and maintain and c) makes it harder for future changes to
the configuration path.

Instead, lets store the configuration path internally in our
configuration structure, as is done with most things. This could even
allow us to technically get rid of `hts_settings_init` in the future,
and get this from the config struct instead.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
src/config.c
src/config.h

index 8cd806bf48c340badd64e79633b7a38a8e7be44b..7889d160a59da14bfe0c3fc1d4689a06a6f83c5a 100644 (file)
@@ -1695,7 +1695,6 @@ config_boot
   ( const char *path, gid_t gid, uid_t uid, const char *http_user_agent )
 {
   struct stat st;
-  char buf[1024];
   htsmsg_t *config2;
   htsmsg_field_t *f;
   const char *s;
@@ -1728,30 +1727,36 @@ config_boot
   /* Generate default */
   if (!path) {
     const char *homedir = getenv("HOME");
+    char buf[PATH_MAX];
+
     if (homedir == NULL) {
       tvherror(LS_START, "environment variable HOME is not set");
       exit(EXIT_FAILURE);
     }
     snprintf(buf, sizeof(buf), "%s/.hts/tvheadend", homedir);
-    path = buf;
+    config.confdir = strndup(buf, sizeof(buf));
+  } else {
+    config.confdir = strndup(path, PATH_MAX);
   }
 
+  tvhinfo(LS_CONFIG, "Using configuration from '%s'\n", config.confdir);
+
   /* Ensure directory exists */
-  if (stat(path, &st)) {
+  if (stat(config.confdir, &st)) {
     config_newcfg = 1;
-    if (makedirs(LS_CONFIG, path, 0700, 1, gid, uid)) {
+    if (makedirs(LS_CONFIG, config.confdir, 0700, 1, gid, uid)) {
       tvhwarn(LS_START, "failed to create settings directory %s,"
-                       " settings will not be saved", path);
+                       " settings will not be saved", config.confdir);
       return;
     }
   }
 
   /* And is usable */
-  else if (access(path, R_OK | W_OK)) {
+  else if (access(config.confdir, R_OK | W_OK)) {
     tvhwarn(LS_START, "configuration path %s is not r/w"
                      " for UID:%d GID:%d [e=%s],"
                      " settings will not be saved",
-            path, getuid(), getgid(), strerror(errno));
+            config.confdir, getuid(), getgid(), strerror(errno));
     return;
   }
 
@@ -1760,7 +1765,7 @@ config_boot
   satip_server_boot();
 
   /* Configure settings routines */
-  hts_settings_init(path);
+  hts_settings_init(config.confdir);
 
   /* Lock it */
   hts_settings_buildpath(config_lock, sizeof(config_lock), ".lock");
@@ -1805,6 +1810,8 @@ config_boot
   if ((config.http_user_agent &&
        strncmp(config.http_user_agent, "TVHeadend/", 10) == 0) ||
       tvh_str_default(config.http_user_agent, NULL) == NULL) {
+    char buf[1024];
+
     snprintf(buf, sizeof(buf), "TVHeadend/%s", tvheadend_version);
     tvh_str_set(&config.http_user_agent, buf);
   }
@@ -1845,6 +1852,7 @@ config_init ( int backup )
 void config_done ( void )
 {
   /* note: tvhlog is inactive !!! */
+  free(config.confdir);
   free(config.wizard);
   free(config.full_version);
   free(config.http_server_name);
index c81c20f75f470550146236cb58e59ffeca49a6cd..cb5b2940468f0f3fea48d9da9f9b902257c4a35b 100644 (file)
@@ -30,6 +30,7 @@
 typedef struct config {
   idnode_t idnode;
   uint32_t version;
+  char *confdir;
   int hbbtv;
   int uilevel;
   int uilevel_nochange;