From d1339821446d3af1f1847f8abb8bfac90fed5698 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96man?= Date: Thu, 16 Oct 2008 15:50:30 +0000 Subject: [PATCH] If /var/lib/hts/tvheadend does not exist and we're thinking of storing settings there, try to create it. --- main.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index f84ffcb9..ad167d5f 100644 --- a/main.c +++ b/main.c @@ -194,6 +194,7 @@ main(int argc, char **argv) int logfacility = LOG_DAEMON; sigset_t set; const char *settingspath = NULL; + struct stat st; signal(SIGPIPE, handle_sigpipe); @@ -227,7 +228,20 @@ main(int argc, char **argv) if(settingspath == NULL) { settingspath = "/var/lib/hts/tvheadend"; - if(chown(settingspath, pw ? pw->pw_uid : 1, grp ? grp->gr_gid : 1)) + if(stat(settingspath, &st)) { + /* Path does not exist */ + + if(mkdir("/var/lib/hts", 0777) && errno != EEXIST) { + settingspath = NULL; + } else if(mkdir("/var/lib/hts/tvheadend", 0777) && errno != EEXIST) { + settingspath = NULL; + } else { + + } + } + + if(settingspath != NULL && + chown(settingspath, pw ? pw->pw_uid : 1, grp ? grp->gr_gid : 1)) settingspath = NULL; }