-
Notifications
You must be signed in to change notification settings - Fork 19
refactor: convert xsettings from executable to plugin #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| [D-BUS Service] | ||
| Name=org.deepin.dde.XSettings1 | ||
| Exec=/usr/bin/deepin-service-manager -n org.deepin.dde.XSettings1 | ||
| SystemdService=org.deepin.dde.XSettings1.service |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd. | ||
| // | ||
| // SPDX-License-Identifier: LGPL-3.0-or-later | ||
|
|
||
| #include "impl/xsettings1.h" | ||
|
|
||
| #include <QDBusConnection> | ||
| #include <QDBusConnectionInterface> | ||
|
|
||
| static XSettings1 *xSettings = nullptr; | ||
|
|
||
| extern "C" int DSMRegister(const char *name, void *data) | ||
| { | ||
|
|
||
| auto connection = reinterpret_cast<QDBusConnection *>(data); | ||
| if (connection->interface()->isServiceRegistered(name)) { | ||
| qWarning() << "DBus service already exists:" << name; | ||
| return 1; | ||
| } | ||
| xSettings = new XSettings1(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (bug_risk): Guard against multiple DSMRegister calls to avoid leaking/reusing the global instance. A second DSMRegister call would overwrite the global if (xSettings) {
qWarning() << "XSettings1 already instantiated";
return 1;
}before allocating to make the singleton’s lifecycle explicit and prevent misuse. |
||
|
|
||
| QDBusConnection::RegisterOptions opts = QDBusConnection::ExportAllSlots | QDBusConnection::ExportAllSignals | QDBusConnection::ExportAllProperties; | ||
| QString path = name; | ||
| path = QString("/%1").arg(path.replace(".", "/")); | ||
| connection->registerObject(path, xSettings, opts); | ||
| return 0; | ||
| } | ||
|
|
||
| // 该函数用于资源释放 | ||
| // 非常驻插件必须实现该函数,以防内存泄漏 | ||
| extern "C" int DSMUnRegister(const char *name, void *data) | ||
| { | ||
| Q_UNUSED(name); | ||
| Q_UNUSED(data); | ||
| if (xSettings) { | ||
| xSettings->deleteLater(); | ||
| xSettings = nullptr; | ||
| } | ||
| return 0; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): Defensive checks for
data/connectionbefore use would avoid undefined behavior.Here we
reinterpret_castand immediately callconnection->interface()without validatingdataor the interface pointer. IfDSMRegisteris ever invoked with a null or unexpecteddata, this will dereference a null pointer and crash. Please add guards, e.g.:Optionally log a warning so these failures are diagnosable.