From: Michael Marley Date: Thu, 22 Jun 2023 20:55:38 +0000 (-0400) Subject: Fix configuration-loading logic to account for forking operation X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=612b615ffd8adfd33f905cf15b67ff817cc59c20;p=thirdparty%2Ftvheadend.git Fix configuration-loading logic to account for forking operation Since config_get_dir() is executed before forking, the uid will always be 0 at this point. Instead, use the uid of the user to which we will fork if a fork will occur. --- diff --git a/src/config.c b/src/config.c index 6769de7a6..6ffa09c71 100644 --- a/src/config.c +++ b/src/config.c @@ -1693,14 +1693,16 @@ config_check ( void ) static int config_newcfg = 0; -static char *config_get_dir ( void ) +static char *config_get_dir ( uid_t uid ) { 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; + if (uid == -1) + uid = getuid(); + 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)); @@ -1777,7 +1779,7 @@ config_boot /* Generate default */ if (!path) - config.confdir = config_get_dir(); + config.confdir = config_get_dir(uid); else config.confdir = strndup(path, PATH_MAX);