Fix daemon modes (Aggregator, Listener, Client)
daemon() must be called prior to set up signal handlers and threads.
This commit is contained in:
parent
cfe58267e3
commit
a1bc3db310
|
@ -51,6 +51,14 @@ int main(int argc, char **argv)
|
||||||
if (! owl_run)
|
if (! owl_run)
|
||||||
goto exit ;
|
goto exit ;
|
||||||
|
|
||||||
|
if (cfg_getbool(cfg, "daemon"))
|
||||||
|
{
|
||||||
|
if (VERBOSE_WARNING)
|
||||||
|
fprintf(stderr, "Detaching to background...\n") ;
|
||||||
|
if (daemon(0, 0))
|
||||||
|
perror("Cannot daemonize") ;
|
||||||
|
}
|
||||||
|
|
||||||
/* Set up signal handlers */
|
/* Set up signal handlers */
|
||||||
action.sa_flags = 0 ;
|
action.sa_flags = 0 ;
|
||||||
sigemptyset(&action.sa_mask) ;
|
sigemptyset(&action.sa_mask) ;
|
||||||
|
@ -102,14 +110,6 @@ 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) ;
|
ret = read_loop(sockfd) ;
|
||||||
|
|
||||||
/* Wait for the threads to terminate */
|
/* Wait for the threads to terminate */
|
||||||
|
|
|
@ -100,6 +100,13 @@ int main(int argc, char *argv[])
|
||||||
program_name = argv[0] ;
|
program_name = argv[0] ;
|
||||||
parse_command_line(argc, argv) ;
|
parse_command_line(argc, argv) ;
|
||||||
|
|
||||||
|
if (options.daemon)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Detaching to background...\n") ;
|
||||||
|
if (daemon(0, 0))
|
||||||
|
perror("Cannot daemonize") ;
|
||||||
|
}
|
||||||
|
|
||||||
/* Set up signal handlers */
|
/* Set up signal handlers */
|
||||||
action.sa_flags = 0 ;
|
action.sa_flags = 0 ;
|
||||||
sigemptyset(&action.sa_mask) ;
|
sigemptyset(&action.sa_mask) ;
|
||||||
|
@ -108,13 +115,6 @@ 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() ;
|
||||||
|
|
|
@ -131,6 +131,14 @@ int main(int argc, char *argv[])
|
||||||
if (! owl_run)
|
if (! owl_run)
|
||||||
goto exit ;
|
goto exit ;
|
||||||
|
|
||||||
|
if (GET_DAEMON())
|
||||||
|
{
|
||||||
|
if (VERBOSE_WARNING)
|
||||||
|
fprintf(stderr, "Detaching to background...\n") ;
|
||||||
|
if (daemon(0, 0))
|
||||||
|
perror("Cannot daemonize") ;
|
||||||
|
}
|
||||||
|
|
||||||
/* Set up signal handlers */
|
/* Set up signal handlers */
|
||||||
action.sa_flags = 0 ;
|
action.sa_flags = 0 ;
|
||||||
sigemptyset(&action.sa_mask) ;
|
sigemptyset(&action.sa_mask) ;
|
||||||
|
@ -185,14 +193,6 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
#endif // USE_PTHREAD
|
#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
|
ret = capture() ; // Capture loop
|
||||||
|
|
||||||
/* Wait for the threads to terminate */
|
/* Wait for the threads to terminate */
|
||||||
|
|
Loading…
Reference in New Issue