Commit e0d2e93cfb3dd5980f71259faede4505a1eb4788
1 parent
04d68733
Default config file location
Showing
1 changed file
with
10 additions
and
3 deletions
mainapp.cpp
| @@ -211,7 +211,7 @@ void MainApp::doHelp(const char *arg) | @@ -211,7 +211,7 @@ void MainApp::doHelp(const char *arg) | ||
| 211 | printf("Usage: %s [options]\n", arg); | 211 | printf("Usage: %s [options]\n", arg); |
| 212 | puts(""); | 212 | puts(""); |
| 213 | puts(" -h, --help Print help"); | 213 | puts(" -h, --help Print help"); |
| 214 | - puts(" -c, --config-file <flashmq.conf> Configuration file."); | 214 | + puts(" -c, --config-file <flashmq.conf> Configuration file. Default '/etc/flashmq/flashmq.conf'."); |
| 215 | puts(" -t, --test-config Test configuration file."); | 215 | puts(" -t, --test-config Test configuration file."); |
| 216 | #ifndef NDEBUG | 216 | #ifndef NDEBUG |
| 217 | puts(" -z, --fuzz-file <inputdata.dat> For fuzzing, provides the bytes that would be sent by a client."); | 217 | puts(" -z, --fuzz-file <inputdata.dat> For fuzzing, provides the bytes that would be sent by a client."); |
| @@ -369,7 +369,14 @@ void MainApp::initMainApp(int argc, char *argv[]) | @@ -369,7 +369,14 @@ void MainApp::initMainApp(int argc, char *argv[]) | ||
| 369 | {nullptr, 0, nullptr, 0} | 369 | {nullptr, 0, nullptr, 0} |
| 370 | }; | 370 | }; |
| 371 | 371 | ||
| 372 | + const std::string defaultConfigFile = "/etc/flashmq/flashmq.conf"; | ||
| 372 | std::string configFile; | 373 | std::string configFile; |
| 374 | + | ||
| 375 | + if (access(defaultConfigFile.c_str(), R_OK) == 0) | ||
| 376 | + { | ||
| 377 | + configFile = defaultConfigFile; | ||
| 378 | + } | ||
| 379 | + | ||
| 373 | std::string fuzzFile; | 380 | std::string fuzzFile; |
| 374 | 381 | ||
| 375 | int option_index = 0; | 382 | int option_index = 0; |
| @@ -409,14 +416,14 @@ void MainApp::initMainApp(int argc, char *argv[]) | @@ -409,14 +416,14 @@ void MainApp::initMainApp(int argc, char *argv[]) | ||
| 409 | { | 416 | { |
| 410 | if (configFile.empty()) | 417 | if (configFile.empty()) |
| 411 | { | 418 | { |
| 412 | - std::cerr << "No config specified." << std::endl; | 419 | + std::cerr << "No config specified (with -c) and the default " << defaultConfigFile << " not found." << std::endl << std::endl; |
| 413 | MainApp::doHelp(argv[0]); | 420 | MainApp::doHelp(argv[0]); |
| 414 | exit(1); | 421 | exit(1); |
| 415 | } | 422 | } |
| 416 | 423 | ||
| 417 | ConfigFileParser c(configFile); | 424 | ConfigFileParser c(configFile); |
| 418 | c.loadFile(true); | 425 | c.loadFile(true); |
| 419 | - puts("Config OK"); | 426 | + printf("Config '%s' OK\n", configFile.c_str()); |
| 420 | exit(0); | 427 | exit(0); |
| 421 | } | 428 | } |
| 422 | catch (ConfigFileException &ex) | 429 | catch (ConfigFileException &ex) |