35#include <sys/capability.h>
38#include <systemd/sd-daemon.h>
75#define MINCHANNELWAIT 10
76#define ACTIVITYTIMEOUT 60
77#define SHUTDOWNWAIT 300
78#define SHUTDOWNRETRY 360
79#define SHUTDOWNFORCEPROMPT 5
80#define SHUTDOWNCANCELPROMPT 5
81#define RESTARTCANCELPROMPT 5
82#define MANUALSTART 600
83#define CHANNELSAVEDELTA 600
84#define DEVICEREADYTIMEOUT 30
85#define MENUTIMEOUT 120
86#define TIMERCHECKDELTA 10
87#define TIMERDEVICETIMEOUT 8
88#define TIMERLOOKAHEADTIME 60
89#define VPSLOOKAHEADTIME 24
90#define VPSUPTODATETIME 3600
92#define EXIT(v) { ShutdownHandler.Exit(v); goto Exit; }
96static bool SetUser(
const char *User,
bool UserDump)
99 struct passwd *user =
isnumber(User) ? getpwuid(atoi(User)) : getpwnam(User);
101 fprintf(stderr,
"vdr: unknown user: '%s'\n", User);
104 if (setgid(user->pw_gid) < 0) {
105 fprintf(stderr,
"vdr: cannot set group id %u: %s\n", (
unsigned int)user->pw_gid, strerror(errno));
108 if (initgroups(user->pw_name, user->pw_gid) < 0) {
109 fprintf(stderr,
"vdr: cannot set supplemental group ids for user %s: %s\n", user->pw_name, strerror(errno));
112 if (setuid(user->pw_uid) < 0) {
113 fprintf(stderr,
"vdr: cannot set user id %u: %s\n", (
unsigned int)user->pw_uid, strerror(errno));
116 if (UserDump && prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) < 0)
117 fprintf(stderr,
"vdr: warning - cannot set dumpable: %s\n", strerror(errno));
118 setenv(
"HOME", user->pw_dir, 1);
119 setenv(
"USER", user->pw_name, 1);
120 setenv(
"LOGNAME", user->pw_name, 1);
121 setenv(
"SHELL", user->pw_shell, 1);
129 cap_t caps_all = cap_get_proc();
131 fprintf(stderr,
"vdr: cap_get_proc failed: %s\n", strerror(errno));
134 cap_flag_value_t cap_flag_value;
135 if (cap_get_flag(caps_all, CAP_SYS_TIME, CAP_PERMITTED , &cap_flag_value)) {
136 fprintf(stderr,
"vdr: cap_get_flag failed: %s\n", strerror(errno));
140 if (cap_flag_value == CAP_SET)
141 caps = cap_from_text(
"= cap_sys_nice,cap_sys_time,cap_net_raw=ep");
143 fprintf(stdout,
"vdr: OS does not support cap_sys_time\n");
144 caps = cap_from_text(
"= cap_sys_nice,cap_net_raw=ep");
147 fprintf(stderr,
"vdr: cap_from_text failed: %s\n", strerror(errno));
150 if (cap_set_proc(caps) == -1) {
151 fprintf(stderr,
"vdr: cap_set_proc failed: %s\n", strerror(errno));
162 if (prctl(PR_SET_KEEPCAPS, On ? 1 : 0, 0, 0, 0) != 0) {
163 fprintf(stderr,
"vdr: prctl failed\n");
189 esyslog(
"PANIC: watchdog timer expired - exiting!");
191 sd_notify(0,
"STOPPING=1\nSTATUS=PANIC");
196int main(
int argc,
char *argv[])
200 struct termios savedTm;
201 bool HasStdin = (tcgetpgrp(STDIN_FILENO) == getpid() || getppid() != (pid_t)1) && tcgetattr(STDIN_FILENO, &savedTm) == 0;
205 setlocale(LC_ALL,
"");
209#define dd(a, b) (*a ? a : b)
210#define DEFAULTSVDRPPORT 6419
211#define DEFAULTWATCHDOG 0
212#define DEFAULTVIDEODIR VIDEODIR
213#define DEFAULTCONFDIR dd(CONFDIR, VideoDirectory)
214#define DEFAULTARGSDIR dd(ARGSDIR, "/etc/vdr/conf.d")
215#define DEFAULTCACHEDIR dd(CACHEDIR, VideoDirectory)
216#define DEFAULTRESDIR dd(RESDIR, ConfigDirectory)
217#define DEFAULTPLUGINDIR PLUGINDIR
218#define DEFAULTLOCDIR LOCDIR
219#define DEFAULTEPGDATAFILENAME "epg.data"
221 bool StartedAsRoot =
false;
222 const char *VdrUser = NULL;
223 bool UserDump =
false;
225 const char *AudioCommand = NULL;
227 const char *ConfigDirectory = NULL;
228 const char *CacheDirectory = NULL;
229 const char *ResourceDirectory = NULL;
232 bool DisplayHelp =
false;
233 bool DisplayVersion =
false;
234 bool DaemonMode =
false;
235 int SysLogTarget = LOG_USER;
236 bool MuteAudio =
false;
238 const char *Terminal = NULL;
242 const char *LircDevice = NULL;
243#if !defined(REMOTE_KBD)
246#if defined(REMOTE_LIRC)
247 LircDevice = LIRC_DEVICE;
253 time_t SdWatchdog = 0;
254 int SdWatchdogTimeout = 0;
259 Args =
new cArgs(argv[0]);
269 static struct option long_options[] = {
270 {
"audio", required_argument, NULL,
'a' },
271 {
"cachedir", required_argument, NULL,
'c' | 0x100 },
272 {
"chartab", required_argument, NULL,
'c' | 0x200 },
273 {
"config", required_argument, NULL,
'c' },
274 {
"daemon", no_argument, NULL,
'd' },
275 {
"device", required_argument, NULL,
'D' },
276 {
"dirnames", required_argument, NULL,
'd' | 0x100 },
277 {
"edit", required_argument, NULL,
'e' | 0x100 },
278 {
"epgfile", required_argument, NULL,
'E' },
279 {
"filesize", required_argument, NULL,
'f' | 0x100 },
280 {
"genindex", required_argument, NULL,
'g' | 0x100 },
281 {
"grab", required_argument, NULL,
'g' },
282 {
"help", no_argument, NULL,
'h' },
283 {
"instance", required_argument, NULL,
'i' },
284 {
"lib", required_argument, NULL,
'L' },
285 {
"lirc", optional_argument, NULL,
'l' | 0x100 },
286 {
"localedir",required_argument, NULL,
'l' | 0x200 },
287 {
"log", required_argument, NULL,
'l' },
288 {
"mute", no_argument, NULL,
'm' },
289 {
"no-kbd", no_argument, NULL,
'n' | 0x100 },
290 {
"plugin", required_argument, NULL,
'P' },
291 {
"port", required_argument, NULL,
'p' },
292 {
"record", required_argument, NULL,
'r' },
293 {
"resdir", required_argument, NULL,
'r' | 0x100 },
294 {
"showargs", optional_argument, NULL,
's' | 0x200 },
295 {
"shutdown", required_argument, NULL,
's' },
296 {
"split", no_argument, NULL,
's' | 0x100 },
297 {
"terminal", required_argument, NULL,
't' },
298 {
"updindex", required_argument, NULL,
'u' | 0x200 },
299 {
"user", required_argument, NULL,
'u' },
300 {
"userdump", no_argument, NULL,
'u' | 0x100 },
301 {
"version", no_argument, NULL,
'V' },
302 {
"vfat", no_argument, NULL,
'v' | 0x100 },
303 {
"video", required_argument, NULL,
'v' },
304 {
"watchdog", required_argument, NULL,
'w' },
305 { NULL, no_argument, NULL, 0 }
309 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) {
311 case 'a': AudioCommand = optarg;
314 CacheDirectory = optarg;
319 case 'c': ConfigDirectory = optarg;
321 case 'd': DaemonMode =
true;
323 case 'D':
if (*optarg ==
'-') {
328 int n = atoi(optarg);
334 fprintf(stderr,
"vdr: invalid DVB device number: %s\n", optarg);
339 int n = strtol(s, &s, 10);
340 if (n <= 0 || n >= PATH_MAX) {
341 fprintf(stderr,
"vdr: invalid directory path length: %s\n", optarg);
348 fprintf(stderr,
"vdr: invalid delimiter: %s\n", optarg);
356 int n = strtol(s, &s, 10);
357 if (n <= 0 || n > NAME_MAX) {
358 fprintf(stderr,
"vdr: invalid directory name length: %s\n", optarg);
365 fprintf(stderr,
"vdr: invalid delimiter: %s\n", optarg);
372 int n = strtol(s, &s, 10);
373 if (n != 0 && n != 1) {
374 fprintf(stderr,
"vdr: invalid directory encoding: %s\n", optarg);
379 fprintf(stderr,
"vdr: unexpected data: %s\n", optarg);
386 case 'E': EpgDataFileName = (*optarg !=
'-' ? optarg : NULL);
399 case 'h': DisplayHelp =
true;
406 fprintf(stderr,
"vdr: invalid instance id: %s\n", optarg);
409 char *p = strchr(optarg,
'.');
413 int l = atoi(optarg);
414 if (0 <= l && l <= 3) {
421 if (0 <= l && l <= 7) {
422 int targets[] = { LOG_LOCAL0, LOG_LOCAL1, LOG_LOCAL2, LOG_LOCAL3, LOG_LOCAL4, LOG_LOCAL5, LOG_LOCAL6, LOG_LOCAL7 };
423 SysLogTarget = targets[l];
431 fprintf(stderr,
"vdr: invalid log level: %s\n", optarg);
434 case 'L':
if (access(optarg, R_OK | X_OK) == 0)
437 fprintf(stderr,
"vdr: can't access plugin directory: %s\n", optarg);
442 LircDevice = optarg ? optarg : LIRC_DEVICE;
445 if (access(optarg, R_OK | X_OK) == 0)
446 LocaleDirectory = optarg;
448 fprintf(stderr,
"vdr: can't access locale directory: %s\n", optarg);
452 case 'm': MuteAudio =
true;
458 SVDRPport = atoi(optarg);
460 fprintf(stderr,
"vdr: invalid port number: %s\n", optarg);
464 case 'P': PluginManager.
AddPlugin(optarg);
469 ResourceDirectory = optarg;
480 fprintf(stderr,
"vdr: can't read arguments from directory: %s\n", ArgsDir);
485 for (
int i = 1; i < c; i++)
486 printf(
"%s\n", v[i]);
489 case 't': Terminal = optarg;
490 if (access(Terminal, R_OK | W_OK) < 0) {
491 fprintf(stderr,
"vdr: can't access terminal: %s\n", Terminal);
495 case 'u':
if (*optarg)
503 case 'V': DisplayVersion =
true;
510 case 'v': VideoDirectory = optarg;
511 while (optarg && *optarg && optarg[strlen(optarg) - 1] ==
'/')
512 optarg[strlen(optarg) - 1] = 0;
516 int t = atoi(optarg);
522 fprintf(stderr,
"vdr: invalid watchdog timeout: %s\n", optarg);
530 if (VdrUser && geteuid() == 0) {
531 StartedAsRoot =
true;
532 if (strcmp(VdrUser,
"root") && strcmp(VdrUser,
"0")) {
535 if (!
SetUser(VdrUser, UserDump))
546 if (DisplayHelp || DisplayVersion) {
551 printf(
"Usage: vdr [OPTIONS]\n\n"
552 " -a CMD, --audio=CMD send Dolby Digital audio to stdin of command CMD\n"
553 " --cachedir=DIR save cache files in DIR (default: %s)\n"
554 " --chartab=CHARACTER_TABLE\n"
555 " set the character table to use for strings in the\n"
556 " DVB data stream that don't begin with a character\n"
557 " table indicator, but don't use the standard default\n"
558 " character table (for instance ISO-8859-9)\n"
559 " -c DIR, --config=DIR read config files from DIR (default: %s)\n"
560 " -d, --daemon run in daemon mode\n"
561 " -D NUM, --device=NUM use only the given DVB device (NUM = 0, 1, 2...)\n"
562 " there may be several -D options (default: all DVB\n"
563 " devices will be used); if -D- is given, no DVB\n"
564 " devices will be used at all, independent of any\n"
565 " other -D options\n"
566 " --dirnames=PATH[,NAME[,ENC]]\n"
567 " set the maximum directory path length to PATH\n"
568 " (default: %d); if NAME is also given, it defines\n"
569 " the maximum directory name length (default: %d);\n"
570 " the optional ENC can be 0 or 1, and controls whether\n"
571 " special characters in directory names are encoded as\n"
572 " hex values (default: 0); if PATH or NAME are left\n"
573 " empty (as in \",,1\" to only set ENC), the defaults\n"
575 " --edit=REC cut recording REC and exit\n"
576 " -E FILE, --epgfile=FILE write the EPG data into the given FILE (default is\n"
577 " '%s' in the cache directory)\n"
578 " '-E-' disables this\n"
579 " if FILE is a directory, the default EPG file will be\n"
580 " created in that directory\n"
581 " --filesize=SIZE limit video files to SIZE bytes (default is %dM)\n"
582 " only useful in conjunction with --edit\n"
583 " --genindex=REC generate index for recording REC and exit\n"
584 " -g DIR, --grab=DIR write images from the SVDRP command GRAB into the\n"
585 " given DIR; DIR must be the full path name of an\n"
586 " existing directory, without any \"..\", double '/'\n"
587 " or symlinks (default: none, same as -g-)\n"
588 " -h, --help print this help and exit\n"
589 " -i ID, --instance=ID use ID as the id of this VDR instance (default: 0)\n"
590 " -l LEVEL, --log=LEVEL set log level (default: 3)\n"
591 " 0 = no logging, 1 = errors only,\n"
592 " 2 = errors and info, 3 = errors, info and debug\n"
593 " if logging should be done to LOG_LOCALn instead of\n"
594 " LOG_USER, add '.n' to LEVEL, as in 3.7 (n=0..7)\n"
595 " -L DIR, --lib=DIR search for plugins in DIR (default is %s)\n"
596 " --lirc[=PATH] use a LIRC remote control device, attached to PATH\n"
598 " --localedir=DIR search for locale files in DIR (default is\n"
600 " -m, --mute mute audio of the primary DVB device at startup\n"
601 " --no-kbd don't use the keyboard as an input device\n"
602 " -p PORT, --port=PORT use PORT for SVDRP (default: %d)\n"
603 " 0 turns off SVDRP\n"
604 " -P OPT, --plugin=OPT load a plugin defined by the given options\n"
605 " -r CMD, --record=CMD call CMD before and after a recording, and after\n"
606 " a recording has been edited or deleted\n"
607 " --resdir=DIR read resource files from DIR (default: %s)\n"
608 " -s CMD, --shutdown=CMD call CMD to shutdown the computer\n"
609 " --split split edited files at the editing marks (only\n"
610 " useful in conjunction with --edit)\n"
611 " --showargs[=DIR] print the arguments read from DIR and exit\n"
613 " -t TTY, --terminal=TTY controlling tty\n"
614 " -u USER, --user=USER run as user USER; only applicable if started as\n"
615 " root; USER can be a user name or a numerical id\n"
616 " --updindex=REC update index for recording REC and exit\n"
617 " --userdump allow coredumps if -u is given (debugging)\n"
618 " -v DIR, --video=DIR use DIR as video directory (default: %s)\n"
619 " -V, --version print version information and exit\n"
620 " --vfat for backwards compatibility (same as\n"
621 " --dirnames=250,40,1)\n"
622 " -w SEC, --watchdog=SEC activate the watchdog timer with a timeout of SEC\n"
623 " seconds (default: %d); '0' disables the watchdog\n"
645 printf(
"Plugins: vdr -P\"name [OPTIONS]\"\n\n");
646 for (
int i = 0; ; i++) {
651 if (DisplayHelp && help) {
666 openlog(
"vdr", LOG_CONS, SysLogTarget);
671 fprintf(stderr,
"vdr: can't access video directory %s\n", VideoDirectory);
678 if (daemon(1, 0) == -1) {
679 fprintf(stderr,
"vdr: %m\n");
686 stdin = freopen(Terminal,
"r", stdin);
687 stdout = freopen(Terminal,
"w", stdout);
688 stderr = freopen(Terminal,
"w", stderr);
690 tcgetattr(STDIN_FILENO, &savedTm);
694 if (StartedAsRoot && VdrUser)
695 isyslog(
"switched to user '%s'", VdrUser);
702 char *CodeSet = NULL;
703 if (setlocale(LC_CTYPE,
""))
704 CodeSet = nl_langinfo(CODESET);
706 char *LangEnv = getenv(
"LANG");
708 CodeSet = strchr(LangEnv,
'.');
715 isyslog(
"codeset is '%s' - %s", CodeSet, known ?
"known" :
"unknown");
732 int LastTimerChannel = -1;
733 int PreviousChannel[2] = { 1, 1 };
734 int PreviousChannelIndex = 0;
735 time_t LastChannelChanged = time(NULL);
736 time_t LastInteract = 0;
737 int MaxLatencyTime = 0;
738 bool InhibitEpgScan =
false;
739 bool IsInfoMenu =
false;
740 cSkin *CurrentSkin = NULL;
741 int OldPrimaryDVB = 0;
750 if (!ConfigDirectory)
756 if (!ResourceDirectory)
779 const char *msg =
"no fonts available - OSD will not show any text!";
780 fprintf(stderr,
"vdr: %s\n", msg);
790 if (EpgDataFileName) {
791 const char *EpgDirectory = NULL;
793 EpgDirectory = EpgDataFileName;
796 else if (*EpgDataFileName !=
'/' && *EpgDataFileName !=
'.')
797 EpgDirectory = CacheDirectory;
802 EpgDataReader.
Start();
824 isyslog(
"trying device number %d instead", i + 1);
832 const char *msg =
"no primary device found - using first device!";
833 fprintf(stderr,
"vdr: %s\n", msg);
838 const char *msg =
"no primary device found - giving up!";
839 fprintf(stderr,
"vdr: %s\n", msg);
879 if (!DaemonMode && HasStdin && UseKbd)
925 if (signal(SIGHUP,
SignalHandler) == SIG_IGN) signal(SIGHUP, SIG_IGN);
926 if (signal(SIGINT,
SignalHandler) == SIG_IGN) signal(SIGINT, SIG_IGN);
927 if (signal(SIGTERM,
SignalHandler) == SIG_IGN) signal(SIGTERM, SIG_IGN);
928 if (signal(SIGPIPE,
SignalHandler) == SIG_IGN) signal(SIGPIPE, SIG_IGN);
929 if (WatchdogTimeout > 0)
930 if (signal(SIGALRM,
Watchdog) == SIG_IGN) signal(SIGALRM, SIG_IGN);
934 if (WatchdogTimeout > 0) {
935 dsyslog(
"setting watchdog timer to %d seconds", WatchdogTimeout);
936 alarm(WatchdogTimeout);
940 if (sd_watchdog_enabled(0, NULL) > 0) {
942 SdWatchdog = time(NULL);
943 sd_watchdog_enabled(0, &timeout);
944 SdWatchdogTimeout = (int)timeout/1000000;
945 dsyslog(
"SD_WATCHDOG enabled with timeout set to %d seconds", SdWatchdogTimeout);
950 sd_notify(0,
"READY=1\nSTATUS=Ready");
960#define DELETE_MENU ((IsInfoMenu &= (Menu == NULL)), delete Menu, Menu = NULL)
963#ifdef DEBUGRINGBUFFERS
964 cRingBufferLinear::PrintDebugRBL();
969 time_t Now = time(NULL);
973 static time_t lastTime = 0;
978 if (Channel && (Channel->
Vpid() || Channel->
Apid(0) || Channel->
Dpid(0))) {
981 else if (LastTimerChannel > 0) {
982 Channel = Channels->GetByNumber(LastTimerChannel);
988 LastTimerChannel = -1;
996 static time_t lastOsdSizeUpdate = 0;
997 if (Now != lastOsdSizeUpdate) {
999 static int OsdState = 0;
1004 lastOsdSizeUpdate = Now;
1008 if (WatchdogTimeout > 0) {
1009 int LatencyTime = WatchdogTimeout - alarm(WatchdogTimeout);
1010 if (LatencyTime > MaxLatencyTime) {
1011 MaxLatencyTime = LatencyTime;
1012 dsyslog(
"max. latency time %d seconds", MaxLatencyTime);
1017 if (SdWatchdogTimeout && (Now - SdWatchdog) * 2 > SdWatchdogTimeout) {
1018 sd_notify(0,
"WATCHDOG=1");
1027 static time_t ChannelSaveTimeout = 0;
1029 static cStateKey ChannelsStateKey(
true);
1030 static int ChannelsModifiedByUser = 0;
1033 if (ChannelSaveTimeout != 1) {
1036 ChannelSaveTimeout = 1;
1037 else if (!ChannelSaveTimeout)
1041 ChannelSaveTimeout = 1;
1044 ChannelSaveTimeout = 1;
1045 if (Timers && Channels) {
1048 ChannelSaveTimeout = 0;
1051 for (
const cChannel *Channel = Channels->
First(); Channel; Channel = Channels->
Next(Channel)) {
1057 isyslog(
"retuning due to modification of channel %d (%s)", Channel->Number(), Channel->Name());
1058 Channels->
SwitchTo(Channel->Number());
1068 ChannelsStateKey.
Remove();
1071 if (ChannelSaveTimeout == 1) {
1073 ChannelsStateKey.
Reset();
1074 TimersStateKey.
Reset();
1082 LastChannelChanged = Now;
1084 if (Now - LastChannelChanged >=
Setup.
ZapTimeout && LastChannel != PreviousChannel[PreviousChannelIndex])
1085 PreviousChannel[PreviousChannelIndex ^= 1] = LastChannel;
1095 SchedulesStateKey.
Reset();
1096 bool TimersModified =
false;
1101 TimersModified =
true;
1104 TimersModified =
true;
1107 TimersModified =
true;
1109 SchedulesStateKey.
Remove();
1111 TimersStateKey.
Remove(TimersModified);
1116 bool TimersModified =
false;
1118 TimersModified =
true;
1122 Timer->SetPending(
true);
1124 LastTimerChannel = Timer->Channel()->Number();
1125 TimersModified =
true;
1128 static time_t LastTimerCheck = 0;
1130 InhibitEpgScan =
false;
1131 for (
cTimer *Timer = Timers->
First(); Timer; Timer = Timers->
Next(Timer)) {
1132 if (Timer->Remote() || Timer->IsPatternTimer())
1134 bool InVpsMargin =
false;
1135 bool NeedsTransponder =
false;
1136 if (Timer->HasFlags(
tfActive) && !Timer->Recording()) {
1137 if (Timer->HasFlags(
tfVps)) {
1140 Timer->SetInVpsMargin(InVpsMargin);
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;
1152 InhibitEpgScan |= InVpsMargin | NeedsTransponder;
1157 if (NeedsTransponder || InVpsMargin) {
1160 if (!Device && InVpsMargin)
1168 dsyslog(
"switching device %d to channel %d %s (%s)", Device->
DeviceNumber() + 1, Timer->Channel()->Number(), *Timer->Channel()->GetChannelID().ToString(), Timer->Channel()->Name());
1177 LastTimerCheck = Now;
1181 TimersModified =
true;
1184 if (MaxPriority >= 0)
1186 TimersStateKey.
Remove(TimersModified);
1200 if (!NeedsFastResponse) {
1225 bool WasOpen = Interact != NULL;
1226 bool WasMenu = Interact && Interact->
IsMenu();
1264 #define DirectMainFunction(function)\
1268 Menu = new cMenuMain(function);\
1290 esyslog(
"ERROR: unknown plugin '%s'", PluginName);
1382 isyslog(
"Power button pressed");
1409 Interact = Menu ? Menu : Control;
1413 if (state ==
osUnknown && Interact != Control) {
1416 if (state ==
osEnd) {
1457 case osEnd:
if (Interact == Menu)
1477 if (PreviousChannel[PreviousChannelIndex ^ 1] == LastChannel || LastChannel != PreviousChannel[0] && LastChannel != PreviousChannel[1])
1478 PreviousChannelIndex ^= 1;
1480 Channels->SwitchTo(PreviousChannel[PreviousChannelIndex ^= 1]);
1503 case kOk: LastChannel = -1;
break;
1518 if (!InhibitEpgScan)
1531 if (NewPrimaryDVB != OldPrimaryDVB) {
1538 OldPrimaryDVB = NewPrimaryDVB;
1591 esyslog(
"emergency exit requested - shutting down");
1596 signal(SIGHUP, SIG_DFL);
1597 signal(SIGINT, SIG_DFL);
1598 signal(SIGTERM, SIG_DFL);
1599 signal(SIGPIPE, SIG_DFL);
1600 signal(SIGALRM, SIG_DFL);
1629 if (WatchdogTimeout > 0)
1630 dsyslog(
"max. latency time %d seconds", MaxLatencyTime);
1639 tcsetattr(STDIN_FILENO, TCSANOW, &savedTm);
1642 sd_notify(0,
"STOPPING=1\nSTATUS=Startup failed, exiting");
1644 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 void Shutdown(void)
virtual cOsdObject * GetInfo(void)
Returns an OSD object that displays information about the currently played programme.
static cControl * Control(bool Hidden=false)
Old version of this function, for backwards compatibility with plugins.
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.
bool IsPrimaryDevice(void) const
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.
void SetOccupied(int Seconds)
Sets the occupied timeout for this device to the given number of Seconds, This can be used to tune a ...
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.
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...
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 Initialize(void)
Initializes the DVB devices.
static bool useDvbDevices
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)
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 OSDSkin[MaxSkinName]
bool Load(const char *FileName)
char FontOsd[MAXFONTNAME]
char OSDTheme[MaxThemeName]
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.
#define MAXVIDEOFILESIZEDEFAULT
#define MAXVIDEOFILESIZETS
cDoneRecordings DoneRecordingsPattern
cRecordingsHandler RecordingsHandler
void RemoveDeletedRecordings(void)
bool GenerateIndex(const char *FileName, bool Update=false)
Generates the index of the existing recording with the given FileName.
void AssertFreeDiskSpace(int Priority=0, bool Force=false)
The special Priority value -1 means that we shall get rid of any deleted recordings faster than norma...
cShutdownHandler ShutdownHandler
cSourceParams SourceParams
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...
bool SetSystemCharacterTable(const char *CharacterTable)
static char * OverrideCharacterTable
bool SetOverrideCharacterTable(const char *CharacterTable)
static tChannelID FromString(const char *s)
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