diff options
Diffstat (limited to 'vdr.c')
-rw-r--r-- | vdr.c | 84 |
1 files changed, 82 insertions, 2 deletions
@@ -22,15 +22,19 @@ * * The project's page is at http://www.cadsoft.de/people/kls/vdr * - * $Id: vdr.c 1.20 2000/07/15 11:45:05 kls Exp $ + * $Id: vdr.c 1.23 2000/07/23 15:36:43 kls Exp $ */ +#include <getopt.h> #include <signal.h> +#include <stdlib.h> +#include <unistd.h> #include "config.h" #include "dvbapi.h" #include "interface.h" #include "menu.h" #include "recording.h" +#include "svdrp.h" #include "tools.h" #ifdef REMOTE_KBD @@ -50,15 +54,83 @@ void SignalHandler(int signum) int main(int argc, char *argv[]) { + // Command line options: + +#define DEFAULTSVDRPPORT 2001 + + int SVDRPport = DEFAULTSVDRPPORT; + bool DaemonMode = false; + + static struct option long_options[] = { + { "daemon", no_argument, NULL, 'd' }, + { "help", no_argument, NULL, 'h' }, + { "port", required_argument, NULL, 'p' }, + { 0 } + }; + + int c; + int option_index = 0; + while ((c = getopt_long(argc, argv, "dhp:", long_options, &option_index)) != -1) { + switch (c) { + case 'd': DaemonMode = true; break; + case 'h': printf("Usage: vdr [OPTION]\n\n" + " -h, --help display this help and exit\n" + " -d, --daemon run in daemon mode\n" + " -p PORT, --port=PORT use PORT for SVDRP ('0' turns off SVDRP)\n" + "\n" + "Report bugs to <vdr-bugs@cadsoft.de>\n" + ); + return 0; + break; + case 'p': if (isnumber(optarg)) + SVDRPport = strtol(optarg, NULL, 10); + else { + fprintf(stderr, "vdr: invalid port number: %s\n", optarg); + return 1; + } + break; + default: abort(); + } + } + + // Log file: + openlog("vdr", LOG_PID | LOG_CONS, LOG_USER); + + // Daemon mode: + + if (DaemonMode) { +#ifndef DEBUG_OSD + pid_t pid = fork(); + if (pid < 0) { + fprintf(stderr, "%s\n", strerror(errno)); + esyslog(LOG_ERR, strerror(errno)); + return 1; + } + if (pid != 0) + return 0; // initial program immediately returns + fclose(stdin); + fclose(stdout); + fclose(stderr); +#else + fprintf(stderr, "vdr: can't run in daemon mode with DEBUG_OSD on!\n"); + abort(); +#endif + } isyslog(LOG_INFO, "started"); + // DVB interfaces: + if (!cDvbApi::Init()) return 1; + // Configuration data: + Channels.Load("channels.conf"); Timers.Load("timers.conf"); -#ifndef REMOTE_LIRC +#ifdef REMOTE_LIRC + Keys.SetDummyValues(); +#else if (!Keys.Load(KEYS_CONF)) Interface.LearnKeys(); #endif @@ -66,10 +138,15 @@ int main(int argc, char *argv[]) cChannel::SwitchTo(CurrentChannel); + // Signal handlers: + if (signal(SIGHUP, SignalHandler) == SIG_IGN) signal(SIGHUP, SIG_IGN); if (signal(SIGINT, SignalHandler) == SIG_IGN) signal(SIGINT, SIG_IGN); if (signal(SIGTERM, SignalHandler) == SIG_IGN) signal(SIGTERM, SIG_IGN); + // Main program loop: + + cSVDRP *SVDRP = SVDRPport ? new cSVDRP(SVDRPport) : NULL; cMenuMain *Menu = NULL; cReplayControl *ReplayControl = NULL; int dcTime = 0, dcNumber = 0; @@ -155,10 +232,13 @@ int main(int argc, char *argv[]) default: break; } } + if (SVDRP) + SVDRP->Process();//TODO lock menu vs. SVDRP? } isyslog(LOG_INFO, "caught signal %d", Interrupted); delete Menu; delete ReplayControl; + delete SVDRP; cDvbApi::Cleanup(); isyslog(LOG_INFO, "exiting"); closelog(); |