[Aggregator] Fix config parsing memory leaks
Same thing as for the Listener: avoid using exit(), prefer return an int value instead.
This commit is contained in:
parent
8f48a22482
commit
1a98cf44b2
|
@ -86,10 +86,10 @@ typedef struct _ap_list
|
||||||
|
|
||||||
|
|
||||||
/* Function headers */
|
/* Function headers */
|
||||||
void initialise_configuration(int argc, char **argv) ;
|
int initialise_configuration(int argc, char **argv) ;
|
||||||
void parse_config_file(int argc, char **argv) ;
|
int parse_config_file(int argc, char **argv) ;
|
||||||
void parse_command_line(int argc, char **argv) ;
|
int parse_command_line(int argc, char **argv) ;
|
||||||
void check_configuration(void) ;
|
int check_configuration(void) ;
|
||||||
|
|
||||||
int read_loop(int sockfd) ;
|
int read_loop(int sockfd) ;
|
||||||
void got_request(owl_captured_request request) ;
|
void got_request(owl_captured_request request) ;
|
||||||
|
|
|
@ -42,10 +42,14 @@ int main(int argc, char **argv)
|
||||||
monitor_aps_thread, // APs monitoring thread
|
monitor_aps_thread, // APs monitoring thread
|
||||||
autocalibration_hello_thread ; // Hello messages reception thread
|
autocalibration_hello_thread ; // Hello messages reception thread
|
||||||
uint_fast16_t listening_port ;
|
uint_fast16_t listening_port ;
|
||||||
int sockfd ; // UDP listening socket
|
int sockfd = -1 ; // UDP listening socket
|
||||||
|
|
||||||
|
owl_run = owl_true ;
|
||||||
|
|
||||||
program_name = argv[0] ;
|
program_name = argv[0] ;
|
||||||
initialise_configuration(argc, argv) ;
|
ret = initialise_configuration(argc, argv) ;
|
||||||
|
if (! owl_run)
|
||||||
|
goto exit ;
|
||||||
|
|
||||||
/* Set up signal handlers */
|
/* Set up signal handlers */
|
||||||
action.sa_flags = 0 ;
|
action.sa_flags = 0 ;
|
||||||
|
@ -98,7 +102,6 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
owl_run = owl_true ;
|
|
||||||
ret = read_loop(sockfd) ;
|
ret = read_loop(sockfd) ;
|
||||||
|
|
||||||
/* Wait for the threads to terminate */
|
/* Wait for the threads to terminate */
|
||||||
|
@ -140,7 +143,8 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
/* Last cleaning tasks */
|
/* Last cleaning tasks */
|
||||||
exit:
|
exit:
|
||||||
close(sockfd) ; // Close socket
|
if (sockfd >= 0)
|
||||||
|
close(sockfd) ; // Close socket
|
||||||
free_request_list() ;
|
free_request_list() ;
|
||||||
free_ap_list() ;
|
free_ap_list() ;
|
||||||
cfg_free(cfg) ; // Clean configuration
|
cfg_free(cfg) ; // Clean configuration
|
||||||
|
@ -154,11 +158,28 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void initialise_configuration(int argc, char **argv)
|
/*
|
||||||
|
* Read the configuration from both the command line and the
|
||||||
|
* configuration file.
|
||||||
|
* Returns an error code, or 0 in case of success. If the program should
|
||||||
|
* stop (because of a special option or a configuration error), owl_run
|
||||||
|
* is set to false.
|
||||||
|
*/
|
||||||
|
int initialise_configuration(int argc, char **argv)
|
||||||
{
|
{
|
||||||
parse_config_file(argc, argv) ;
|
int ret ;
|
||||||
parse_command_line(argc, argv) ;
|
|
||||||
check_configuration() ;
|
ret = parse_config_file(argc, argv) ;
|
||||||
|
if (! owl_run)
|
||||||
|
return ret ;
|
||||||
|
|
||||||
|
ret = parse_command_line(argc, argv) ;
|
||||||
|
if (! owl_run)
|
||||||
|
return ret ;
|
||||||
|
|
||||||
|
ret = check_configuration() ;
|
||||||
|
if (! owl_run)
|
||||||
|
return ret ;
|
||||||
|
|
||||||
/* Configuration printing */
|
/* Configuration printing */
|
||||||
if (VERBOSE_INFO)
|
if (VERBOSE_INFO)
|
||||||
|
@ -166,10 +187,12 @@ void initialise_configuration(int argc, char **argv)
|
||||||
fprintf(stderr, "Configuration:\n") ;
|
fprintf(stderr, "Configuration:\n") ;
|
||||||
cfg_print(cfg, stderr) ;
|
cfg_print(cfg, stderr) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void parse_config_file(int argc, char **argv)
|
int parse_config_file(int argc, char **argv)
|
||||||
{
|
{
|
||||||
// Config file options for confuse
|
// Config file options for confuse
|
||||||
cfg_opt_t opts[] =
|
cfg_opt_t opts[] =
|
||||||
|
@ -221,10 +244,12 @@ void parse_config_file(int argc, char **argv)
|
||||||
break ;
|
break ;
|
||||||
case 'h' :
|
case 'h' :
|
||||||
print_usage() ;
|
print_usage() ;
|
||||||
exit(0) ;
|
owl_run = owl_false ;
|
||||||
|
return EXIT_SUCCESS ;
|
||||||
case 'V' :
|
case 'V' :
|
||||||
print_version() ;
|
print_version() ;
|
||||||
exit(0) ;
|
owl_run = owl_false ;
|
||||||
|
return EXIT_SUCCESS ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,13 +275,16 @@ void parse_config_file(int argc, char **argv)
|
||||||
"Error! Parsing of configuration file « %s » failed!\n",
|
"Error! Parsing of configuration file « %s » failed!\n",
|
||||||
config_file) ;
|
config_file) ;
|
||||||
free(config_file) ;
|
free(config_file) ;
|
||||||
exit(ERR_PARSING_CONFIG_FILE) ;
|
owl_run = owl_false ;
|
||||||
|
return ERR_PARSING_CONFIG_FILE ;
|
||||||
}
|
}
|
||||||
free(config_file) ;
|
free(config_file) ;
|
||||||
|
|
||||||
|
return 0 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void parse_command_line(int argc, char **argv)
|
int parse_command_line(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int opt ;
|
int opt ;
|
||||||
|
|
||||||
|
@ -281,9 +309,6 @@ void parse_command_line(int argc, char **argv)
|
||||||
break ;
|
break ;
|
||||||
case 'f' : // Config file
|
case 'f' : // Config file
|
||||||
break ; // (already parsed)
|
break ; // (already parsed)
|
||||||
case 'h' :
|
|
||||||
print_usage() ;
|
|
||||||
exit(0) ;
|
|
||||||
case 'i' :
|
case 'i' :
|
||||||
cfg_setstr(cfg, "positioner_ip", optarg) ;
|
cfg_setstr(cfg, "positioner_ip", optarg) ;
|
||||||
break ;
|
break ;
|
||||||
|
@ -316,20 +341,24 @@ void parse_command_line(int argc, char **argv)
|
||||||
break ;
|
break ;
|
||||||
default :
|
default :
|
||||||
print_usage() ;
|
print_usage() ;
|
||||||
exit(ERR_BAD_USAGE) ;
|
owl_run = owl_false ;
|
||||||
|
return ERR_BAD_USAGE ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void check_configuration()
|
int check_configuration()
|
||||||
{
|
{
|
||||||
// output_file //
|
// output_file //
|
||||||
if (cfg_getstr(cfg, "output_file")[0] == '\0')
|
if (cfg_getstr(cfg, "output_file")[0] == '\0')
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error! You must specify an output file.\n") ;
|
fprintf(stderr, "Error! You must specify an output file.\n") ;
|
||||||
print_usage() ;
|
print_usage() ;
|
||||||
exit(ERR_BAD_USAGE) ;
|
owl_run = owl_false ;
|
||||||
|
return ERR_BAD_USAGE ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// listening_port //
|
// listening_port //
|
||||||
|
@ -358,7 +387,8 @@ void check_configuration()
|
||||||
fprintf(stderr, "Error! You must specify the IP address of the"
|
fprintf(stderr, "Error! You must specify the IP address of the"
|
||||||
" localisation server.\n") ;
|
" localisation server.\n") ;
|
||||||
print_usage() ;
|
print_usage() ;
|
||||||
exit(ERR_BAD_USAGE) ;
|
owl_run = owl_false ;
|
||||||
|
return ERR_BAD_USAGE ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// aggregate_timeout //
|
// aggregate_timeout //
|
||||||
|
@ -405,6 +435,8 @@ void check_configuration()
|
||||||
" failing back to the default value.\n") ;
|
" failing back to the default value.\n") ;
|
||||||
cfg_setint(cfg, "ap_check_interval", DEFAULT_AP_CHECK_INTERVAL) ;
|
cfg_setint(cfg, "ap_check_interval", DEFAULT_AP_CHECK_INTERVAL) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue