summaryrefslogtreecommitdiff
path: root/vdr.c
diff options
context:
space:
mode:
Diffstat (limited to 'vdr.c')
-rw-r--r--vdr.c111
1 files changed, 89 insertions, 22 deletions
diff --git a/vdr.c b/vdr.c
index 698cc7a..938afcf 100644
--- a/vdr.c
+++ b/vdr.c
@@ -22,7 +22,7 @@
*
* The project's page is at http://www.cadsoft.de/people/kls/vdr
*
- * $Id: vdr.c 1.49 2001/01/14 15:29:51 kls Exp $
+ * $Id: vdr.c 1.54 2001/02/24 16:18:43 kls Exp $
*/
#include <getopt.h>
@@ -44,6 +44,8 @@
#define KEYS_CONF "keys.conf"
#endif
+#define ACTIVITYTIMEOUT 60 // seconds before starting housekeeping
+
static int Interrupted = 0;
static void SignalHandler(int signum)
@@ -53,48 +55,76 @@ static void SignalHandler(int signum)
signal(signum, SignalHandler);
}
+static void Watchdog(int signum)
+{
+ // Something terrible must have happened that prevented the 'alarm()' from
+ // being called in time, so let's get out of here:
+ esyslog(LOG_ERR, "PANIC: watchdog timer expired - exiting!");
+ exit(1);
+}
+
int main(int argc, char *argv[])
{
// Command line options:
#define DEFAULTSVDRPPORT 2001
+#define DEFAULTWATCHDOG 0 // seconds
int SVDRPport = DEFAULTSVDRPPORT;
const char *ConfigDirectory = NULL;
bool DaemonMode = false;
+ int WatchdogTimeout = DEFAULTWATCHDOG;
static struct option long_options[] = {
- { "config", required_argument, NULL, 'c' },
- { "daemon", no_argument, NULL, 'd' },
- { "help", no_argument, NULL, 'h' },
- { "log", required_argument, NULL, 'l' },
- { "port", required_argument, NULL, 'p' },
- { "video", required_argument, NULL, 'v' },
+ { "config", required_argument, NULL, 'c' },
+ { "daemon", no_argument, NULL, 'd' },
+ { "device", required_argument, NULL, 'D' },
+ { "help", no_argument, NULL, 'h' },
+ { "log", required_argument, NULL, 'l' },
+ { "port", required_argument, NULL, 'p' },
+ { "video", required_argument, NULL, 'v' },
+ { "watchdog", required_argument, NULL, 'w' },
{ 0 }
};
int c;
int option_index = 0;
- while ((c = getopt_long(argc, argv, "c:dhl:p:v:", long_options, &option_index)) != -1) {
+ while ((c = getopt_long(argc, argv, "c:dD:hl:p:v:w:", long_options, &option_index)) != -1) {
switch (c) {
case 'c': ConfigDirectory = optarg;
break;
case 'd': DaemonMode = true; break;
+ case 'D': if (isnumber(optarg)) {
+ int n = atoi(optarg);
+ if (0 <= n && n < MAXDVBAPI) {
+ cDvbApi::SetUseDvbApi(n);
+ break;
+ }
+ }
+ fprintf(stderr, "vdr: invalid DVB device number: %s\n", optarg);
+ abort();
+ break;
case 'h': printf("Usage: vdr [OPTION]\n\n" // for easier orientation, this is column 80|
- " -c DIR, --config=DIR read config files from DIR (default is to read them\n"
- " from the video directory)\n"
- " -h, --help display this help and exit\n"
- " -d, --daemon run in daemon mode\n"
- " -l LEVEL, --log=LEVEL set log level (default: 3)\n"
- " 0 = no logging, 1 = errors only,\n"
- " 2 = errors and info, 3 = errors, info and debug\n"
- " -p PORT, --port=PORT use PORT for SVDRP (default: %d)\n"
- " 0 turns off SVDRP\n"
- " -v DIR, --video=DIR use DIR as video directory (default is %s)\n"
+ " -c DIR, --config=DIR read config files from DIR (default is to read them\n"
+ " from the video directory)\n"
+ " -h, --help display this help and exit\n"
+ " -d, --daemon run in daemon mode\n"
+ " -D NUM, --device=NUM use only the given DVB device (NUM = 0, 1, 2...)\n"
+ " there may be several -D options (default: all DVB\n"
+ " devices will be used)\n"
+ " -l LEVEL, --log=LEVEL set log level (default: 3)\n"
+ " 0 = no logging, 1 = errors only,\n"
+ " 2 = errors and info, 3 = errors, info and debug\n"
+ " -p PORT, --port=PORT use PORT for SVDRP (default: %d)\n"
+ " 0 turns off SVDRP\n"
+ " -v DIR, --video=DIR use DIR as video directory (default is %s)\n"
+ " -w SEC, --watchdog=SEC activate the watchdog timer with a timeout of SEC\n"
+ " seconds (default: %d); '0' disables the watchdog\n"
"\n"
"Report bugs to <vdr-bugs@cadsoft.de>\n",
DEFAULTSVDRPPORT,
- VideoDirectory
+ VideoDirectory,
+ DEFAULTWATCHDOG
);
return 0;
break;
@@ -119,6 +149,16 @@ int main(int argc, char *argv[])
while (optarg && *optarg && optarg[strlen(optarg) - 1] == '/')
optarg[strlen(optarg) - 1] = 0;
break;
+ case 'w': if (isnumber(optarg)) {
+ int t = atoi(optarg);
+ if (t >= 0) {
+ WatchdogTimeout = t;
+ break;
+ }
+ }
+ fprintf(stderr, "vdr: invalid watchdog timeout: %s\n", optarg);
+ abort();
+ break;
default: abort();
}
}
@@ -166,9 +206,9 @@ int main(int argc, char *argv[])
Channels.Load(AddDirectory(ConfigDirectory, "channels.conf"));
Timers.Load(AddDirectory(ConfigDirectory, "timers.conf"));
Commands.Load(AddDirectory(ConfigDirectory, "commands.conf"));
-#ifdef REMOTE_LIRC
+#if defined(REMOTE_LIRC)
Keys.SetDummyValues();
-#else
+#elif !defined(REMOTE_NONE)
bool KeysLoaded = Keys.Load(AddDirectory(ConfigDirectory, KEYS_CONF));
#endif
@@ -186,7 +226,7 @@ int main(int argc, char *argv[])
// User interface:
Interface = new cInterface(SVDRPport);
-#ifndef REMOTE_LIRC
+#if !defined(REMOTE_LIRC) && !defined(REMOTE_NONE)
if (!KeysLoaded)
Interface->LearnKeys();
#endif
@@ -197,6 +237,8 @@ int main(int argc, char *argv[])
if (signal(SIGINT, SignalHandler) == SIG_IGN) signal(SIGINT, SIG_IGN);
if (signal(SIGTERM, SignalHandler) == SIG_IGN) signal(SIGTERM, SIG_IGN);
if (signal(SIGPIPE, SignalHandler) == SIG_IGN) signal(SIGPIPE, SIG_IGN);
+ if (WatchdogTimeout > 0)
+ if (signal(SIGALRM, Watchdog) == SIG_IGN) signal(SIGALRM, SIG_IGN);
// Main program loop:
@@ -204,8 +246,23 @@ int main(int argc, char *argv[])
cReplayControl *ReplayControl = NULL;
int LastChannel = -1;
int PreviousChannel = cDvbApi::CurrentChannel();
+ time_t LastActivity = time(NULL);
+ int MaxLatencyTime = 0;
+
+ if (WatchdogTimeout > 0) {
+ dsyslog(LOG_INFO, "setting watchdog timer to %d seconds", WatchdogTimeout);
+ alarm(WatchdogTimeout); // Initial watchdog timer start
+ }
while (!Interrupted) {
+ // Restart the Watchdog timer:
+ if (WatchdogTimeout > 0) {
+ int LatencyTime = WatchdogTimeout - alarm(WatchdogTimeout);
+ if (LatencyTime > MaxLatencyTime) {
+ MaxLatencyTime = LatencyTime;
+ dsyslog(LOG_INFO, "max. latency time %d seconds", MaxLatencyTime);
+ }
+ }
// Channel display:
if (!EITScanner.Active() && cDvbApi::CurrentChannel() != LastChannel) {
if (!Menu)
@@ -310,6 +367,14 @@ int main(int argc, char *argv[])
EITScanner.Process();
cVideoCutter::Active();
}
+ if (!*Interact && !cRecordControls::Active()) {
+ if (time(NULL) - LastActivity > ACTIVITYTIMEOUT) {
+ RemoveDeletedRecordings();
+ LastActivity = time(NULL);
+ }
+ }
+ else
+ LastActivity = time(NULL);
}
isyslog(LOG_INFO, "caught signal %d", Interrupted);
Setup.CurrentChannel = cDvbApi::CurrentChannel();
@@ -319,6 +384,8 @@ int main(int argc, char *argv[])
delete ReplayControl;
delete Interface;
cDvbApi::Cleanup();
+ if (WatchdogTimeout > 0)
+ dsyslog(LOG_INFO, "max. latency time %d seconds", MaxLatencyTime);
isyslog(LOG_INFO, "exiting");
if (SysLogLevel > 0)
closelog();