From 71a12bb770c5d20483abbca3af277015cd75612e Mon Sep 17 00:00:00 2001 From: donghualin Date: Thu, 30 Jun 2022 16:02:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=88=A0=E9=99=A4=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E6=A0=8F=E5=90=AF=E5=8A=A8=E6=97=B6=E5=80=99=E7=94=A8ldd?= =?UTF-8?q?=E6=A3=80=E6=B5=8Blibdtk=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit v23版本无须检测,删除dtk库的检测,防止在启动的时候出现错误信息 Log: 优化任务栏启动 Influence: 任务栏启动的时候检测是否有ldd报错信息 Task: https://pms.uniontech.com/task-view-157235.html Change-Id: I51e229a46a46c8a745e5db59b4e1902fb74c15f2 --- frame/util/pluginloader.cpp | 108 +----------------------------------- frame/util/pluginloader.h | 4 -- 2 files changed, 1 insertion(+), 111 deletions(-) diff --git a/frame/util/pluginloader.cpp b/frame/util/pluginloader.cpp index 93533b5b3..35a6cd166 100644 --- a/frame/util/pluginloader.cpp +++ b/frame/util/pluginloader.cpp @@ -51,8 +51,6 @@ void PluginLoader::run() const QStringList disable_plugins_list = getDisablePluginList(); - const QString dtkCoreName = dtkCoreFileName(); - QStringList plugins; // 查找可用插件 @@ -72,117 +70,13 @@ void PluginLoader::run() qDebug() << "disable loading plugin:" << file; continue; } - // 判断当前进程加载的dtkcore库是否和当前库加载的dtkcore的库为同一个,如果不同,则无需加载, - // 否则在加载dtkcore的时候会报错(dtkcore内部判断如果加载两次会抛出错误) - QString libUsedDtkCore = libUsedDtkCoreFileName(pluginsDir.absoluteFilePath(file)); - if (!libUsedDtkCore.isEmpty() && libUsedDtkCore != dtkCoreName) - continue; plugins << file; } + for (auto plugin : plugins) { emit pluginFounded(pluginsDir.absoluteFilePath(plugin)); } emit finished(); } - -/** - * @brief 获取当前进程使用的dtkcore库的文件名 - * @return 当前进程使用的dtkCore库的文件名 - */ -QString PluginLoader::dtkCoreFileName() -{ - QFile f("/proc/self/maps"); - if (!f.open(QIODevice::ReadOnly)) - return QString(); - - const QByteArray &data = f.readAll(); - QTextStream ts(data); - while (Q_UNLIKELY(!ts.atEnd())) { - const QString line = ts.readLine(); - const QStringList &maps = line.split(' ', QString::SplitBehavior::SkipEmptyParts); - if (Q_UNLIKELY(maps.size() < 6)) - continue; - - QFileInfo info(maps.value(5)); - QString infoAbPath = info.absoluteFilePath(); - if (info.fileName().contains("dtkcore")) { - infoAbPath = realFileName(infoAbPath); - if (infoAbPath.contains("/")) { - int pathIndex = infoAbPath.lastIndexOf("/"); - infoAbPath = infoAbPath.mid(pathIndex + 1).trimmed(); - } - - f.close(); - return infoAbPath; - } - } - - f.close(); - return QString(); -} - -/** - * @brief 返回某个so库使用的dtkcore库文件名 - * @param 用于获取dtkcore库的so库文件名 - * @return 返回使用的dtkcore库文件名 - */ -QString PluginLoader::libUsedDtkCoreFileName(const QString &fileName) -{ - QString lddCommand = QString("ldd -r %1").arg(fileName); - FILE *fp = popen(lddCommand.toLocal8Bit().data(), "r"); - if (fp) { - char buf[2000] = {0}; - while (fgets(buf, sizeof(buf), fp)) { - QString rowResult = buf; - rowResult = rowResult.trimmed(); - if (rowResult.contains("dtkcore")) { - QStringList coreSplits = rowResult.split("=>"); - if (coreSplits.size() < 2) - continue; - - pclose(fp); - QString dtkCorePath = coreSplits[1]; - - // 删除后面的括号的内容 - int addrIndex = dtkCorePath.indexOf("(0x"); - dtkCorePath = realFileName(dtkCorePath.left(addrIndex).trimmed()); - if (dtkCorePath.contains("/")) { - int pathIndex = dtkCorePath.lastIndexOf("/"); - dtkCorePath = dtkCorePath.mid(pathIndex + 1).trimmed(); - } - - return dtkCorePath; - } - } - pclose(fp); - } - return QString(); -} - -/** - * @brief 返回软连接对应的实际的文件名 - * @param 当前软连接的文件名 - * @return 软连接对应的库的实际的文件名 - */ -QString PluginLoader::realFileName(QString fileName) -{ - QString command = QString("ls %1 -al").arg(fileName); - FILE *fp = popen(command.toLocal8Bit().data(), "r"); - if (fp) { - char buf[2000] = {0}; - if (fgets(buf, sizeof(buf), fp)) { - QString rowInfo = buf; - if (rowInfo.contains("->")) { - pclose(fp); - QStringList fileInfos = rowInfo.split("->"); - QString srcFileName = fileInfos[1]; - srcFileName = srcFileName.trimmed(); - return srcFileName; - } - } - pclose(fp); - } - return fileName; -} diff --git a/frame/util/pluginloader.h b/frame/util/pluginloader.h index 97031772d..00d6dc945 100644 --- a/frame/util/pluginloader.h +++ b/frame/util/pluginloader.h @@ -38,10 +38,6 @@ signals: protected: void run(); - QString dtkCoreFileName(); - QString libUsedDtkCoreFileName(const QString &fileName); - QString realFileName(QString fileName); // 获取软连接的真实文件的路径 - private: QString m_pluginDirPath; };