From d0b3d7a087eb11637ef730aa35e53aeac9e2d680 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96man?= Date: Mon, 25 Jan 2010 21:13:16 +0000 Subject: [PATCH] Fix problems with settings paths --- src/main.c | 35 +++++------------------------------ src/settings.c | 32 +++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 31 deletions(-) diff --git a/src/main.c b/src/main.c index 7cc5b7d2..d8c23771 100644 --- a/src/main.c +++ b/src/main.c @@ -74,28 +74,6 @@ static int log_decorate; int log_debug_to_syslog; int log_debug_to_console; -static char confpath[256]; - - -static void -set_confpath(void) -{ - char buf[256]; - const char *homedir = getenv("HOME"); - struct stat st; - - if(homedir != NULL) { - snprintf(buf, sizeof(buf), "%s/.hts", homedir); - if(stat(buf, &st) == 0 || mkdir(buf, 0700) == 0) { - - snprintf(buf, sizeof(buf), "%s/.hts/tvheadend", homedir); - - if(stat(buf, &st) == 0 || mkdir(buf, 0700) == 0) - snprintf(confpath, sizeof(confpath), "%s", buf); - } - } -} - static void handle_sigpipe(int x) @@ -178,9 +156,7 @@ usage(const char *argv0) printf("\n"); printf(" -a Use only DVB adapters specified (csv)\n"); printf(" -c Alternate configuration path.\n" - " Defaults to [%s]\n", - *confpath ? confpath : ""); - + " Defaults to [$HOME/.hts/tvheadend]\n"); printf(" -f Fork and daemonize\n"); printf(" -u Run as user , only works with -f\n"); printf(" -g Run as group , only works with -f\n"); @@ -263,12 +239,11 @@ main(int argc, char **argv) const char *homedir; const char *rawts_input = NULL; const char *join_transport = NULL; + const char *confpath = NULL; char *p, *endp; uint32_t adapter_mask = 0xffffffff; int crash = 0; - set_confpath(); - while((c = getopt(argc, argv, "Aa:fu:g:c:Chdr:j:s")) != -1) { switch(c) { case 'a': @@ -304,7 +279,7 @@ main(int argc, char **argv) groupnam = optarg; break; case 'c': - snprintf(confpath, sizeof(confpath), "%s", optarg); + confpath = optarg; break; case 'd': log_debug_to_console = 1; @@ -372,7 +347,7 @@ main(int argc, char **argv) openlog("tvheadend", LOG_PID, logfacility); - hts_settings_init(*confpath ? confpath : NULL); + hts_settings_init(confpath); pthread_mutex_init(&ffmpeg_lock, NULL); pthread_mutex_init(&fork_lock, NULL); @@ -449,7 +424,7 @@ main(int argc, char **argv) pthread_sigmask(SIG_UNBLOCK, &set, NULL); tvhlog(LOG_NOTICE, "START", "HTS Tvheadend version %s started, " - "running as pid:%d uid:%d gid:%d, settings located in '%s'", + "running as PID:%d UID:%d GID:%d, settings located in '%s'", htsversion_full, getpid(), getuid(), getgid(), hts_settings_get_root()); diff --git a/src/settings.c b/src/settings.c index b781796b..2b207c75 100644 --- a/src/settings.c +++ b/src/settings.c @@ -50,9 +50,39 @@ hts_settings_get_root(void) void hts_settings_init(const char *confpath) { - settingspath = confpath ? strdup(confpath) : NULL; + char buf[256]; + const char *homedir = getenv("HOME"); + struct stat st; + + if(confpath != NULL) { + settingspath = strdup(confpath); + } else { + + if(homedir != NULL) { + snprintf(buf, sizeof(buf), "%s/.hts", homedir); + if(stat(buf, &st) == 0 || mkdir(buf, 0700) == 0) { + + snprintf(buf, sizeof(buf), "%s/.hts/tvheadend", homedir); + + if(stat(buf, &st) == 0 || mkdir(buf, 0700) == 0) + settingspath = strdup(buf); + } + } + } + if(settingspath == NULL) { + tvhlog(LOG_ALERT, "START", + "No configuration path set, " + "settings and configuration will not be saved"); + } else if(access(settingspath, R_OK | W_OK)) { + tvhlog(LOG_ALERT, "START", + "Configuration path %s is not read/write:able " + "by user (UID:%d, GID:%d) -- %s", + settingspath, getuid(), getgid(), strerror(errno)); + settingspath = NULL; + } } + /** * */