From 696115ca276dced24e0ce97b8bfc43a852181f1b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= Date: Wed, 16 Oct 2013 16:17:32 +0200 Subject: [PATCH] Accept relative paths to dmlite configuration file. --- run.cpp | 6 ++++++ scan.cpp | 18 +++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/run.cpp b/run.cpp index 7df59e0..11a53a0 100644 --- a/run.cpp +++ b/run.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -28,6 +29,11 @@ int main(int argc, char *argv[]) { } if (argc >= 2) conf = argv[1]; + if (conf[0] != '/') { + char *cwd = get_current_dir_name(); + conf = std::string(cwd) + "/" + conf; + free(cwd); + } std::cout << "Config file: " << conf << std::endl; try { diff --git a/scan.cpp b/scan.cpp index 3551ce8..2ef9076 100644 --- a/scan.cpp +++ b/scan.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -88,7 +89,8 @@ int main(int argc, char *argv[]) { dmlite::Catalog* catalog = NULL; //dmlite::PoolManager* poolManager = NULL; dmlite::SecurityCredentials creds; - char *dmlite_config = NULL, *user = NULL, *address = NULL, *path, *target; + char *user = NULL, *address = NULL, *path, *target; + std::string dmlite_config; int opt; bool safetyCheck = true; @@ -100,8 +102,7 @@ int main(int argc, char *argv[]) { address = strdup(optarg); break; case 'c': - free(dmlite_config); - dmlite_config = strdup(optarg); + dmlite_config = optarg; break; case 'h': usage(argv[0]); @@ -123,9 +124,15 @@ int main(int argc, char *argv[]) { throw dmlite::DmException(); } + if (dmlite_config[0] != '/') { + char *cwd = get_current_dir_name(); + dmlite_config = std::string(cwd) + "/" + dmlite_config; + free(cwd); + } + // load configuration try { - manager.loadConfiguration(dmlite_config ? : DMLITE_CONFIG_DEFAULT); + manager.loadConfiguration(dmlite_config.empty() ? DMLITE_CONFIG_DEFAULT : dmlite_config); } catch (dmlite::DmException& e) { std::cout << "Could not load the configuration file." << std::endl << "Reason: " << e.what() << std::endl; @@ -178,20 +185,17 @@ int main(int argc, char *argv[]) { delete stack; } catch (dmlite::DmException& e) { free(address); - free(dmlite_config); free(user); delete stack; return 1; } catch (...) { free(address); - free(dmlite_config); free(user); delete stack; throw; } free(address); - free(dmlite_config); free(user); return 0; } -- 1.8.2.3