[Listener] Improve config file-related warning
Display a warning when the configuration file cannot be read only when the -f option was used. As stated in comment, the initial plan was to also display the warning in verbose mode, but at this point of the program the command-line is not parsed yet, so it's pointless to test for it.
This commit is contained in:
parent
b930333fbb
commit
46e1510536
6
TODO.t2t
6
TODO.t2t
|
@ -121,12 +121,6 @@ Work to do in OwlPS
|
||||||
|
|
||||||
- Refactor and review read_packet().
|
- Refactor and review read_packet().
|
||||||
|
|
||||||
- Handle better the configuration file reading
|
|
||||||
|
|
||||||
Get rid of the "Cannot open configuration file" error, in quiet mode
|
|
||||||
and when the default configuration file has to be used (no file
|
|
||||||
specified by the user with -f).
|
|
||||||
|
|
||||||
- Filter the number of implicit packets per mobile?
|
- Filter the number of implicit packets per mobile?
|
||||||
|
|
||||||
Currently, in passive or mixed mode, //all// the received packets are
|
Currently, in passive or mixed mode, //all// the received packets are
|
||||||
|
|
|
@ -418,7 +418,11 @@ int parse_config_file(int argc, char **argv)
|
||||||
CFG_END()
|
CFG_END()
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
char *config_file = NULL ; // Configuration file name
|
// Configuration file name
|
||||||
|
char *config_file = NULL ;
|
||||||
|
// True if we are using the default configuration file, false if the
|
||||||
|
// user specified a different one with -f
|
||||||
|
bool default_config_file = false ;
|
||||||
#endif // OWLPS_LISTENER_USES_CONFIG_FILE
|
#endif // OWLPS_LISTENER_USES_CONFIG_FILE
|
||||||
|
|
||||||
// Option -f specifies a config file, options -h and -V exit the
|
// Option -f specifies a config file, options -h and -V exit the
|
||||||
|
@ -460,6 +464,7 @@ int parse_config_file(int argc, char **argv)
|
||||||
// If -f isn't found, we use the default config file
|
// If -f isn't found, we use the default config file
|
||||||
if (config_file == NULL)
|
if (config_file == NULL)
|
||||||
{
|
{
|
||||||
|
default_config_file = true ;
|
||||||
config_file =
|
config_file =
|
||||||
malloc((strlen(DEFAULT_CONFIG_FILE) + 1) * sizeof(char)) ;
|
malloc((strlen(DEFAULT_CONFIG_FILE) + 1) * sizeof(char)) ;
|
||||||
if (! config_file)
|
if (! config_file)
|
||||||
|
@ -476,9 +481,15 @@ int parse_config_file(int argc, char **argv)
|
||||||
switch (cfg_parse(cfg, config_file))
|
switch (cfg_parse(cfg, config_file))
|
||||||
{
|
{
|
||||||
case CFG_FILE_ERROR :
|
case CFG_FILE_ERROR :
|
||||||
fprintf(stderr,
|
/* If we can't open the file, we display a message only if
|
||||||
"Warning! Cannot open configuration file \"%s\": %s.\n",
|
* the user used -f. In verbose mode, it would be nice to
|
||||||
config_file, strerror(errno)) ;
|
* display the message even if the user didn't use -f, but
|
||||||
|
* the command-line options are not parsed yet so the verbose
|
||||||
|
* level is always zero. */
|
||||||
|
if (! default_config_file)
|
||||||
|
fprintf(stderr,
|
||||||
|
"Warning! Cannot open configuration file \"%s\": %s.\n",
|
||||||
|
config_file, strerror(errno)) ;
|
||||||
break ;
|
break ;
|
||||||
case CFG_PARSE_ERROR :
|
case CFG_PARSE_ERROR :
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
|
|
Loading…
Reference in New Issue