36#include <sys/capability.h>
39#include <systemd/sd-daemon.h>
76#define MINCHANNELWAIT 10
77#define ACTIVITYTIMEOUT 60
78#define MEMCLEANUPDELTA 3600
79#define SHUTDOWNWAIT 300
80#define SHUTDOWNRETRY 360
81#define SHUTDOWNFORCEPROMPT 5
82#define SHUTDOWNCANCELPROMPT 5
83#define RESTARTCANCELPROMPT 5
84#define MANUALSTART 600
85#define CHANNELSAVEDELTA 600
86#define DEVICEREADYTIMEOUT 30
87#define MENUTIMEOUT 120
88#define TIMERCHECKDELTA 5
89#define TIMERDEVICETIMEOUT 8
90#define TIMERLOOKAHEADTIME 60
91#define VPSLOOKAHEADTIME 24
92#define VPSUPTODATETIME 3600
94#define EXIT(v) { ShutdownHandler.Exit(v); goto Exit; }
98static bool SetUser(
const char *User,
bool UserDump)
101 struct passwd *user =
isnumber(User) ? getpwuid(atoi(User)) : getpwnam(User);
103 fprintf(stderr,
"vdr: unknown user: '%s'\n", User);
106 if (setgid(user->pw_gid) < 0) {
107 fprintf(stderr,
"vdr: cannot set group id %u: %s\n", (
unsigned int)user->pw_gid, strerror(errno));
110 if (initgroups(user->pw_name, user->pw_gid) < 0) {
111 fprintf(stderr,
"vdr: cannot set supplemental group ids for user %s: %s\n", user->pw_name, strerror(errno));
114 if (setuid(user->pw_uid) < 0) {
115 fprintf(stderr,
"vdr: cannot set user id %u: %s\n", (
unsigned int)user->pw_uid, strerror(errno));
118 if (UserDump && prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) < 0)
119 fprintf(stderr,
"vdr: warning - cannot set dumpable: %s\n", strerror(errno));
120 setenv(
"HOME", user->pw_dir, 1);
121 setenv(
"USER", user->pw_name, 1);
122 setenv(
"LOGNAME", user->pw_name, 1);
123 setenv(
"SHELL", user->pw_shell, 1);
131 cap_t caps_all = cap_get_proc();
133 fprintf(stderr,
"vdr: cap_get_proc failed: %s\n", strerror(errno));
136 cap_flag_value_t cap_flag_value;
137 if (cap_get_flag(caps_all, CAP_SYS_TIME, CAP_PERMITTED , &cap_flag_value)) {
138 fprintf(stderr,
"vdr: cap_get_flag failed: %s\n", strerror(errno));
142 if (cap_flag_value == CAP_SET)
143 caps = cap_from_text(
"= cap_sys_nice,cap_sys_time,cap_net_raw=ep");
145 fprintf(stdout,
"vdr: OS does not support cap_sys_time\n");
146 caps = cap_from_text(
"= cap_sys_nice,cap_net_raw=ep");
149 fprintf(stderr,
"vdr: cap_from_text failed: %s\n", strerror(errno));
152 if (cap_set_proc(caps) == -1) {
153 fprintf(stderr,
"vdr: cap_set_proc failed: %s\n", strerror(errno));
164 if (prctl(PR_SET_KEEPCAPS, On ? 1 : 0, 0, 0, 0) != 0) {
165 fprintf(stderr,
"vdr: prctl failed\n");
191 esyslog(
"PANIC: watchdog timer expired - exiting!");
193 sd_notify(0,
"STOPPING=1\nSTATUS=PANIC");
198int main(
int argc,
char *argv[])
202 struct termios savedTm;
203 bool HasStdin = (tcgetpgrp(STDIN_FILENO) == getpid() || getppid() != (pid_t)1) && tcgetattr(STDIN_FILENO, &savedTm) == 0;
207 setlocale(LC_ALL,
"");
211#define dd(a, b) (*a ? a : b)
212#define DEFAULTSVDRPPORT 6419
213#define DEFAULTWATCHDOG 0
214#define DEFAULTVIDEODIR VIDEODIR
215#define DEFAULTCONFDIR dd(CONFDIR, VideoDirectory)
216#define DEFAULTARGSDIR dd(ARGSDIR, "/etc/vdr/conf.d")
217#define DEFAULTCACHEDIR dd(CACHEDIR, VideoDirectory)
218#define DEFAULTRESDIR dd(RESDIR, ConfigDirectory)
219#define DEFAULTPLUGINDIR PLUGINDIR
220#define DEFAULTLOCDIR LOCDIR
221#define DEFAULTEPGDATAFILENAME "epg.data"
223 bool StartedAsRoot =
false;
224 const char *VdrUser = NULL;
225 bool UserDump =
false;
227 const char *AudioCommand = NULL;
229 const char *ConfigDirectory = NULL;
230 const char *CacheDirectory = NULL;
231 const char *ResourceDirectory = NULL;
234 bool DisplayHelp =
false;
235 bool DisplayVersion =
false;
236 bool DaemonMode =
false;
237 int SysLogTarget = LOG_USER;
238 bool MuteAudio =
false;
240 const char *Terminal = NULL;
241 const char *OverrideCharacterTable = NULL;
244 const char *LircDevice = NULL;
245#if !defined(REMOTE_KBD)
248#if defined(REMOTE_LIRC)
249 LircDevice = LIRC_DEVICE;
255 time_t SdWatchdog = 0;
256 int SdWatchdogTimeout = 0;
261 Args =
new cArgs(argv[0]);
271 static struct option long_options[] = {
272 {
"audio", required_argument, NULL,
'a' },
273 {
"cachedir", required_argument, NULL,
'c' | 0x100 },
274 {
"chartab", required_argument, NULL,
'c' | 0x200 },
275 {
"config", required_argument, NULL,
'c' },
276 {
"daemon", no_argument, NULL,
'd' },
277 {
"device", required_argument, NULL,
'D' },
278 {
"dirnames", required_argument, NULL,
'd' | 0x100 },
279 {
"edit", required_argument, NULL,
'e' | 0x100 },
280 {
"epgfile", required_argument, NULL,
'E' },
281 {
"filesize", required_argument, NULL,
'f' | 0x100 },
282 {
"genindex", required_argument, NULL,
'g' | 0x100 },
283 {
"grab", required_argument, NULL,
'g' },
284 {
"help", no_argument, NULL,
'h' },
285 {
"instance", required_argument, NULL,
'i' },
286 {
"lib", required_argument, NULL,
'L' },
287 {
"lirc", optional_argument, NULL,
'l' | 0x100 },
288 {
"localedir",required_argument, NULL,
'l' | 0x200 },
289 {
"log", required_argument, NULL,
'l' },
290 {
"mute", no_argument, NULL,
'm' },
291 {
"no-kbd", no_argument, NULL,
'n' | 0x100 },
292 {
"plugin", required_argument, NULL,
'P' },
293 {
"port", required_argument, NULL,
'p' },
294 {
"record", required_argument, NULL,
'r' },
295 {
"resdir", required_argument, NULL,
'r' | 0x100 },
296 {
"showargs", optional_argument, NULL,
's' | 0x200 },
297 {
"shutdown", required_argument, NULL,
's' },
298 {
"split", no_argument, NULL,
's' | 0x100 },
299 {
"terminal", required_argument, NULL,
't' },
300 {
"updindex", required_argument, NULL,
'u' | 0x200 },
301 {
"user", required_argument, NULL,
'u' },
302 {
"userdump", no_argument, NULL,
'u' | 0x100 },
303 {
"version", no_argument, NULL,
'V' },
304 {
"vfat", no_argument, NULL,
'v' | 0x100 },
305 {
"video", required_argument, NULL,
'v' },
306 {
"watchdog", required_argument, NULL,
'w' },
307 { NULL, no_argument, NULL, 0 }
311 while ((c = getopt_long(argc, argv,
"a:c:dD:e:E:g:hi:l:L:mp:P:r:s:t:u:v:Vw:", long_options, NULL)) != -1) {
313 case 'a': AudioCommand = optarg;
316 CacheDirectory = optarg;
319 OverrideCharacterTable = optarg;
321 case 'c': ConfigDirectory = optarg;
323 case 'd': DaemonMode =
true;
325 case 'D':
if (*optarg ==
'-') {
330 int n = atoi(optarg);
336 fprintf(stderr,
"vdr: invalid DVB device number: %s\n", optarg);
341 int n = strtol(s, &s, 10);
342 if (n <= 0 || n >= PATH_MAX) {
343 fprintf(stderr,
"vdr: invalid directory path length: %s\n", optarg);
350 fprintf(stderr,
"vdr: invalid delimiter: %s\n", optarg);
358 int n = strtol(s, &s, 10);
359 if (n <= 0 || n > NAME_MAX) {
360 fprintf(stderr,
"vdr: invalid directory name length: %s\n", optarg);
367 fprintf(stderr,
"vdr: invalid delimiter: %s\n", optarg);
374 int n = strtol(s, &s, 10);
375 if (n != 0 && n != 1) {
376 fprintf(stderr,
"vdr: invalid directory encoding: %s\n", optarg);
381 fprintf(stderr,
"vdr: unexpected data: %s\n", optarg);
388 case 'E': EpgDataFileName = (*optarg !=
'-' ? optarg : NULL);
401 case 'h': DisplayHelp =
true;
408 fprintf(stderr,
"vdr: invalid instance id: %s\n", optarg);
411 char *p = strchr(optarg,
'.');
415 int l = atoi(optarg);
416 if (0 <= l && l <= 3) {
423 if (0 <= l && l <= 7) {
424 int targets[] = { LOG_LOCAL0, LOG_LOCAL1, LOG_LOCAL2, LOG_LOCAL3, LOG_LOCAL4, LOG_LOCAL5, LOG_LOCAL6, LOG_LOCAL7 };
425 SysLogTarget = targets[l];
433 fprintf(stderr,
"vdr: invalid log level: %s\n", optarg);
436 case 'L':
if (access(optarg, R_OK | X_OK) == 0)
439 fprintf(stderr,
"vdr: can't access plugin directory: %s\n", optarg);
444 LircDevice = optarg ? optarg : LIRC_DEVICE;
447 if (access(optarg, R_OK | X_OK) == 0)
448 LocaleDirectory = optarg;
450 fprintf(stderr,
"vdr: can't access locale directory: %s\n", optarg);
454 case 'm': MuteAudio =
true;
460 SVDRPport = atoi(optarg);
462 fprintf(stderr,
"vdr: invalid port number: %s\n", optarg);
466 case 'P': PluginManager.
AddPlugin(optarg);
471 ResourceDirectory = optarg;
482 fprintf(stderr,
"vdr: can't read arguments from directory: %s\n", ArgsDir);
487 for (
int i = 1; i < c; i++)
488 printf(
"%s\n", v[i]);
491 case 't': Terminal = optarg;
492 if (access(Terminal, R_OK | W_OK) < 0) {
493 fprintf(stderr,
"vdr: can't access terminal: %s\n", Terminal);
497 case 'u':
if (*optarg)
505 case 'V': DisplayVersion =
true;
512 case 'v': VideoDirectory = optarg;
513 while (optarg && *optarg && optarg[strlen(optarg) - 1] ==
'/')
514 optarg[strlen(optarg) - 1] = 0;
518 int t = atoi(optarg);
524 fprintf(stderr,
"vdr: invalid watchdog timeout: %s\n", optarg);
532 if (DisplayHelp || DisplayVersion) {
537 printf(
"Usage: vdr [OPTIONS]\n\n"
538 " -a CMD, --audio=CMD send Dolby Digital audio to stdin of command CMD\n"
539 " --cachedir=DIR save cache files in DIR (default: %s)\n"
540 " --chartab=CHARACTER_TABLE\n"
541 " set the character table to use for strings in the\n"
542 " DVB data stream that don't begin with a character\n"
543 " table indicator, but don't use the standard default\n"
544 " character table (for instance ISO-8859-9)\n"
545 " -c DIR, --config=DIR read config files from DIR (default: %s)\n"
546 " -d, --daemon run in daemon mode\n"
547 " -D NUM, --device=NUM use only the given DVB device (NUM = 0, 1, 2...)\n"
548 " there may be several -D options (default: all DVB\n"
549 " devices will be used); if -D- is given, no DVB\n"
550 " devices will be used at all, independent of any\n"
551 " other -D options\n"
552 " --dirnames=PATH[,NAME[,ENC]]\n"
553 " set the maximum directory path length to PATH\n"
554 " (default: %d); if NAME is also given, it defines\n"
555 " the maximum directory name length (default: %d);\n"
556 " the optional ENC can be 0 or 1, and controls whether\n"
557 " special characters in directory names are encoded as\n"
558 " hex values (default: 0); if PATH or NAME are left\n"
559 " empty (as in \",,1\" to only set ENC), the defaults\n"
561 " --edit=REC cut recording REC and exit\n"
562 " -E FILE, --epgfile=FILE write the EPG data into the given FILE (default is\n"
563 " '%s' in the cache directory)\n"
564 " '-E-' disables this\n"
565 " if FILE is a directory, the default EPG file will be\n"
566 " created in that directory\n"
567 " --filesize=SIZE limit video files to SIZE bytes (default is %dM)\n"
568 " only useful in conjunction with --edit\n"
569 " --genindex=REC generate index for recording REC and exit\n"
570 " -g DIR, --grab=DIR write images from the SVDRP command GRAB into the\n"
571 " given DIR; DIR must be the full path name of an\n"
572 " existing directory, without any \"..\", double '/'\n"
573 " or symlinks (default: none, same as -g-)\n"
574 " -h, --help print this help and exit\n"
575 " -i ID, --instance=ID use ID as the id of this VDR instance (default: 0)\n"
576 " -l LEVEL, --log=LEVEL set log level (default: 3)\n"
577 " 0 = no logging, 1 = errors only,\n"
578 " 2 = errors and info, 3 = errors, info and debug\n"
579 " if logging should be done to LOG_LOCALn instead of\n"
580 " LOG_USER, add '.n' to LEVEL, as in 3.7 (n=0..7)\n"
581 " -L DIR, --lib=DIR search for plugins in DIR (default is %s)\n"
582 " --lirc[=PATH] use a LIRC remote control device, attached to PATH\n"
584 " --localedir=DIR search for locale files in DIR (default is\n"
586 " -m, --mute mute audio of the primary DVB device at startup\n"
587 " --no-kbd don't use the keyboard as an input device\n"
588 " -p PORT, --port=PORT use PORT for SVDRP (default: %d)\n"
589 " 0 turns off SVDRP\n"
590 " -P OPT, --plugin=OPT load a plugin defined by the given options\n"
591 " -r CMD, --record=CMD call CMD before and after a recording, and after\n"
592 " a recording has been edited or deleted\n"
593 " --resdir=DIR read resource files from DIR (default: %s)\n"
594 " -s CMD, --shutdown=CMD call CMD to shutdown the computer\n"
595 " --split split edited files at the editing marks (only\n"
596 " useful in conjunction with --edit)\n"
597 " --showargs[=DIR] print the arguments read from DIR and exit\n"
599 " -t TTY, --terminal=TTY controlling tty\n"
600 " -u USER, --user=USER run as user USER; only applicable if started as\n"
601 " root; USER can be a user name or a numerical id\n"
602 " --updindex=REC update index for recording REC and exit\n"
603 " --userdump allow coredumps if -u is given (debugging)\n"
604 " -v DIR, --video=DIR use DIR as video directory (default: %s)\n"
605 " -V, --version print version information and exit\n"
606 " --vfat for backwards compatibility (same as\n"
607 " --dirnames=250,40,1)\n"
608 " -w SEC, --watchdog=SEC activate the watchdog timer with a timeout of SEC\n"
609 " seconds (default: %d); '0' disables the watchdog\n"
631 printf(
"Plugins: vdr -P\"name [OPTIONS]\"\n\n");
632 for (
int i = 0; ; i++) {
637 if (DisplayHelp && help) {
652 openlog(
"vdr", LOG_CONS, SysLogTarget);
657 if (daemon(1, 0) == -1) {
658 fprintf(stderr,
"vdr: %m\n");
665 stdin = freopen(Terminal,
"r", stdin);
666 stdout = freopen(Terminal,
"w", stdout);
667 stderr = freopen(Terminal,
"w", stderr);
669 tcgetattr(STDIN_FILENO, &savedTm);
674 if (VdrUser && geteuid() == 0) {
675 StartedAsRoot =
true;
676 if (strcmp(VdrUser,
"root") && strcmp(VdrUser,
"0")) {
679 if (!
SetUser(VdrUser, UserDump))
691 fprintf(stderr,
"vdr: can't access video directory %s\n", VideoDirectory);
696 if (StartedAsRoot && VdrUser)
697 isyslog(
"switched to user '%s'", VdrUser);
704 char *CodeSet = NULL;
705 if (setlocale(LC_CTYPE,
""))
706 CodeSet = nl_langinfo(CODESET);
708 char *LangEnv = getenv(
"LANG");
710 CodeSet = strchr(LangEnv,
'.');
717 isyslog(
"codeset is '%s' - %s", CodeSet, known ?
"known" :
"unknown");
720 if (OverrideCharacterTable) {
722 isyslog(
"override character table is '%s' - %s", OverrideCharacterTable, known ?
"known" :
"unknown");
734 int LastTimerChannel = -1;
735 int PreviousChannel[2] = { 1, 1 };
736 int PreviousChannelIndex = 0;
737 time_t LastChannelChanged = time(NULL);
738 time_t LastInteract = 0;
739 int MaxLatencyTime = 0;
740 bool IsInfoMenu =
false;
741 cSkin *CurrentSkin = NULL;
742 int OldPrimaryDVB = 0;
751 if (!ConfigDirectory)
757 if (!ResourceDirectory)
780 const char *msg =
"no fonts available - OSD will not show any text!";
781 fprintf(stderr,
"vdr: %s\n", msg);
791 if (EpgDataFileName) {
792 const char *EpgDirectory = NULL;
794 EpgDirectory = EpgDataFileName;
797 else if (*EpgDataFileName !=
'/' && *EpgDataFileName !=
'.')
798 EpgDirectory = CacheDirectory;
803 EpgDataReader.
Start();
825 isyslog(
"trying device number %d instead", i + 1);
833 const char *msg =
"no primary device found - using first device!";
834 fprintf(stderr,
"vdr: %s\n", msg);
839 const char *msg =
"no primary device found - giving up!";
840 fprintf(stderr,
"vdr: %s\n", msg);
880 if (!DaemonMode && HasStdin && UseKbd)
928 if (signal(SIGHUP,
SignalHandler) == SIG_IGN) signal(SIGHUP, SIG_IGN);
929 if (signal(SIGINT,
SignalHandler) == SIG_IGN) signal(SIGINT, SIG_IGN);
930 if (signal(SIGTERM,
SignalHandler) == SIG_IGN) signal(SIGTERM, SIG_IGN);
931 if (signal(SIGPIPE,
SignalHandler) == SIG_IGN) signal(SIGPIPE, SIG_IGN);
932 if (WatchdogTimeout > 0)
933 if (signal(SIGALRM,
Watchdog) == SIG_IGN) signal(SIGALRM, SIG_IGN);
937 if (WatchdogTimeout > 0) {
938 dsyslog(
"setting watchdog timer to %d seconds", WatchdogTimeout);
939 alarm(WatchdogTimeout);
943 if (sd_watchdog_enabled(0, NULL) > 0) {
945 SdWatchdog = time(NULL);
946 sd_watchdog_enabled(0, &timeout);
947 SdWatchdogTimeout = (int)timeout/1000000;
948 dsyslog(
"SD_WATCHDOG enabled with timeout set to %d seconds", SdWatchdogTimeout);
953 sd_notify(0,
"READY=1\nSTATUS=Ready");
963#define DELETE_MENU ((IsInfoMenu &= (Menu == NULL)), delete Menu, Menu = NULL)
966#ifdef DEBUGRINGBUFFERS
967 cRingBufferLinear::PrintDebugRBL();
972 time_t Now = time(NULL);
976 static time_t lastTime = 0;
981 if (Channel && (Channel->
Vpid() || Channel->
Apid(0) || Channel->
Dpid(0))) {
984 else if (LastTimerChannel > 0) {
985 Channel = Channels->GetByNumber(LastTimerChannel);
991 LastTimerChannel = -1;
999 static time_t lastOsdSizeUpdate = 0;
1000 if (Now != lastOsdSizeUpdate) {
1002 static int OsdState = 0;
1007 lastOsdSizeUpdate = Now;
1011 if (WatchdogTimeout > 0) {
1012 int LatencyTime = WatchdogTimeout - alarm(WatchdogTimeout);
1013 if (LatencyTime > MaxLatencyTime) {
1014 MaxLatencyTime = LatencyTime;
1015 dsyslog(
"max. latency time %d seconds", MaxLatencyTime);
1020 if (SdWatchdogTimeout && (Now - SdWatchdog) * 2 > SdWatchdogTimeout) {
1021 sd_notify(0,
"WATCHDOG=1");
1030 static time_t ChannelSaveTimeout = 0;
1032 static cStateKey ChannelsStateKey(
true);
1033 static int ChannelsModifiedByUser = 0;
1036 if (ChannelSaveTimeout != 1) {
1039 ChannelSaveTimeout = 1;
1040 else if (!ChannelSaveTimeout)
1044 ChannelSaveTimeout = 1;
1047 ChannelSaveTimeout = 1;
1048 if (Timers && Channels) {
1051 ChannelSaveTimeout = 0;
1054 for (
const cChannel *Channel = Channels->
First(); Channel; Channel = Channels->
Next(Channel)) {
1060 isyslog(
"retuning due to modification of channel %d (%s)", Channel->Number(), Channel->Name());
1061 Channels->
SwitchTo(Channel->Number());
1071 ChannelsStateKey.
Remove();
1074 if (ChannelSaveTimeout == 1) {
1076 ChannelsStateKey.
Reset();
1077 TimersStateKey.
Reset();
1085 LastChannelChanged = Now;
1087 if (Now - LastChannelChanged >=
Setup.
ZapTimeout && LastChannel != PreviousChannel[PreviousChannelIndex])
1088 PreviousChannel[PreviousChannelIndex ^= 1] = LastChannel;
1098 SchedulesStateKey.
Reset();
1099 bool TimersModified =
false;
1104 TimersModified =
true;
1107 TimersModified =
true;
1110 TimersModified =
true;
1112 SchedulesStateKey.
Remove();
1114 TimersStateKey.
Remove(TimersModified);
1119 bool TimersModified =
false;
1121 TimersModified =
true;
1125 Timer->SetPending(
true);
1127 LastTimerChannel = Timer->Channel()->Number();
1128 TimersModified =
true;
1131 static time_t LastTimerCheck = 0;
1133 for (
cTimer *Timer = Timers->
First(); Timer; Timer = Timers->
Next(Timer)) {
1134 if (Timer->Remote() || Timer->IsPatternTimer())
1136 bool InVpsMargin =
false;
1137 bool NeedsTransponder =
false;
1138 if (Timer->HasFlags(
tfActive) && !Timer->Recording()) {
1139 if (Timer->HasFlags(
tfVps)) {
1142 else if (Timer->Event()) {
1143 InVpsMargin = Timer->Event()->StartTime() <= Now && Now < Timer->Event()->EndTime();
1148 const cSchedule *Schedule = Schedules->GetSchedule(Timer->Channel());
1149 InVpsMargin = !Schedule;
1156 if (!Timer->Recording())
1157 Timer->SetInVpsMargin(InVpsMargin);
1158 if (NeedsTransponder || InVpsMargin) {
1173 dsyslog(
"switching device %d to channel %d %s (%s)", Device->
DeviceNumber() + 1, Timer->Channel()->Number(), *Timer->Channel()->GetChannelID().ToString(), Timer->Channel()->Name());
1178 LastTimerChannel = Timer->Channel()->Number();
1184 LastTimerCheck = Now;
1188 TimersModified =
true;
1191 if (MaxPriority >= 0)
1193 TimersStateKey.
Remove(TimersModified);
1207 if (!NeedsFastResponse) {
1232 bool WasOpen = Interact != NULL;
1233 bool WasMenu = Interact && Interact->
IsMenu();
1271 #define DirectMainFunction(function)\
1275 Menu = new cMenuMain(function);\
1297 esyslog(
"ERROR: unknown plugin '%s'", PluginName);
1389 isyslog(
"Power button pressed");
1416 Interact = Menu ? Menu : Control;
1420 if (state ==
osUnknown && Interact != Control) {
1423 if (state ==
osEnd) {
1464 case osEnd:
if (Interact == Menu)
1484 if (PreviousChannel[PreviousChannelIndex ^ 1] == LastChannel || LastChannel != PreviousChannel[0] && LastChannel != PreviousChannel[1])
1485 PreviousChannelIndex ^= 1;
1487 Channels->SwitchTo(PreviousChannel[PreviousChannelIndex ^= 1]);
1510 case kOk: LastChannel = -1;
break;
1537 if (NewPrimaryDVB != OldPrimaryDVB) {
1544 OldPrimaryDVB = NewPrimaryDVB;
1588 static time_t LastMemoryCleanup = 0;
1591 LastMemoryCleanup = Now;
1603 esyslog(
"emergency exit requested - shutting down");
1608 signal(SIGHUP, SIG_DFL);
1609 signal(SIGINT, SIG_DFL);
1610 signal(SIGTERM, SIG_DFL);
1611 signal(SIGPIPE, SIG_DFL);
1612 signal(SIGALRM, SIG_DFL);
1641 if (WatchdogTimeout > 0)
1642 dsyslog(
"max. latency time %d seconds", MaxLatencyTime);
1651 tcsetattr(STDIN_FILENO, TCSANOW, &savedTm);
1654 sd_notify(0,
"STOPPING=1\nSTATUS=Startup failed, exiting");
1656 sd_notify(0,
"STOPPING=1\nSTATUS=Exiting");
#define CHANNELMOD_RETUNE
#define LOCK_CHANNELS_READ
cChannelCamRelations ChannelCamRelations
cCiResourceHandlers CiResourceHandlers
bool CamResponsesLoad(const char *FileName, bool AllowComments, bool MustExist)
char ** GetArgv(void) const
bool ReadDirectory(const char *Directory)
bool WaitForAllCamSlotsReady(int Timeout=0)
Waits until all CAM slots have become ready, or the given Timeout (seconds) has expired.
void Load(const char *FileName)
bool ModifiedByUser(int &State) const
Returns true if the channels have been modified by the user since the last call to this function with...
static const cChannels * GetChannelsRead(cStateKey &StateKey, int TimeoutMs=0)
Gets the list of channels for read access.
bool SwitchTo(int Number) const
static bool Load(const char *FileName, bool AllowComments=false, bool MustExist=false)
static void SetSystemCharacterTable(const char *CharacterTable)
bool Load(const char *FileName=NULL, bool AllowComments=false, bool MustExist=false)
static cControl * Control(cMutexLock &MutexLock, bool Hidden=false)
Returns the current replay control (if any) in case it is currently visible.
static void Shutdown(void)
virtual cOsdObject * GetInfo(void)
Returns an OSD object that displays information about the currently played programme.
static void Launch(cControl *Control)
virtual void Hide(void)=0
bool Update(void)
Update status display of the countdown.
void Start(const char *Message, int Seconds)
Start the 5 minute shutdown warning countdown.
void Cancel(void)
Cancel the 5 minute shutdown warning countdown.
bool Done(void)
Check if countdown timer has run out without canceling.
static bool WaitForAllDevicesReady(int Timeout=0)
Waits until all devices have become ready, or the given Timeout (seconds) has expired.
static cDevice * ActualDevice(void)
Returns the actual receiving device in case of Transfer Mode, or the primary device otherwise.
static cDevice * PrimaryDevice(void)
Returns the primary device.
static void SetUseDevice(int n)
Sets the 'useDevice' flag of the given device.
static cDevice * GetDevice(int Index)
Gets the device with the given Index.
static void Shutdown(void)
Closes down all devices.
bool SwitchChannel(const cChannel *Channel, bool LiveView)
Switches the device to the given Channel, initiating transfer mode if necessary.
int DeviceNumber(void) const
Returns the number of this device (0 ... numDevices - 1).
static int CurrentChannel(void)
Returns the number of the current channel on the primary device.
bool IsPrimaryDevice(bool CheckDecoder=true) const
static bool SetPrimaryDevice(int n)
Sets the primary device to 'n'.
void StopReplay(void)
Stops the current replay session (if any).
void SetVolume(int Volume, bool Absolute=false)
Sets the volume to the given value, either absolutely or relative to the current volume.
static int NumDevices(void)
Returns the total number of devices.
virtual bool HasDecoder(void) const
Tells whether this device has an MPEG decoder.
virtual bool HasProgramme(void) const
Returns true if the device is currently showing any programme to the user, either through replaying o...
static int CurrentVolume(void)
virtual bool IsTunedToTransponder(const cChannel *Channel) const
Returns true if this device is currently tuned to the given Channel's transponder.
static cDevice * GetDeviceForTransponder(const cChannel *Channel, int Priority)
Returns a device that is not currently "occupied" and can be tuned to the transponder of the given Ch...
void SetOccupied(int Seconds, int Priority=MINPRIORITY, time_t From=0)
Sets the occupied timeout for this device to the given number of Seconds, This can be used to tune a ...
bool ToggleMute(void)
Turns the volume off or on and returns the new mute state.
bool Load(const char *FileName, bool AllowComments=false, bool MustExist=false)
static void Process(eKeys Key)
static cDisplaySubtitleTracks * Create(void)
static cDisplayTracks * Create(void)
static void Process(eKeys Key)
static cDisplayVolume * Create(void)
static void Process(eKeys Key)
bool Load(const char *FileName)
static bool BondDevices(const char *Bondings)
Bonds the devices as defined in the given Bondings string.
static bool useDvbDevices
static bool Initialize(void)
Initializes the DVB devices.
static cString GetFontFileName(const char *FontName)
Returns the actual font file name for the given FontName.
bool Confirm(const char *s, int Seconds=10, bool WaitForTimeout=false)
eKeys GetKey(bool Wait=true)
const cKeyMacro * Get(eKeys Key)
static void NewLircRemote(const char *Name)
void SetSyncStateKey(cStateKey &StateKey)
When making changes to this list (while holding a write lock) that shall not affect some other code t...
void Purge(bool Force=false)
const T * First(void) const
Returns the first element in this list, or NULL if the list is empty.
const T * Next(const T *Object) const
< Returns the element immediately before Object in this list, or NULL if Object is the first element ...
static cOsdObject * PluginOsdObject(void)
bool Load(const char *FileName)
virtual bool NeedsFastResponse(void)
virtual eOSState ProcessKey(eKeys Key)
static bool OsdSizeChanged(int &State)
Checks if the OSD size has changed and a currently displayed OSD needs to be redrawn.
static void Shutdown(void)
Shuts down the OSD provider facility by deleting the current OSD provider.
static void UpdateOsdSize(bool Force=false)
Inquires the actual size of the video display and adjusts the OSD and font sizes accordingly.
static int IsOpen(void)
Returns true if there is currently a level 0 OSD open.
void MainThreadHook(void)
void SetDirectory(const char *Directory)
bool InitializePlugins(void)
void AddPlugin(const char *Args)
static bool HasPlugins(void)
bool LoadPlugins(bool Log=false)
void Shutdown(bool Log=false)
static cPlugin * GetPlugin(int Index)
virtual const char * CommandLineHelp(void)
virtual const char * Version(void)=0
static void SetCacheDirectory(const char *Dir)
virtual cOsdObject * MainMenuAction(void)
static void SetConfigDirectory(const char *Dir)
static void SetResourceDirectory(const char *Dir)
virtual const char * Description(void)=0
static cPositioner * GetPositioner(void)
Returns a previously created positioner.
static void DestroyPositioner(void)
Destroys a previously created positioner.
static void ChannelDataModified(const cChannel *Channel)
static bool Process(cTimers *Timers, time_t t)
static bool PauseLiveVideo(void)
static void Shutdown(void)
static bool Start(cTimers *Timers, cTimer *Timer, bool Pause=false)
static void SetCommand(const char *Command)
void DelAll(void)
Deletes/terminates all operations.
bool Finished(bool &Error)
Returns true if all operations in the list have been finished.
static void Update(bool Wait=false)
Triggers an update of the list of recordings, which will run as a separate thread if Wait is false.
static bool NeedsUpdate(void)
static const char * GetPlugin(void)
Returns the name of the plugin that was set with a previous call to PutMacro() or CallPlugin().
bool Put(uint64_t Code, bool Repeat=false, bool Release=false)
static bool PutMacro(eKeys Key)
static time_t LastActivity(void)
Absolute time when last key was delivered by Get().
static const char * LastReplayed(void)
bool PresentSeenWithin(int Seconds) const
static const cSchedules * GetSchedulesRead(cStateKey &StateKey, int TimeoutMs=0)
Gets the list of schedules for read access.
static void SetEpgDataFileName(const char *FileName)
static void Cleanup(bool Force=false)
bool Load(const char *FileName, bool AllowComments=false, bool MustExist=false)
char OSDTheme[MaxThemeName]
char OSDSkin[MaxSkinName]
bool Load(const char *FileName)
char FontOsd[MAXFONTNAME]
void CheckManualStart(int ManualStart)
Check whether the next timer is in ManualStart time window.
void SetShutdownCommand(const char *ShutdownCommand)
Set the command string for shutdown command.
bool ConfirmShutdown(bool Ask)
Check for background activity that blocks shutdown.
bool EmergencyExitRequested(void)
Returns true if an emergency exit was requested.
void SetRetry(int Seconds)
Set shutdown retry so that VDR will not try to automatically shut down within Seconds.
bool Retry(time_t AtTime=0)
Check whether its time to re-try the shutdown.
bool IsUserInactive(time_t AtTime=0)
Check whether VDR is in interactive mode or non-interactive mode (waiting for shutdown).
bool DoShutdown(bool Force)
Call the shutdown script with data of the next pending timer.
bool ConfirmRestart(bool Ask)
Check for background activity that blocks restart.
void Exit(int ExitCode)
Set VDR exit code and initiate end of VDR main loop.
void SetUserInactiveTimeout(int Seconds=-1, bool Force=false)
Set the time in the future when VDR will switch into non-interactive mode or power down.
bool DoExit(void)
Check if an exit code was set, and VDR should exit.
void SetUserInactive(void)
Set VDR manually into non-interactive mode from now on.
int GetExitCode(void)
Get the currently set exit code of VDR.
bool SetCurrent(const char *Name=NULL)
Sets the current skin to the one indicated by name.
eKeys Message(eMessageType Type, const char *s, int Seconds=0)
Displays the given message, either through a currently visible display object that is capable of doin...
cSkin * Current(void)
Returns a pointer to the current skin.
virtual void Clear(void)
Free up all registered skins.
void ProcessQueuedMessages(void)
Processes the first queued message, if any.
int QueueMessage(eMessageType Type, const char *s, int Seconds=0, int Timeout=0)
Like Message(), but this function may be called from a background thread.
void Remove(bool IncState=true)
Removes this key from the lock it was previously used with.
void Reset(void)
Resets the state of this key, so that the next call to a lock's Lock() function with this key will re...
bool StateChanged(void)
Returns true if this key is used for obtaining a write lock, and the lock's state differs from that o...
static void MsgChannelChange(const cChannel *Channel)
static void SetThemesDirectory(const char *ThemesDirectory)
bool Load(const char *SkinName)
static void SetMainThreadId(void)
void bool Start(void)
Sets the description of this thread, which will be used when logging starting or stopping of the thre...
bool Active(void)
Checks whether the thread is still alive.
static tThreadId ThreadId(void)
static bool Load(const char *FileName)
int GetMaxPriority(void) const
Returns the maximum priority of all local timers that are currently recording.
static cTimers * GetTimersWrite(cStateKey &StateKey, int TimeoutMs=0)
Gets the list of timers for write access.
static const cTimers * GetTimersRead(cStateKey &StateKey, int TimeoutMs=0)
Gets the list of timers for read access.
const cTimer * GetMatch(time_t t) const
bool SpawnPatternTimers(const cSchedules *Schedules)
bool DeleteExpired(bool Force)
bool SetEvents(const cSchedules *Schedules)
bool AdjustSpawnedTimers(void)
static void Destroy(void)
static void SetName(const char *Name)
cNestedItemList RecordingCommands
bool CutRecording(const char *FileName)
void ReportEpgBugFixStats(bool Force)
#define LOCK_SCHEDULES_READ
void I18nInitialize(const char *LocaleDir)
Detects all available locales and loads the language names and codes.
bool SetSystemCharacterTable(const char *CharacterTable)
bool SetOverrideCharacterTable(const char *CharacterTable)
bool GenerateIndex(const char *FileName, bool Update)
Generates the index of the existing recording with the given FileName.
void AssertFreeDiskSpace(int Priority, bool Force)
The special Priority value -1 means that we shall get rid of any deleted recordings faster than norma...
cDoneRecordings DoneRecordingsPattern
cRecordingsHandler RecordingsHandler
void RemoveDeletedRecordings(void)
#define MAXVIDEOFILESIZEDEFAULT
#define MAXVIDEOFILESIZETS
cShutdownHandler ShutdownHandler
cSourceParams SourceParams
static tChannelID FromString(const char *s)
void StopSVDRPHandler(void)
void SetSVDRPGrabImageDir(const char *GrabImageDir)
void StartSVDRPHandler(void)
void SetSVDRPPorts(int TcpPort, int UdpPort)
cStateKey StateKeySVDRPRemoteTimersPoll
Controls whether a change to the local list of timers needs to result in sending a POLL to the remote...
static bool SetUser(const char *User, bool UserDump)
#define SHUTDOWNFORCEPROMPT
int main(int argc, char *argv[])
#define TIMERLOOKAHEADTIME
#define SHUTDOWNCANCELPROMPT
#define DEFAULTEPGDATAFILENAME
static void SignalHandler(int signum)
static bool SetKeepCaps(bool On)
#define DirectMainFunction(function)
#define TIMERDEVICETIMEOUT
static bool DropCaps(void)
static void Watchdog(int signum)
#define RESTARTCANCELPROMPT
#define DEVICEREADYTIMEOUT