diff options
author | Klaus Schmidinger <vdr@tvdr.de> | 2000-07-23 15:36:43 +0200 |
---|---|---|
committer | Klaus Schmidinger <vdr@tvdr.de> | 2000-07-23 15:36:43 +0200 |
commit | 6602eb5c90210906273a5b9a15aa0d2d1d095a16 (patch) | |
tree | 2e11db4adf480374f27644b3bb6466686be94aa3 /vdr.c | |
parent | 52514313fbb740517a65da615de18d3e6e9e151a (diff) | |
download | vdr-6602eb5c90210906273a5b9a15aa0d2d1d095a16.tar.gz vdr-6602eb5c90210906273a5b9a15aa0d2d1d095a16.tar.bz2 |
Implemented daemon mode
Diffstat (limited to 'vdr.c')
-rw-r--r-- | vdr.c | 34 |
1 files changed, 30 insertions, 4 deletions
@@ -22,12 +22,13 @@ * * The project's page is at http://www.cadsoft.de/people/kls/vdr * - * $Id: vdr.c 1.22 2000/07/23 14:53:22 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" @@ -58,19 +59,23 @@ int main(int argc, char *argv[]) #define DEFAULTSVDRPPORT 2001 int SVDRPport = DEFAULTSVDRPPORT; + bool DaemonMode = false; static struct option long_options[] = { - { "help", no_argument, NULL, 'h' }, - { "port", required_argument, NULL, 'p' }, + { "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, "hp:", long_options, &option_index)) != -1) { + 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" @@ -91,6 +96,27 @@ int main(int argc, char *argv[]) // 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: |