]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
Fix configuration-loading logic to account for forking operation
authorMichael Marley <michael@michaelmarley.com>
Thu, 22 Jun 2023 20:55:38 +0000 (16:55 -0400)
committerFlole998 <Flole998@users.noreply.github.com>
Fri, 23 Jun 2023 11:27:51 +0000 (13:27 +0200)
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.

src/config.c

index 6769de7a63a7c27f71ad4d11215fabda8c11ece8..6ffa09c718bcb7f16eef8f3981f3bf1c5d46bf5f 100644 (file)
@@ -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);