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)
printf("\n");
printf(" -a <adapters> Use only DVB adapters specified (csv)\n");
printf(" -c <directory> Alternate configuration path.\n"
- " Defaults to [%s]\n",
- *confpath ? confpath : "<unset>");
-
+ " Defaults to [$HOME/.hts/tvheadend]\n");
printf(" -f Fork and daemonize\n");
printf(" -u <username> Run as user <username>, only works with -f\n");
printf(" -g <groupname> Run as group <groupname>, only works with -f\n");
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':
groupnam = optarg;
break;
case 'c':
- snprintf(confpath, sizeof(confpath), "%s", optarg);
+ confpath = optarg;
break;
case 'd':
log_debug_to_console = 1;
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);
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());
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;
+ }
}
+
/**
*
*/