mirror of
https://github.com/VDR4Arch/vdr.git
synced 2023-10-10 13:36:52 +02:00
Implemented daemon mode
This commit is contained in:
parent
52514313fb
commit
6602eb5c90
1
HISTORY
1
HISTORY
@ -86,3 +86,4 @@ Video Disk Recorder Revision History
|
|||||||
- Implemented the "Simple Video Disk Recorder Protocol" (SVDRP) to control
|
- Implemented the "Simple Video Disk Recorder Protocol" (SVDRP) to control
|
||||||
the VDR over a network connection.
|
the VDR over a network connection.
|
||||||
- Implemented command line option handling.
|
- Implemented command line option handling.
|
||||||
|
- The program can now run in full background mode by using the --daemon option.
|
||||||
|
4
INSTALL
4
INSTALL
@ -45,6 +45,10 @@ port ("Simple Video Disk Recorder Protocol"). By default, it listens
|
|||||||
on port 2001 (use the --port=PORT option to change this). For details
|
on port 2001 (use the --port=PORT option to change this). For details
|
||||||
about the SVDRP syntax see the source file 'svdrp.c'.
|
about the SVDRP syntax see the source file 'svdrp.c'.
|
||||||
|
|
||||||
|
If the program shall run as a daemon, use the --daemon option. This
|
||||||
|
will completely detach it from the terminal and will continue as a
|
||||||
|
background process.
|
||||||
|
|
||||||
Use "vdr --help" for a list of available command line options.
|
Use "vdr --help" for a list of available command line options.
|
||||||
|
|
||||||
The video data directory:
|
The video data directory:
|
||||||
|
30
vdr.c
30
vdr.c
@ -22,12 +22,13 @@
|
|||||||
*
|
*
|
||||||
* The project's page is at http://www.cadsoft.de/people/kls/vdr
|
* 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 <getopt.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "dvbapi.h"
|
#include "dvbapi.h"
|
||||||
#include "interface.h"
|
#include "interface.h"
|
||||||
@ -58,8 +59,10 @@ int main(int argc, char *argv[])
|
|||||||
#define DEFAULTSVDRPPORT 2001
|
#define DEFAULTSVDRPPORT 2001
|
||||||
|
|
||||||
int SVDRPport = DEFAULTSVDRPPORT;
|
int SVDRPport = DEFAULTSVDRPPORT;
|
||||||
|
bool DaemonMode = false;
|
||||||
|
|
||||||
static struct option long_options[] = {
|
static struct option long_options[] = {
|
||||||
|
{ "daemon", no_argument, NULL, 'd' },
|
||||||
{ "help", no_argument, NULL, 'h' },
|
{ "help", no_argument, NULL, 'h' },
|
||||||
{ "port", required_argument, NULL, 'p' },
|
{ "port", required_argument, NULL, 'p' },
|
||||||
{ 0 }
|
{ 0 }
|
||||||
@ -67,10 +70,12 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
int c;
|
int c;
|
||||||
int option_index = 0;
|
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) {
|
switch (c) {
|
||||||
|
case 'd': DaemonMode = true; break;
|
||||||
case 'h': printf("Usage: vdr [OPTION]\n\n"
|
case 'h': printf("Usage: vdr [OPTION]\n\n"
|
||||||
" -h, --help display this help and exit\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"
|
" -p PORT, --port=PORT use PORT for SVDRP ('0' turns off SVDRP)\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Report bugs to <vdr-bugs@cadsoft.de>\n"
|
"Report bugs to <vdr-bugs@cadsoft.de>\n"
|
||||||
@ -91,6 +96,27 @@ int main(int argc, char *argv[])
|
|||||||
// Log file:
|
// Log file:
|
||||||
|
|
||||||
openlog("vdr", LOG_PID | LOG_CONS, LOG_USER);
|
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");
|
isyslog(LOG_INFO, "started");
|
||||||
|
|
||||||
// DVB interfaces:
|
// DVB interfaces:
|
||||||
|
Loading…
Reference in New Issue
Block a user