Abort with a clear error message for invalid uses of --config inside a config file
The options.cxx code is not ready to handle recursive use of --config (for config files). Instead of failing in an ugly way, abort with a clear error message in such situations. See discussion at <https://sourceforge.net/p/flightgear/mailman/message/35838852/>. Note: it *is* possible to load XML PropertyList files from config files, so --config is not entirely "banned" from config files. + add missing include
This commit is contained in:
parent
6ef8b5bf94
commit
034fb89db3
2 changed files with 17 additions and 6 deletions
|
@ -39,6 +39,7 @@
|
|||
#include <cstdlib> // atof(), atoi()
|
||||
#include <cstring> // strcmp()
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
@ -2020,7 +2021,7 @@ void Options::init(int argc, char **argv, const SGPath& appDataPath)
|
|||
continue;
|
||||
}
|
||||
|
||||
int result = parseOption(argv[i]);
|
||||
int result = parseOption(argv[i], /* fromConfigFile */ false);
|
||||
processArgResult(result);
|
||||
} else {
|
||||
// XML properties file
|
||||
|
@ -2231,7 +2232,7 @@ void Options::readConfig(const SGPath& path)
|
|||
break;
|
||||
line = line.substr( 0, i );
|
||||
|
||||
if ( parseOption( line ) == FG_OPTIONS_ERROR ) {
|
||||
if ( parseOption(line, /* fromConfigFile */ true) == FG_OPTIONS_ERROR ) {
|
||||
cerr << endl << "Config file parse error: " << path << " '"
|
||||
<< line << "'" << endl;
|
||||
p->showHelp = true;
|
||||
|
@ -2242,7 +2243,7 @@ void Options::readConfig(const SGPath& path)
|
|||
p->insertGroupMarker(); // each config file is a group
|
||||
}
|
||||
|
||||
int Options::parseOption(const string& s)
|
||||
int Options::parseOption(const string& s, bool fromConfigFile)
|
||||
{
|
||||
if ((s == "--help") || (s=="-h")) {
|
||||
return FG_OPTIONS_HELP;
|
||||
|
@ -2276,7 +2277,15 @@ int Options::parseOption(const string& s)
|
|||
SGPath path = s.substr(9);
|
||||
if (path.extension() == "xml") {
|
||||
p->propertyFiles.push_back(path);
|
||||
} else {
|
||||
} else if (fromConfigFile) {
|
||||
flightgear::fatalMessageBoxThenExit(
|
||||
"FlightGear",
|
||||
"Invalid use of the --config option.",
|
||||
"Sorry, it is currently not supported to load a configuration file "
|
||||
"using --config from another configuration file.\n\n"
|
||||
"Note: this does not apply to loading of XML PropertyList files "
|
||||
"with --config.");
|
||||
} else { // the --config option comes from the command line
|
||||
p->configFiles.push_back(path);
|
||||
}
|
||||
|
||||
|
|
|
@ -171,8 +171,10 @@ private:
|
|||
// paths, etc. to stdout in JSON format, using the UTF-8 encoding.
|
||||
void printJSONReport() const;
|
||||
|
||||
int parseOption(const std::string& s);
|
||||
|
||||
// The 'fromConfigFile' parameter indicates whether the option comes from a
|
||||
// config file or directly from the command line.
|
||||
int parseOption(const std::string& s, bool fromConfigFile);
|
||||
|
||||
void processArgResult(int result);
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue