Improved plugin version logging for Unix #4866

This commit is contained in:
Xinyu Hou 2015-07-24 20:44:48 +01:00 committed by Jerry (Xinyu Hou)
parent 3eb1bffb70
commit fedad2b8a1
2 changed files with 42 additions and 21 deletions

View File

@ -73,32 +73,41 @@ ArchPluginUnix::load()
std::vector<String>::iterator it;
for (it = plugins.begin(); it != plugins.end(); ++it) {
LOG((CLOG_DEBUG "loading plugin: %s", (*it).c_str()));
String path = String(getPluginsDir()).append("/").append(*it);
void* library = dlopen(path.c_str(), RTLD_LAZY);
String filename = *it;
String path = synergy::string::sprintf(
"%s/%s", pluginsDir.c_str(), filename.c_str());
String name = synergy::string::removeFileExt(filename.substr(3));
if (library == NULL) {
LOG((CLOG_ERR "failed to load plugin '%s', error: %s", (*it).c_str(), dlerror()));
LOG((CLOG_DEBUG "loading plugin: %s", filename.c_str()));
void* handle = dlopen(path.c_str(), RTLD_LAZY);
if (handle == NULL) {
LOG((CLOG_ERR "failed to load plugin '%s', error: %s",
filename.c_str(), dlerror()));
continue;
}
String filename = synergy::string::removeFileExt(*it);
size_t pos = filename.find("lib");
String pluginName = filename.substr(pos + 3);
char* version = (char*)invoke(filename.c_str(), "version", NULL, library);
String expectedVersion(pluginVersion(pluginName.c_str()));
if (version != NULL && expectedVersion.compare(version) == 0) {
LOG((CLOG_DEBUG "loaded plugin: %s (%s)", (*it).c_str(), version));
m_pluginTable.insert(std::make_pair(filename, library));
}
else {
LOG((CLOG_ERR "plugin version doesn't match"));
LOG((CLOG_DEBUG "expected plugin version: %s actual plugin version: %s",
expectedVersion.c_str(), version));
LOG((CLOG_ERR "skip plugin: %s", (*it).c_str()));
dlclose(library);
String expectedVersion = getExpectedPluginVersion(name.c_str());
String currentVersion = getCurrentVersion(name, handle);
if (currentVersion.empty() || (expectedVersion != currentVersion)) {
LOG((CLOG_ERR
"failed to load plugin '%s', "
"expected version %s but was %s",
filename.c_str(),
expectedVersion.c_str(),
currentVersion.empty() ? "unknown" : currentVersion.c_str()));
dlclose(handle);
continue;
}
LOG((CLOG_DEBUG "plugin loaded: %s (version %s)",
filename.c_str(),
currentVersion.c_str()));
m_pluginTable.insert(std::make_pair(name, handle));
}
}
@ -204,6 +213,17 @@ ArchPluginUnix::getPluginsDir()
return ARCH->getPluginDirectory();
}
String
ArchPluginUnix::getCurrentVersion(const String& name, void* handle)
{
char* version = (char*)invoke(name.c_str(), "version", NULL, handle);
if (version == NULL) {
return "";
}
return version;
}
void
sendEvent(const char* eventName, void* data)
{

View File

@ -41,8 +41,9 @@ public:
void** args,
void* library = NULL);
private:
private:
String getPluginsDir();
String getCurrentVersion(const String& name, void* handle);
private:
PluginTable m_pluginTable;