bool gt::Platform::processIsUnique() { if(ld == -1) { gt::Log::Debug("The lock wasn't ready, retrying..."); if(!checkDirExist(getDefaultConfigPath())) makeDir(getDefaultConfigPath(), 0755); ld = open(string(getDefaultConfigPath() + "gtorrent.lock").c_str(), O_CREAT | O_RDWR, 0600); return processIsUnique(); } struct flock fl = { 0 }; fl.l_type = F_WRLCK; fl.l_whence = SEEK_SET; int state = fcntl(ld, F_SETLK, &fl); if(state == 0) gt::Log::Debug("Process is unique"); if(state) gt::Log::Debug("Process is not unique"); return state == 0; }
GameConfig::GameConfig(const std::string& configName, const std::string& configPath) : m_configName(configName) , m_configPath(configPath) , m_valid(false) , m_inputInvertY(false) { if (m_configPath.empty()) { m_configPath = getDefaultConfigPath(); } // Look up the path to use auto configFile = getConfigFile(); if (ini_parse(configFile.c_str(), handler, this) < 0) { m_valid = false; } else { m_valid = true; } }