diff --git a/node/Node.cpp b/node/Node.cpp index c88741a64..f2668e4e5 100644 --- a/node/Node.cpp +++ b/node/Node.cpp @@ -467,6 +467,7 @@ Node::ReasonForTermination Node::run() // Core I/O loop try { + std::string shutdownIfUnreadablePath(_r->homePath + ZT_PATH_SEPARATOR_S + "shutdownIfUnreadable"); uint64_t lastNetworkAutoconfCheck = Utils::now() - 5000; // check autoconf again after 5s for startup uint64_t lastPingCheck = 0; uint64_t lastClean = Utils::now(); // don't need to do this immediately @@ -476,6 +477,13 @@ Node::ReasonForTermination Node::run() long lastDelayDelta = 0; while (impl->reasonForTermination == NODE_RUNNING) { + if (Utils::fileExists(shutdownIfUnreadablePath.c_str(),false)) { + FILE *tmpf = fopen(shutdownIfUnreadablePath.c_str(),"r"); + if (!tmpf) + return impl->terminateBecause(Node::NODE_NORMAL_TERMINATION,"shutdownIfUnreadable was not readable"); + fclose(tmpf); + } + uint64_t now = Utils::now(); bool resynchronize = false; diff --git a/node/Utils.cpp b/node/Utils.cpp index 31cb40dd9..608de5937 100644 --- a/node/Utils.cpp +++ b/node/Utils.cpp @@ -246,7 +246,7 @@ no getSecureRandom() implementation; void Utils::lockDownFile(const char *path,bool isDir) { -#if defined(__APPLE__) || defined(__linux__) || defined(linux) || defined(__LINUX__) || defined(__linux) +#ifdef __UNIX_LIKE__ chmod(path,isDir ? 0700 : 0600); #else #ifdef _WIN32 @@ -263,6 +263,16 @@ uint64_t Utils::getLastModified(const char *path) return (((uint64_t)s.st_mtime) * 1000ULL); } +bool Utils::fileExists(const char *path,bool followLinks) +{ + struct stat s; +#ifdef __UNIX_LIKE__ + if (!followLinks) + return (lstat(path,&s) == 0); +#endif + return (stat(path,&s) == 0); +} + int64_t Utils::getFileSize(const char *path) { struct stat s; diff --git a/node/Utils.hpp b/node/Utils.hpp index 4e060748b..2fea8b9b0 100644 --- a/node/Utils.hpp +++ b/node/Utils.hpp @@ -177,12 +177,10 @@ public: /** * @param path Path to check + * @param followLinks Follow links (on platforms with that concept) * @return True if file or directory exists at path location */ - static inline bool fileExists(const char *path) - { - return (getLastModified(path) != 0); - } + static bool fileExists(const char *path,bool followLinks = true); /** * @param path Path to file