Skip to content

Commit

Permalink
Improved plugin version logging for Unix deskflow#4866
Browse files Browse the repository at this point in the history
  • Loading branch information
Xinyu Hou committed Aug 3, 2015
1 parent 3eb1bff commit fedad2b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 21 deletions.
60 changes: 40 additions & 20 deletions src/lib/arch/unix/ArchPluginUnix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down Expand Up @@ -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)
{
Expand Down
3 changes: 2 additions & 1 deletion src/lib/arch/unix/ArchPluginUnix.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ class ArchPluginUnix : public IArchPlugin {
void** args,
void* library = NULL);

private:
private:
String getPluginsDir();
String getCurrentVersion(const String& name, void* handle);

private:
PluginTable m_pluginTable;
Expand Down

0 comments on commit fedad2b

Please sign in to comment.