From e15c1abe97370b461ed1457b3ac2dc4dff58dbd7 Mon Sep 17 00:00:00 2001 From: Olliver Schinagl Date: Tue, 13 Jun 2023 15:35:25 +0200 Subject: [PATCH] config: Support server configurations 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 --- src/config.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/config.c b/src/config.c index 63657b597..8ee750acf 100644 --- a/src/config.c +++ b/src/config.c @@ -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)); } -- 2.47.2