[Aggregator] Daemon mode (-D)

This commit is contained in:
Matteo Cypriani 2012-01-07 16:21:55 +01:00
parent 2ed7ccd4bc
commit a4857e4b1f
2 changed files with 17 additions and 1 deletions

View File

@ -9,7 +9,7 @@
/* Arguments & program configuration */
#define OPTIONS "a:Ac:C:f:hi:k:K:l:o:p:qt:vV" // getopt string
#define OPTIONS "a:Ac:C:Df:hi:k:K:l:o:p:qt:vV" // getopt string
#define DEFAULT_CONFIG_FILE "/usr/local/etc/owlps/owlps-aggregator.conf"
#define DEFAULT_AGGREGATE_TIMEOUT 1500 // milliseconds
#define DEFAULT_KEEP_TIMEOUT 3000 // milliseconds

View File

@ -102,6 +102,14 @@ int main(int argc, char **argv)
}
}
if (cfg_getbool(cfg, "daemon"))
{
if (VERBOSE_WARNING)
fprintf(stderr, "Detaching to background...\n") ;
if (daemon(0, 0))
perror("Cannot daemonize") ;
}
ret = read_loop(sockfd) ;
/* Wait for the threads to terminate */
@ -197,6 +205,9 @@ int parse_config_file(int argc, char **argv)
// Config file options for confuse
cfg_opt_t opts[] =
{
// Daemon mode
CFG_BOOL("daemon", cfg_false, CFGF_NONE),
// Verbose level
CFG_INT("verbose", 0, CFGF_NONE),
@ -307,6 +318,9 @@ int parse_command_line(int argc, char **argv)
case 'C' :
cfg_setint(cfg, "ap_check_interval", strtol(optarg, NULL, 0)) ;
break ;
case 'D' :
cfg_setbool(cfg, "daemon", cfg_true) ;
break ;
case 'f' : // Config file
break ; // (already parsed)
case 'i' :
@ -1309,6 +1323,7 @@ void print_usage()
printf("Usage:\n"
"\t%s"
" [-f config_file]"
" [-D]"
" [-v[v[v[v]]] | -q]"
" -o output_file"
" [-i positionner_ip]"
@ -1330,6 +1345,7 @@ void print_usage()
"\t-V\t\tShow version information.\n"
"\t-f config_file\tUse 'config_file' instead of the default"
" configuration file (%s).\n"
"\t-D\t\tDaemon mode.\n"
"\t-v\t\tBe verbose. You can use this option up to 4 times to"
" increase the level of verbosity (1 = warnings, 2 = useful"
" information, 3 = too much information, 4 = displays the"