Improved plugin version logging for Unix #4866
This commit is contained in:
parent
3eb1bffb70
commit
fedad2b8a1
|
@ -73,32 +73,41 @@ ArchPluginUnix::load()
|
||||||
|
|
||||||
std::vector<String>::iterator it;
|
std::vector<String>::iterator it;
|
||||||
for (it = plugins.begin(); it != plugins.end(); ++it) {
|
for (it = plugins.begin(); it != plugins.end(); ++it) {
|
||||||
LOG((CLOG_DEBUG "loading plugin: %s", (*it).c_str()));
|
String filename = *it;
|
||||||
String path = String(getPluginsDir()).append("/").append(*it);
|
String path = synergy::string::sprintf(
|
||||||
void* library = dlopen(path.c_str(), RTLD_LAZY);
|
"%s/%s", pluginsDir.c_str(), filename.c_str());
|
||||||
|
String name = synergy::string::removeFileExt(filename.substr(3));
|
||||||
|
|
||||||
if (library == NULL) {
|
LOG((CLOG_DEBUG "loading plugin: %s", filename.c_str()));
|
||||||
LOG((CLOG_ERR "failed to load plugin '%s', error: %s", (*it).c_str(), dlerror()));
|
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;
|
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) {
|
String expectedVersion = getExpectedPluginVersion(name.c_str());
|
||||||
LOG((CLOG_DEBUG "loaded plugin: %s (%s)", (*it).c_str(), version));
|
String currentVersion = getCurrentVersion(name, handle);
|
||||||
m_pluginTable.insert(std::make_pair(filename, library));
|
|
||||||
}
|
if (currentVersion.empty() || (expectedVersion != currentVersion)) {
|
||||||
else {
|
LOG((CLOG_ERR
|
||||||
LOG((CLOG_ERR "plugin version doesn't match"));
|
"failed to load plugin '%s', "
|
||||||
LOG((CLOG_DEBUG "expected plugin version: %s actual plugin version: %s",
|
"expected version %s but was %s",
|
||||||
expectedVersion.c_str(), version));
|
filename.c_str(),
|
||||||
LOG((CLOG_ERR "skip plugin: %s", (*it).c_str()));
|
expectedVersion.c_str(),
|
||||||
dlclose(library);
|
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();
|
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
|
void
|
||||||
sendEvent(const char* eventName, void* data)
|
sendEvent(const char* eventName, void* data)
|
||||||
{
|
{
|
||||||
|
|
|
@ -43,6 +43,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
String getPluginsDir();
|
String getPluginsDir();
|
||||||
|
String getCurrentVersion(const String& name, void* handle);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PluginTable m_pluginTable;
|
PluginTable m_pluginTable;
|
||||||
|
|
Loading…
Reference in New Issue