[Listener] Daemon mode (-D)
Basic implementation of the daemon mode.
This commit is contained in:
parent
cf73bf6309
commit
2ed7ccd4bc
|
@ -62,7 +62,7 @@
|
|||
|
||||
|
||||
/* Arguments & program configuration */
|
||||
#define OPTIONS "a:Af:hH:i:I:Kl:m:n:p:P:qr:t:vVw:" // getopt string
|
||||
#define OPTIONS "a:ADf:hH:i:I:Kl:m:n:p:P:qr:t:vVw:" // getopt string
|
||||
#define DEFAULT_CONFIG_FILE "/usr/local/etc/owlps/owlps-listener.conf"
|
||||
enum {MODE_ACTIVE = 'a', MODE_PASSIVE = 'p', MODE_MIXED = 'm'} ;
|
||||
#define DEFAULT_AUTOCALIBRATION_HELLO_DELAY 120 // seconds
|
||||
|
@ -213,6 +213,10 @@ void print_version(void) ;
|
|||
(cfg_setint(cfg, "mode", (MODE)))
|
||||
#define GET_MODE() \
|
||||
(cfg_getint(cfg, "mode"))
|
||||
#define SET_DAEMON() \
|
||||
(cfg_setbool(cfg, "daemon", cfg_true))
|
||||
#define GET_DAEMON() \
|
||||
(cfg_getbool(cfg, "daemon"))
|
||||
#define SET_AGGREGATION_IP(IP) \
|
||||
(cfg_setstr(cfg, "aggregation_ip", (IP)))
|
||||
#define GET_AGGREGATION_IP() \
|
||||
|
@ -296,6 +300,10 @@ void print_version(void) ;
|
|||
|
||||
/* Home-made structure macros */
|
||||
#else // USE_CONFIG_FILE
|
||||
#define SET_DAEMON() \
|
||||
(options.daemon = owl_true)
|
||||
#define GET_DAEMON() \
|
||||
(options.daemon)
|
||||
#define SET_MODE(MODE) \
|
||||
(options.mode = (MODE))
|
||||
#define GET_MODE() \
|
||||
|
|
|
@ -60,6 +60,7 @@ cfg_t *cfg = NULL ; // Configuration structure
|
|||
* options.
|
||||
*/
|
||||
struct {
|
||||
owl_bool daemon ;
|
||||
char mode ;
|
||||
char aggregation_ip[INET_ADDRSTRLEN] ;
|
||||
uint_fast16_t aggregation_port ;
|
||||
|
@ -84,6 +85,7 @@ struct {
|
|||
#endif // USE_PTHREAD
|
||||
uint_fast8_t verbose ;
|
||||
} options = { // Initalise default options:
|
||||
owl_false,
|
||||
MODE_ACTIVE,
|
||||
"127.0.0.1",
|
||||
OWL_DEFAULT_LISTENER_PORT,
|
||||
|
@ -183,6 +185,14 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
#endif // USE_PTHREAD
|
||||
|
||||
if (GET_DAEMON())
|
||||
{
|
||||
if (VERBOSE_WARNING)
|
||||
fprintf(stderr, "Detaching to background...\n") ;
|
||||
if (daemon(0, 0))
|
||||
perror("Cannot daemonize") ;
|
||||
}
|
||||
|
||||
ret = capture() ; // Capture loop
|
||||
|
||||
/* Wait for the threads to terminate */
|
||||
|
@ -290,6 +300,8 @@ int parse_config_file(int argc, char **argv)
|
|||
// If we use libconfuse, we declare options:
|
||||
cfg_opt_t opts[] =
|
||||
{
|
||||
// Daemon mode:
|
||||
CFG_BOOL("daemon", cfg_false, CFGF_NONE),
|
||||
// Listening mode: a for active, p for passive, m for mixed
|
||||
// (default: a):
|
||||
CFG_INT("mode", MODE_ACTIVE, CFGF_NONE),
|
||||
|
@ -456,6 +468,9 @@ int parse_main_options(int argc, char **argv)
|
|||
SET_AUTOCALIBRATION_PORT(strtol(optarg, NULL, 0)) ;
|
||||
#endif // USE_PTHREAD
|
||||
break ;
|
||||
case 'D' :
|
||||
SET_DAEMON() ;
|
||||
break ;
|
||||
case 'f' : // Config file
|
||||
break ; // (already parsed)
|
||||
case 'H' :
|
||||
|
@ -1451,6 +1466,7 @@ void print_usage()
|
|||
printf("Usage :\n"
|
||||
"\t%s"
|
||||
" [-f config_file]"
|
||||
" [-D]"
|
||||
" [-m mode]"
|
||||
" [-i aggregation_ip]"
|
||||
" [-l listening_port]"
|
||||
|
@ -1476,6 +1492,12 @@ void print_usage()
|
|||
"\t-f config_file\tUse 'config_file' instead of the default"
|
||||
" configuration file (%s). Available only if program was"
|
||||
" compiled with libconfuse.\n"
|
||||
"\t-D\t\tDaemon mode.\n"
|
||||
"\t-v\t\tBe verbose. You can use this option up to 3 times to"
|
||||
" increase the level of verbosity (1 = warnings, 2 = useful"
|
||||
" information, 3 = a lot of information, 4 = display each"
|
||||
" captured packet).\n"
|
||||
"\t-q\t\tQuiet mode (default): sets the verbose level to 0.\n"
|
||||
|
||||
"Capture options:\n"
|
||||
"\t-m mode\t\t\tCapture mode: a(ctive), p(assive), m(ixed)"
|
||||
|
@ -1510,16 +1532,11 @@ void print_usage()
|
|||
"\tdirection x y z\t\tThe coordinates of the listener"
|
||||
" (direction is an integer; x, y, z are floats).\n"
|
||||
|
||||
"Other options:\n"
|
||||
"Miscelanneous options:\n"
|
||||
"\t-K\tKeep the monitor mode up on wifi_iface. Use it with buggy"
|
||||
" drivers that disable monitor mode periodically. Available"
|
||||
" only if the program was compiled with the option"
|
||||
" ENABLE_KEEP_MONITOR.\n"
|
||||
"\t-v\tBe verbose. You can use this option up to 3 times to"
|
||||
" increase the level of verbosity (1 = warnings, 2 = useful"
|
||||
" information, 3 = a lot of information, 4 = display each"
|
||||
" captured packet).\n"
|
||||
"\t-q\tQuiet mode (default): sets the verbose level to 0.\n"
|
||||
,
|
||||
program_name,
|
||||
program_name,
|
||||
|
|
Loading…
Reference in New Issue