From 973d2be629e1b45abd82e72f11f3136ce2e7d071 Mon Sep 17 00:00:00 2001 From: Alexey Shilov Date: Wed, 5 Jan 2011 15:51:57 +0200 Subject: [PATCH] Changes: load plugins without qt stuff. Details: libapplauncherd.so still needs to be linked to QtCore, mainly because of the booster being QObject. RevBy: Jussi Lind, Antti Kervinen --- src/launcherlib/daemon.cpp | 60 ++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/src/launcherlib/daemon.cpp b/src/launcherlib/daemon.cpp index 8bd5708..4b7788a 100644 --- a/src/launcherlib/daemon.cpp +++ b/src/launcherlib/daemon.cpp @@ -36,9 +36,7 @@ #include #include #include - -#include -#include +#include Daemon * Daemon::m_instance = NULL; int Daemon::m_lockFd = -1; @@ -274,38 +272,50 @@ void Daemon::loadSingleInstancePlugin() void Daemon::loadBoosterPlugins() { - QString strPluginDir(BOOSTER_PLUGIN_DIR); - QDir pluginDir(strPluginDir); - - QStringList filters; - filters << "lib*booster.so"; - pluginDir.setNameFilters(filters); + const char* PATTERN = "lib*booster.so"; + const int BUF_LEN = 256; - // Loop through entries in the plugin dir - QStringListIterator entry(pluginDir.entryList()); - while (entry.hasNext()) + if (strlen(PATTERN) + strlen(BOOSTER_PLUGIN_DIR) + 2 > BUF_LEN) { - QString file = entry.next(); - QString path = strPluginDir + QDir::separator() + file; + Logger::logError("Daemon: path to plugins too long"); + return; + } - const char * constPath = path.toAscii().constData(); - void * handle = dlopen(constPath, RTLD_NOW | RTLD_GLOBAL); - if (!handle) - { - Logger::logWarning("Daemon: dlopening booster failed: %s", dlerror()); - } - else + char buffer[BUF_LEN]; + memset(buffer, 0, BUF_LEN); + strcpy(buffer, BOOSTER_PLUGIN_DIR); + strcat(buffer, "/"); + strcat(buffer, PATTERN); + + // get full path to all plugins + glob_t globbuf; + if (glob(buffer, 0, NULL, &globbuf) == 0) + { + for (__size_t i = 0; i < globbuf.gl_pathc; i++) { - char newType = BoosterPluginRegistry::validateAndRegisterPlugin(handle); - if (newType) + void *handle = dlopen(globbuf.gl_pathv[i], RTLD_NOW | RTLD_GLOBAL); + if (!handle) { - Logger::logInfo("Daemon: Booster of type '%c' loaded.'", newType); + Logger::logWarning("Daemon: dlopening booster failed: %s", dlerror()); } else { - Logger::logWarning("Daemon: Invalid booster plugin: '%s'", constPath); + char newType = BoosterPluginRegistry::validateAndRegisterPlugin(handle); + if (newType) + { + Logger::logInfo("Daemon: Booster of type '%c' loaded.'", newType); + } + else + { + Logger::logWarning("Daemon: Invalid booster plugin: '%s'", buffer); + } } } + globfree(&globbuf); + } + else + { + Logger::logError("Daemon: can't find booster plugins"); } }