[Client] Daemon mode (-D)
This commit is contained in:
parent
a4857e4b1f
commit
327f8ae199
|
@ -27,7 +27,7 @@
|
||||||
#define DEFAULT_FLOOD_DELAY 1000
|
#define DEFAULT_FLOOD_DELAY 1000
|
||||||
|
|
||||||
/* Program arguments (getopt string) */
|
/* Program arguments (getopt string) */
|
||||||
#define OPTIONS "F::hi:I:l::n:p:t:V"
|
#define OPTIONS "DF::hi:I:l::n:p:t:V"
|
||||||
|
|
||||||
|
|
||||||
/* Function headers */
|
/* Function headers */
|
||||||
|
@ -49,6 +49,7 @@ void print_version(void) ;
|
||||||
|
|
||||||
/* Options */
|
/* Options */
|
||||||
struct {
|
struct {
|
||||||
|
owl_bool daemon ;
|
||||||
char dest_ip[INET_ADDRSTRLEN] ; // Destination IP of the packets
|
char dest_ip[INET_ADDRSTRLEN] ; // Destination IP of the packets
|
||||||
uint_fast16_t dest_port ;
|
uint_fast16_t dest_port ;
|
||||||
char iface[IFNAMSIZ + 1] ; // Source network interface
|
char iface[IFNAMSIZ + 1] ; // Source network interface
|
||||||
|
@ -62,6 +63,7 @@ struct {
|
||||||
float y ;
|
float y ;
|
||||||
float z ;
|
float z ;
|
||||||
} options = {
|
} options = {
|
||||||
|
owl_false,
|
||||||
"",
|
"",
|
||||||
OWL_DEFAULT_REQUEST_PORT,
|
OWL_DEFAULT_REQUEST_PORT,
|
||||||
"",
|
"",
|
||||||
|
@ -101,6 +103,13 @@ int main(int argc, char *argv[])
|
||||||
action.sa_handler = owl_sigterm_handler ;
|
action.sa_handler = owl_sigterm_handler ;
|
||||||
sigaction(SIGTERM, &action, NULL) ;
|
sigaction(SIGTERM, &action, NULL) ;
|
||||||
|
|
||||||
|
if (options.daemon)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Detaching to background...\n") ;
|
||||||
|
if (daemon(0, 0))
|
||||||
|
perror("Cannot daemonize") ;
|
||||||
|
}
|
||||||
|
|
||||||
create_socket() ;
|
create_socket() ;
|
||||||
|
|
||||||
send_request() ;
|
send_request() ;
|
||||||
|
@ -143,6 +152,9 @@ void parse_main_options(int argc, char **argv)
|
||||||
{
|
{
|
||||||
switch (opt)
|
switch (opt)
|
||||||
{
|
{
|
||||||
|
case 'D' :
|
||||||
|
options.daemon = owl_true ;
|
||||||
|
break ;
|
||||||
case 'F' :
|
case 'F' :
|
||||||
/* Facultative getopt options do not handle separated values
|
/* Facultative getopt options do not handle separated values
|
||||||
* (like -F <delay>), so we have to test separately.
|
* (like -F <delay>), so we have to test separately.
|
||||||
|
@ -320,16 +332,29 @@ void check_configuration()
|
||||||
options.listening_port = 0 ;
|
options.listening_port = 0 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.flood_delay >= 0)
|
||||||
|
{
|
||||||
// We want to flood AND to be located, which is not allowed:
|
// We want to flood AND to be located, which is not allowed:
|
||||||
if (options.flood_delay >= 0 && options.listening_port > 0)
|
if (options.listening_port > 0)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf(stderr, "Warning! You cannot wait for a server answer when"
|
fprintf(stderr, "Warning! You cannot wait for a server answer"
|
||||||
" you flood. Option -l ignored…\n") ;
|
" when you flood. Option -l ignored…\n") ;
|
||||||
#endif // DEBUG
|
#endif // DEBUG
|
||||||
options.listening_port = 0 ;
|
options.listening_port = 0 ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else // Flood is unactivated
|
||||||
|
if (options.daemon)
|
||||||
|
{
|
||||||
|
#ifdef DEBUG
|
||||||
|
fprintf(stderr, "Warning! It is useless to detach from"
|
||||||
|
" the foreground if the flood mode is not activated"
|
||||||
|
" Option -D ignored…\n") ;
|
||||||
|
#endif // DEBUG
|
||||||
|
options.daemon = owl_false ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -491,7 +516,7 @@ void print_usage()
|
||||||
" [-I iface]"
|
" [-I iface]"
|
||||||
" [-t delay]"
|
" [-t delay]"
|
||||||
" [-n nb_packets]"
|
" [-n nb_packets]"
|
||||||
" [-F [delay]]"
|
" [-F [delay] [-D]]"
|
||||||
" [-l [port]]\n"
|
" [-l [port]]\n"
|
||||||
"Calibration request:\n"
|
"Calibration request:\n"
|
||||||
"\t%s"
|
"\t%s"
|
||||||
|
@ -500,6 +525,7 @@ void print_usage()
|
||||||
" [-I iface]"
|
" [-I iface]"
|
||||||
" [-t delay]"
|
" [-t delay]"
|
||||||
" [-n nb_packets]"
|
" [-n nb_packets]"
|
||||||
|
" [-F [delay] [-D]]"
|
||||||
" direction x y z\n"
|
" direction x y z\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Options:\n"
|
"Options:\n"
|
||||||
|
@ -521,6 +547,7 @@ void print_usage()
|
||||||
" option.\n"
|
" option.\n"
|
||||||
"\t-F [delay]\t\"Flood mode\": loop undefinitely, sending a"
|
"\t-F [delay]\t\"Flood mode\": loop undefinitely, sending a"
|
||||||
" new request every <delay> milliseconds (default: %d ms).\n"
|
" new request every <delay> milliseconds (default: %d ms).\n"
|
||||||
|
"\t-D\t\tDaemon mode. Useful only in flood mode.\n"
|
||||||
"\t-l [port]\tWait for the computed position and display it."
|
"\t-l [port]\tWait for the computed position and display it."
|
||||||
" The Optional argument <port> allows to specify the listening"
|
" The Optional argument <port> allows to specify the listening"
|
||||||
" port (default: %d).\n"
|
" port (default: %d).\n"
|
||||||
|
|
Loading…
Reference in New Issue