]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
config: Support server configurations
authorOlliver Schinagl <oliver@schinagl.nl>
Tue, 13 Jun 2023 13:35:25 +0000 (15:35 +0200)
committerFlole998 <Flole998@users.noreply.github.com>
Fri, 16 Jun 2023 11:11:41 +0000 (13:11 +0200)
On server loads, it is not uncommon to have the config directory live in
`/var/lib/tvheadend`. While `/etc/tvheadend` is also common, it's more
for manually written configuration files, tvheadend is more a 'config
state'. Support both regardless.

This change shouldn't impact desktop users, presuming they do not have
these locations installed.

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

index 63657b597086174b9348b0b3acbddda615729659..8ee750acfa35e71c9ff696e065018ebd8e130b01 100644 (file)
@@ -1698,8 +1698,17 @@ static char *config_get_dir ( void )
   char hts_home[PATH_MAX + sizeof("/.hts/tvheadend")]; /* Must be largest of the 3 config strings! */
   char config_home[PATH_MAX];
   char home_dir[PATH_MAX];
+  uid_t uid = getuid();
   struct stat st;
 
+  snprintf(hts_home, sizeof(hts_home), "/var/lib/tvheadend");
+  if ((stat(hts_home, &st) == 0) && (st.st_uid == uid))
+    return strndup(hts_home, sizeof(hts_home));
+
+  snprintf(hts_home, sizeof(hts_home), "/etc/tvheadend");
+  if ((stat(hts_home, &st) == 0) && (st.st_uid == uid))
+    return strndup(hts_home, sizeof(hts_home));
+
   if (realpath(getenv("HOME"), home_dir) == NULL) {
     tvherror(LS_CONFIG, "environment variable HOME is not set");
     return NULL;
@@ -1711,9 +1720,9 @@ static char *config_get_dir ( void )
       char hts_home_link[PATH_MAX];
 
       if ((readlink(hts_home, hts_home_link, sizeof(hts_home_link)) == -1) ||
-          (stat(hts_home_link, &st) == -1)) {
-        tvherror(LS_CONFIG, ".hts/tvheadend is inaccessable: %s", strerror(errno));
-        return NULL;
+         (stat(hts_home_link, &st) == -1)) {
+       tvherror(LS_CONFIG, ".hts/tvheadend is inaccessable: %s", strerror(errno));
+       return NULL;
       }
       strncpy(hts_home, hts_home_link, sizeof(hts_home));
     }