diff options
author | Joseph Henry <josephjah@gmail.com> | 2018-09-10 16:25:39 -0700 |
---|---|---|
committer | Joseph Henry <josephjah@gmail.com> | 2018-09-10 16:25:39 -0700 |
commit | 3dd9b1aa9be18b127e86db65900fe3af00d60d04 (patch) | |
tree | 752e38eba945846c53b59a92687c41fb489a0597 | |
parent | 0fddebc7913bffc2b3fd98ae3076e60c0d429396 (diff) | |
download | infinitytier-3dd9b1aa9be18b127e86db65900fe3af00d60d04.tar.gz infinitytier-3dd9b1aa9be18b127e86db65900fe3af00d60d04.zip |
Added ability to specify zt home directory via ZEROTIER_HOME - Addresses ticket #829
-rw-r--r-- | osdep/OSUtils.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/osdep/OSUtils.cpp b/osdep/OSUtils.cpp index 8b7fd948..e6c2f940 100644 --- a/osdep/OSUtils.cpp +++ b/osdep/OSUtils.cpp @@ -29,6 +29,7 @@ #include <stdlib.h> #include <stdarg.h> #include <sys/stat.h> +#include <stdlib.h> #include "../node/Constants.hpp" #include "../node/Utils.hpp" @@ -398,6 +399,21 @@ std::string OSUtils::platformDefaultHomePath() return homeDir; #endif + // Check for user-defined environment variable before using defaults +#ifdef __WINDOWS__ + DWORD bufferSize = 65535; + std::string userDefinedPath; + bufferSize = GetEnvironmentVariable("ZEROTIER_HOME", &userDefinedPath[0], bufferSize); + if (bufferSize) { + return userDefinedPath; + } +#else + if(const char* userDefinedPath = getenv("ZEROTIER_HOME")) { + return std::string(userDefinedPath); + } +#endif + + // Finally, resort to using default paths if no user-defined path was provided #ifdef __UNIX_LIKE__ #ifdef __APPLE__ |