From 50f0dc7f9c0e3e7325f2cad421774329adb4f5ef Mon Sep 17 00:00:00 2001 From: Adam Sutton Date: Fri, 27 Dec 2013 23:39:37 +0000 Subject: [PATCH] main: provide option to make daemon dumpable --- src/main.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/main.c b/src/main.c index 61a9025d..967eddfb 100644 --- a/src/main.c +++ b/src/main.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -417,6 +418,7 @@ main(int argc, char **argv) int log_level = LOG_INFO; int log_options = TVHLOG_OPT_MILLIS | TVHLOG_OPT_STDERR | TVHLOG_OPT_SYSLOG; const char *log_debug = NULL, *log_trace = NULL; + char buf[512]; /* Defaults */ tvheadend_webui_port = 9981; @@ -437,7 +439,8 @@ main(int argc, char **argv) opt_fileline = 0, opt_threadid = 0, opt_ipv6 = 0, - opt_tsfile_tuner = 0; + opt_tsfile_tuner = 0, + opt_dump = 0; const char *opt_config = NULL, *opt_user = NULL, *opt_group = NULL, @@ -496,6 +499,7 @@ main(int argc, char **argv) { 0, "threadid", "Add the thread ID to debug", OPT_BOOL, &opt_threadid }, { 0, "uidebug", "Enable webUI debug (non-minified JS)", OPT_BOOL, &opt_uidebug }, { 'A', "abort", "Immediately abort", OPT_BOOL, &opt_abort }, + { 'D', "dump", "Enable coredumps for daemon", OPT_BOOL, &opt_dump }, { 0, "noacl", "Disable all access control checks", OPT_BOOL, &opt_noacl }, { 'j', "join", "Subscribe to a service permanently", @@ -675,6 +679,13 @@ main(int argc, char **argv) fclose(pidfile); } + /* Make dumpable */ + if (opt_dump) { + if (chdir("/tmp")) + tvhwarn("START", "failed to change cwd to /tmp"); + prctl(PR_SET_DUMPABLE, 1); + } + umask(0); } @@ -790,9 +801,10 @@ 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'", - tvheadend_version, - getpid(), getuid(), getgid(), hts_settings_get_root()); + "running as PID:%d UID:%d GID:%d, CWD:%s CNF:%s", + tvheadend_version, + getpid(), getuid(), getgid(), getcwd(buf, sizeof(buf)), + hts_settings_get_root()); if(opt_abort) abort(); @@ -815,10 +827,7 @@ main(int argc, char **argv) if(opt_fork) unlink(opt_pidpath); - // TODO: could join all threads for clean shutdown - return 0; - } /**