diff --git a/arangosh/ArangoShell/ArangoClient.cpp b/arangosh/ArangoShell/ArangoClient.cpp index 2da1ab25d5..96ba825144 100644 --- a/arangosh/ArangoShell/ArangoClient.cpp +++ b/arangosh/ArangoShell/ArangoClient.cpp @@ -291,19 +291,12 @@ void ArangoClient::parse (ProgramOptions& options, } -#ifdef _SYSCONFDIR_ else { - // use packaged config file from etc/relative - string sysDir = string(_SYSCONFDIR_); - string systemConfigFile = initFilename; + char* d = TRI_LocateConfigDirectory(); - if (! sysDir.empty()) { - if (sysDir[sysDir.size() - 1] != TRI_DIR_SEPARATOR_CHAR) { - sysDir += TRI_DIR_SEPARATOR_CHAR + systemConfigFile; - } - else { - sysDir += systemConfigFile; - } + if (d != 0) { + string sysDir = string(d) + initFilename; + TRI_FreeString(TRI_CORE_MEM_ZONE, d); if (FileUtils::exists(sysDir)) { configFile = sysDir; @@ -313,7 +306,6 @@ void ArangoClient::parse (ProgramOptions& options, } } } -#endif if (! configFile.empty()) { LOGGER_DEBUG("using init file '" << configFile << "'"); diff --git a/lib/ApplicationServer/ApplicationServer.cpp b/lib/ApplicationServer/ApplicationServer.cpp index 99073593b4..11b1dde333 100644 --- a/lib/ApplicationServer/ApplicationServer.cpp +++ b/lib/ApplicationServer/ApplicationServer.cpp @@ -45,6 +45,8 @@ #include "Basics/StringUtils.h" #include "Basics/delete_object.h" #include "BasicsC/conversions.h" +#include "BasicsC/files.h" +#include "BasicsC/tri-strings.h" #include "Logger/Logger.h" using namespace triagens::basics; @@ -124,7 +126,6 @@ ApplicationServer::ApplicationServer (std::string const& name, std::string const _configFile(), _userConfigFile(), _systemConfigFile(), - _systemConfigPath(), _uid(), _realUid(0), _effectiveUid(0), @@ -166,7 +167,6 @@ ApplicationServer::ApplicationServer (std::string const& name, std::string const _configFile(), _userConfigFile(), _systemConfigFile(), - _systemConfigPath(), _uid(), _realUid(0), _effectiveUid(0), @@ -225,20 +225,11 @@ void ApplicationServer::addFeature (ApplicationFeature* feature) { } //////////////////////////////////////////////////////////////////////////////// -/// @brief sets the name of the system config file with a path -//////////////////////////////////////////////////////////////////////////////// - -void ApplicationServer::setSystemConfigFile (std::string const& name, std::string const& path) { - _systemConfigFile = name; - _systemConfigPath = path; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief sets the name of the system config file without a path +/// @brief sets the name of the system config file //////////////////////////////////////////////////////////////////////////////// void ApplicationServer::setSystemConfigFile (std::string const& name) { - return setSystemConfigFile(name, ""); + _systemConfigFile = name; } //////////////////////////////////////////////////////////////////////////////// @@ -968,7 +959,7 @@ bool ApplicationServer::readConfigurationFile () { // A safer approach below // ......................................................................... - string homeDir = FileUtils::homeDirectory(); + string homeDir = FileUtils::homeDirectory(); // TODO homedirectory should either always or never end in "/" if (! homeDir.empty()) { if (homeDir[homeDir.size() - 1] != TRI_DIR_SEPARATOR_CHAR) { @@ -994,9 +985,7 @@ bool ApplicationServer::readConfigurationFile () { return ok; } else { - LOGGER_DEBUG("no user init file '" << homeDir << "' found"); - } } else { @@ -1005,56 +994,17 @@ bool ApplicationServer::readConfigurationFile () { } - if (_systemConfigPath.empty()) { - -#ifdef _SYSCONFDIR_ - - // try the configuration file in the system directory - if there is one + // try the configuration file in the system directory - if there is one + if (! _systemConfigFile.empty()) { // Please note that the system directory changes depending on // where the user installed the application server. - if (! _systemConfigFile.empty()) { - string sysDir = string(_SYSCONFDIR_); + char* d = TRI_LocateConfigDirectory(); - if (! sysDir.empty()) { - if (sysDir[sysDir.size() - 1] != TRI_DIR_SEPARATOR_CHAR) { - sysDir += TRI_DIR_SEPARATOR_CHAR + _systemConfigFile; - } - else { - sysDir += _systemConfigFile; - } - - // check and see if file exists - if (FileUtils::exists(sysDir)) { - LOGGER_INFO("using init file '" << sysDir << "'"); - - bool ok = _options.parse(_descriptionFile, sysDir); - - // Observe that this is treated as an error - the configuration file exists - // but for some reason can not be parsed. Best to report an error. - - if (! ok) { - LOGGER_ERROR("cannot parse config file '" << sysDir << "': " << _options.lastError()); - } - - return ok; - } - else { - LOGGER_INFO("no system init file '" << sysDir << "' found"); - } - } - else { - LOGGER_DEBUG("no system init file, not system directory is known"); - } - } - -#endif - - } - else { - if (! _systemConfigFile.empty()) { - string sysDir = _systemConfigPath + TRI_DIR_SEPARATOR_CHAR + _systemConfigFile; + if (d != 0) { + string sysDir = string(d) + _systemConfigFile; + TRI_FreeString(TRI_CORE_MEM_ZONE, d); // check and see if file exists if (FileUtils::exists(sysDir)) { @@ -1076,7 +1026,7 @@ bool ApplicationServer::readConfigurationFile () { } } else { - LOGGER_DEBUG("no system init file specified"); + LOGGER_DEBUG("no system init file, system directory is not known"); } } diff --git a/lib/ApplicationServer/ApplicationServer.h b/lib/ApplicationServer/ApplicationServer.h index 840b679378..a1ff259383 100644 --- a/lib/ApplicationServer/ApplicationServer.h +++ b/lib/ApplicationServer/ApplicationServer.h @@ -157,13 +157,7 @@ namespace triagens { void addFeature (ApplicationFeature*); //////////////////////////////////////////////////////////////////////////////// -/// @brief sets the name of the system config file with a path -//////////////////////////////////////////////////////////////////////////////// - - void setSystemConfigFile (const std::string& name, const std::string& path); - -//////////////////////////////////////////////////////////////////////////////// -/// @brief sets the name of the system config file without a path +/// @brief sets the name of the system config file //////////////////////////////////////////////////////////////////////////////// void setSystemConfigFile (const std::string& name); @@ -490,12 +484,6 @@ namespace triagens { std::string _systemConfigFile; -//////////////////////////////////////////////////////////////////////////////// -/// @brief system config path -//////////////////////////////////////////////////////////////////////////////// - - std::string _systemConfigPath; - //////////////////////////////////////////////////////////////////////////////// /// @brief the user id to use for the process /// diff --git a/lib/BasicsC/files.c b/lib/BasicsC/files.c old mode 100755 new mode 100644 index 521cfc5ce2..5977242ebb --- a/lib/BasicsC/files.c +++ b/lib/BasicsC/files.c @@ -1870,8 +1870,132 @@ void TRI_SetUserTempPath (char* path) { } } +//////////////////////////////////////////////////////////////////////////////// +/// @brief locate the installation directory +/// +/// Will always end in a directory separator. +//////////////////////////////////////////////////////////////////////////////// + +#if _WIN32 + +char* TRI_LocateInstallDirectory () { + DWORD dwType; + char szPath[1023]; + DWORD dwDataSize; + HKEY key; + + dwDataSize = sizeof(szPath); + memset(szPath, 0, dwDataSize); + + // open the key for reading + // TODO: the installer always uses the 32bit path (Wow6432) + long lResult = RegOpenKeyEx( + HKEY_LOCAL_MACHINE, + "SOFTWARE\\Wow6432Node\\triAGENS GmbH\\ArangoDB 1.4.4", // TODO + 0, + KEY_READ, + &key); + + if (lResult == ERROR_SUCCESS) { + + // read the version value + lResult = RegQueryValueEx(key, "", NULL, &dwType, (BYTE*)szPath, &dwDataSize); + + if (lResult == ERROR_SUCCESS) { + return TRI_DuplicateString(szPath); + } + + RegCloseKey(key); + } + + return NULL; +} + +#else + +char* TRI_LocateInstallDirectory () { + return NULL; +} + +#endif + +//////////////////////////////////////////////////////////////////////////////// +/// @brief locate the configuration directory +/// +/// Will always end in a directory separator. +//////////////////////////////////////////////////////////////////////////////// + +#if _WIN32 + +char* TRI_LocateConfigDirectory () { + DWORD dwType; + char szPath[1023]; + DWORD dwDataSize; + HKEY key; + + dwDataSize = sizeof(szPath); + memset(szPath, 0, dwDataSize); + + // open the key for reading + // TODO: the installer always uses the 32bit path (Wow6432) + long lResult = RegOpenKeyEx( + HKEY_LOCAL_MACHINE, + "SOFTWARE\\Wow6432Node\\triAGENS GmbH\\ArangoDB 1.4.4", // TODO + 0, + KEY_READ, + &key); + + if (lResult == ERROR_SUCCESS) { + + // read the version value + lResult = RegQueryValueEx(key, "", NULL, &dwType, (BYTE*)szPath, &dwDataSize); + + if (lResult == ERROR_SUCCESS) { + return TRI_Concatenate2File(szPath, "etc\\arangodb\\"); + } + + RegCloseKey(key); + } + + return NULL; +} + +#elif defined(_SYSCONFDIR_) + +char* TRI_LocateConfigDirectory () { + size_t len; + const char* dir = _SYSCONFDIR_; + + if (*dir == '\0') { + return NULL; + } + + len = strlen(dir); + + if (dir[len - 1] != TRI_DIR_SEPARATOR_CHAR) { + return TRI_Concatenate2String(dir, "/"); + } + else { + return TRI_DuplicateString(dir); + } +} + +#else + +char* TRI_LocateConfigDirectory () { + return NULL; +} + +#endif + +// ----------------------------------------------------------------------------- +// --SECTION-- module functions +// ----------------------------------------------------------------------------- + //////////////////////////////////////////////////////////////////////////////// /// @brief initialise the files subsystem +/// +/// TODO: inialise logging here? //////////////////////////////////////////////////////////////////////////////// void TRI_InitialiseFiles (void) { @@ -1881,6 +2005,8 @@ void TRI_InitialiseFiles (void) { //////////////////////////////////////////////////////////////////////////////// /// @brief shutdown the files subsystem +/// +/// TODO: inialise logging here? //////////////////////////////////////////////////////////////////////////////// void TRI_ShutdownFiles (void) { diff --git a/lib/BasicsC/files.h b/lib/BasicsC/files.h index 9f6a6646b9..82680143d4 100644 --- a/lib/BasicsC/files.h +++ b/lib/BasicsC/files.h @@ -289,6 +289,22 @@ char* TRI_GetUserTempPath (void); void TRI_SetUserTempPath (char*); +//////////////////////////////////////////////////////////////////////////////// +/// @brief locate the installation directory +//////////////////////////////////////////////////////////////////////////////// + +char* TRI_LocateInstallDirectory (); + +//////////////////////////////////////////////////////////////////////////////// +/// @brief locate the configuration directory +//////////////////////////////////////////////////////////////////////////////// + +char* TRI_LocateConfigDirectory (); + +// ----------------------------------------------------------------------------- +// --SECTION-- module functions +// ----------------------------------------------------------------------------- + //////////////////////////////////////////////////////////////////////////////// /// @brief initialise the files subsystem //////////////////////////////////////////////////////////////////////////////// diff --git a/lib/BasicsC/win-utils.c b/lib/BasicsC/win-utils.c index b1682d5d86..64c55154d9 100644 --- a/lib/BasicsC/win-utils.c +++ b/lib/BasicsC/win-utils.c @@ -33,17 +33,6 @@ #include #include -/* -#include -#include -#include -#include -#include -*/ - - - - // ............................................................................. // Some global variables which may be required throughout the lifetime of the // server @@ -317,40 +306,21 @@ int TRI_openFile (const char* filename, int openFlags) { int fileDescriptor; fileHandle = CreateFileA(filename, - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, - OPEN_EXISTING, - 0, - NULL); + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + 0, + NULL); + if (fileHandle == INVALID_HANDLE_VALUE) { return -1; } fileDescriptor = _open_osfhandle( (intptr_t)(fileHandle), O_RDWR| _O_BINARY); return fileDescriptor; - -/* -#define O_RDONLY _O_RDONLY -#define O_WRONLY _O_WRONLY -#define O_RDWR _O_RDWR -#define O_APPEND _O_APPEND -#define O_CREAT _O_CREAT -#define O_TRUNC _O_TRUNC -#define O_EXCL _O_EXCL -#define O_TEXT _O_TEXT -#define O_BINARY _O_BINARY -#define O_RAW _O_BINARY -#define O_TEMPORARY _O_TEMPORARY -#define O_NOINHERIT _O_NOINHERIT -#define O_SEQUENTIAL _O_SEQUENTIAL -#define O_RANDOM _O_RANDOM -//filename, O_CREAT | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR -*/ } - - //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// diff --git a/lib/BasicsC/win-utils.h b/lib/BasicsC/win-utils.h index 43d9575dcc..74cdc26fd7 100644 --- a/lib/BasicsC/win-utils.h +++ b/lib/BasicsC/win-utils.h @@ -30,23 +30,6 @@ #include -/* Constants rounded for 21 decimals. -#define M_E 2.71828182845904523536 -#define M_LOG2E 1.44269504088896340736 -#define M_LOG10E 0.434294481903251827651 -#define M_LN2 0.693147180559945309417 -#define M_LN10 2.30258509299404568402 -#define M_PI 3.14159265358979323846 -#define M_PI_2 1.57079632679489661923 -#define M_PI_4 0.785398163397448309616 -#define M_1_PI 0.318309886183790671538 -#define M_2_PI 0.636619772367581343076 -#define M_1_SQRTPI 0.564189583547756286948 -#define M_2_SQRTPI 1.12837916709551257390 -#define M_SQRT2 1.41421356237309504880 -#define M_SQRT_2 0.707106781186547524401 -*/ - #ifdef __cplusplus extern "C" { #endif diff --git a/lib/ProgramOptions/program-options.c b/lib/ProgramOptions/program-options.c index dae9a4092a..001d7388ba 100644 --- a/lib/ProgramOptions/program-options.c +++ b/lib/ProgramOptions/program-options.c @@ -178,8 +178,23 @@ static char * FillVariables (const char* value) { char* k = TRI_DuplicateString2(t, q - t); char* v = getenv(k); + if (v != NULL && *v == '\0') { + TRI_FreeString(TRI_CORE_MEM_ZONE, v); + v = NULL; + } + + if (v == NULL) { + if (TRI_EqualString(k, "ROOTDIR")) { + v = TRI_LocateInstallDirectory(); + } + } + else { + v = TRI_DuplicateString(v); + } + if (v != NULL) { TRI_AppendStringStringBuffer(&buffer, v); + TRI_FreeString(TRI_CORE_MEM_ZONE, v); } TRI_FreeString(TRI_CORE_MEM_ZONE, k);