From 6fae5a758b32887dfd171f335eb936f16a1c2af9 Mon Sep 17 00:00:00 2001 From: ComixHe Date: Mon, 28 Aug 2023 11:11:50 +0800 Subject: [PATCH] fix: core dumped under Qt 6.4 1. call method metaObject of QMetaType will coredump under Qt 6.4 2. remove `std::terminate()` when AM can't connect to Systemd Signals. 3. call `Subscribe` before connecting to Systemd Signals to guarantee that systemd will send UnitNew and UnitRemoved. Signed-off-by: ComixHe --- apps/dde-application-manager/src/main.cpp | 1 + src/constant.h | 7 +++++++ src/dbus/applicationmanager1service.cpp | 6 ++---- src/dbus/applicationservice.cpp | 2 +- src/dbus/jobmanager1service.cpp | 3 +-- src/dbus/jobmanager1service.h | 2 +- src/global.h | 22 +++++++++++++++++----- src/systemdsignaldispatcher.h | 8 +++++++- 8 files changed, 37 insertions(+), 14 deletions(-) diff --git a/apps/dde-application-manager/src/main.cpp b/apps/dde-application-manager/src/main.cpp index a5c33e4..3082c4a 100644 --- a/apps/dde-application-manager/src/main.cpp +++ b/apps/dde-application-manager/src/main.cpp @@ -26,6 +26,7 @@ void registerComplexDbusType() qDBusRegisterMetaType>(); qRegisterMetaType(); qDBusRegisterMetaType(); + qDBusRegisterMetaType(); } } // namespace diff --git a/src/constant.h b/src/constant.h index b85e92e..71a8c71 100644 --- a/src/constant.h +++ b/src/constant.h @@ -35,4 +35,11 @@ constexpr auto ApplicationManagerDestDBusName = u8"deepin_application_manager_dest_bus"; #endif +constexpr auto ObjectManagerInterface = "org.desktopspec.DBus.ObjectManager"; +constexpr auto JobManagerInterface = "org.desktopspec.JobManager1"; +constexpr auto JobInterface = "org.desktopspec.JobManager1.Job"; +constexpr auto ApplicationManagerInterface = "org.desktopspec.ApplicationManager1"; +constexpr auto InstanceInterface = "org.desktopspec.ApplicationManager1.Instance"; +constexpr auto ApplicationInterface = "org.desktopspec.ApplicationManager1.Application"; + #endif diff --git a/src/dbus/applicationmanager1service.cpp b/src/dbus/applicationmanager1service.cpp index 57b6951..17001dc 100644 --- a/src/dbus/applicationmanager1service.cpp +++ b/src/dbus/applicationmanager1service.cpp @@ -28,8 +28,7 @@ ApplicationManager1Service::ApplicationManager1Service(std::unique_ptr()))) { + if (!registerObjectToDBus(this, DDEApplicationManager1ObjectPath, ApplicationManagerInterface)) { std::terminate(); } @@ -130,8 +129,7 @@ bool ApplicationManager1Service::addApplication(DesktopFile desktopFileSource) n return false; } - if (!registerObjectToDBus( - ptr, application->applicationPath().path(), getDBusInterface(QMetaType::fromType()))) { + if (!registerObjectToDBus(ptr, application->applicationPath().path(), ApplicationInterface)) { return false; } m_applicationList.insert(application->applicationPath(), application); diff --git a/src/dbus/applicationservice.cpp b/src/dbus/applicationservice.cpp index 252cf4a..a4a288a 100644 --- a/src/dbus/applicationservice.cpp +++ b/src/dbus/applicationservice.cpp @@ -317,7 +317,7 @@ bool ApplicationService::addOneInstance(const QString &instanceId, const QString auto *adaptor = new InstanceAdaptor(service); QString objectPath{m_applicationPath.path() + "/" + instanceId}; - if (registerObjectToDBus(service, objectPath, getDBusInterface(QMetaType::fromType()))) { + if (registerObjectToDBus(service, objectPath, InstanceInterface)) { m_Instances.insert(QDBusObjectPath{objectPath}, QSharedPointer{service}); service->moveToThread(this->thread()); adaptor->moveToThread(this->thread()); diff --git a/src/dbus/jobmanager1service.cpp b/src/dbus/jobmanager1service.cpp index 33a1533..62ba2a9 100644 --- a/src/dbus/jobmanager1service.cpp +++ b/src/dbus/jobmanager1service.cpp @@ -9,8 +9,7 @@ JobManager1Service::JobManager1Service(ApplicationManager1Service *parent) : m_parent(parent) { new JobManager1Adaptor{this}; - if (!registerObjectToDBus( - this, DDEApplicationManager1JobManagerObjectPath, getDBusInterface(QMetaType::fromType()))) { + if (!registerObjectToDBus(this, DDEApplicationManager1JobManagerObjectPath, JobManagerInterface)) { std::terminate(); } qRegisterMetaType(); diff --git a/src/dbus/jobmanager1service.h b/src/dbus/jobmanager1service.h index 47e004d..4d9dfe4 100644 --- a/src/dbus/jobmanager1service.h +++ b/src/dbus/jobmanager1service.h @@ -61,7 +61,7 @@ public: auto *ptr = job.data(); new JobAdaptor(ptr); - if (!registerObjectToDBus(ptr, objectPath, getDBusInterface(QMetaType::fromType()))) { + if (!registerObjectToDBus(ptr, objectPath, JobInterface)) { qCritical() << "can't register job to dbus."; future.cancel(); return {}; diff --git a/src/global.h b/src/global.h index 8ac1357..7a0007a 100644 --- a/src/global.h +++ b/src/global.h @@ -196,12 +196,24 @@ void unregisterObjectFromDBus(const QString &path); inline QString getDBusInterface(const QMetaType &meta) { - const auto *infoObject = meta.metaObject(); - if (auto infoIndex = infoObject->indexOfClassInfo("D-Bus Interface"); infoIndex != -1) { - return infoObject->classInfo(infoIndex).value(); + auto name = QString{meta.name()}; + if (name == "ApplicationAdaptor") { + return ApplicationInterface; } - qWarning() << "no interface found."; - return {}; + + if (name == "InstanceAdaptor") { + return InstanceInterface; + } + + if (name == "APPObjectManagerAdaptor" or name == "AMObjectManagerAdaptor") { + return ObjectManagerInterface; + } + // const auto *infoObject = meta.metaObject(); + // if (auto infoIndex = infoObject->indexOfClassInfo("D-Bus Interface"); infoIndex != -1) { + // return infoObject->classInfo(infoIndex).value(); + // } + qWarning() << "couldn't found interface:" << name; + return ""; } inline ObjectInterfaceMap getChildInterfacesAndPropertiesFromObject(QObject *o) diff --git a/src/systemdsignaldispatcher.h b/src/systemdsignaldispatcher.h index d1f950b..ee4da8a 100644 --- a/src/systemdsignaldispatcher.h +++ b/src/systemdsignaldispatcher.h @@ -6,6 +6,7 @@ #define SYSTEMDSIGNALDISPATCHER_H #include "global.h" +#include class SystemdSignalDispatcher : public QObject { @@ -29,8 +30,13 @@ private: explicit SystemdSignalDispatcher(QObject *parent = nullptr) : QObject(parent) { + auto &con = ApplicationManager1DBus::instance().globalDestBus(); + auto ret = con.call(QDBusMessage::createMethodCall(SystemdService, SystemdObjectPath, SystemdInterfaceName, "Subscribe")); + if (ret.type() == QDBusMessage::ErrorMessage) { + qFatal("%s", ret.errorMessage().toLocal8Bit().data()); + } if (!connectToSignals()) { - std::terminate(); + qCritical() << "couldn't connect to Systemd signals"; } } bool connectToSignals() noexcept;