Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion REUSE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ SPDX-FileCopyrightText = "UnionTech Software Technology Co., Ltd."
SPDX-License-Identifier = "LGPL-3.0-or-later"

[[annotations]]
path = ["dbus/**.service", "systemd/**", "tools/**.service"]
path = ["dbus/**.service", "systemd/**", "tools/**.service", "tools/**.desktop"]
precedence = "aggregate"
SPDX-FileCopyrightText = "UnionTech Software Technology Co., Ltd."
SPDX-License-Identifier = "LGPL-3.0-or-later"
Expand Down
1 change: 1 addition & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Maintainer: Deepin Packages Builder <packages@deepin.com>
Build-Depends:
cmake,
debhelper-compat (= 11),
libcap-ng-dev,
libdtk6core-dev,
libdtk6core-bin,
libglib2.0-dev,
Expand Down
13 changes: 13 additions & 0 deletions debian/postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

case "$1" in
configure)
# Set CAP_SYS_RESOURCE capability on dde-oom-score-adj
# This allows it to adjust oom_score_adj for monitored services
if [ -x /usr/bin/dde-oom-score-adj ]; then
setcap cap_sys_resource=ep /usr/bin/dde-oom-score-adj || true
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The postinst script uses "|| true" which silently suppresses all errors from setcap, including permission errors, missing binary, or invalid capability names. This makes debugging difficult if the capability setting fails. Consider logging the failure or at minimum documenting why failures are acceptable. A better approach would be to check the return value and log a warning to help system administrators identify configuration issues.

Suggested change
setcap cap_sys_resource=ep /usr/bin/dde-oom-score-adj || true
if command -v setcap >/dev/null 2>&1; then
if ! setcap cap_sys_resource=ep /usr/bin/dde-oom-score-adj; then
echo "warning: failed to set CAP_SYS_RESOURCE on /usr/bin/dde-oom-score-adj" >&2
fi
else
echo "warning: setcap not found; cannot set CAP_SYS_RESOURCE on /usr/bin/dde-oom-score-adj" >&2
fi

Copilot uses AI. Check for mistakes.
fi
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The postinst script is missing the debhelper token "#DEBHELPER#" which is standard practice in Debian packaging. This token is replaced by debhelper with any generated maintainer script fragments from the package build. Without it, any auto-generated scripts from debhelper won't be included, potentially causing incomplete package configuration.

Suggested change
fi
fi
#DEBHELPER#

Copilot uses AI. Check for mistakes.
;;
esac

#DEBHELPER#
3 changes: 3 additions & 0 deletions misc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ install(

install(FILES ${XSESSION} DESTINATION /etc/X11/Xsession.d/)
install(FILES ${PROFILE} DESTINATION /etc/profile.d)

file(GLOB DCONFIG_FILES "misc/dconf/*.json")
dtk_add_config_meta_files(APPID org.deepin.dde.session BASE misc/dconf FILES ${DCONFIG_FILES})
16 changes: 16 additions & 0 deletions misc/dconf/org.deepin.dde.session.oom-score-adj.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"magic": "dsg.config.meta",
"version": "1.0",
"contents": {
"monitorServices": {
"value": ["dde-session-manager.service","dde-session@x11.service"],
"serial": 0,
"flags": ["global"],
"name": "monitorServices",
"name[zh_CN]": "OOM 分数调整监控服务列表",
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent Chinese translation style: The name field uses English "OOM" abbreviation without explanation in "OOM 分数调整监控服务列表", which may be unclear to Chinese users who are not familiar with the technical term. Consider providing the full Chinese translation or adding a brief explanation, such as "内存溢出(OOM)分数调整监控服务列表" for better clarity.

Suggested change
"name[zh_CN]": "OOM 分数调整监控服务列表",
"name[zh_CN]": "内存溢出(OOM)分数调整监控服务列表",

Copilot uses AI. Check for mistakes.
"description": "List of systemd services to monitor for OOM score adjustment",
"permissions": "readonly",
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The permissions field is set to "readonly" which means users cannot modify the monitored services list through DConfig. However, the PR description mentions "customizable service monitoring list", which implies this should be configurable. If the intent is to make this configurable by administrators or users, change permissions to "readwrite". If it should only be modifiable by the system, consider using "readwrite" with appropriate visibility settings or clarify in the description that it's readonly by design.

Suggested change
"permissions": "readonly",
"permissions": "readwrite",

Copilot uses AI. Check for mistakes.
"visibility": "private"
}
}
}
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
# SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: CC0-1.0

Expand Down
1 change: 1 addition & 0 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ add_subdirectory("dde-keyring-checker")
add_subdirectory("dde-version-checker")
add_subdirectory("dde-xsettings-checker")
add_subdirectory("dde-quick-login")
add_subdirectory("dde-oom-score-adj")
30 changes: 30 additions & 0 deletions tools/dde-oom-score-adj/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: CC0-1.0

set(BIN_NAME dde-oom-score-adj)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core DBus REQUIRED)
find_package(Dtk${DTK_VERSION_MAJOR} REQUIRED COMPONENTS Core)
find_package(PkgConfig REQUIRED)
pkg_check_modules(CAPNG REQUIRED IMPORTED_TARGET libcap-ng)

add_executable(${BIN_NAME}
main.cpp
oomscoreadjuster.h
oomscoreadjuster.cpp
)

target_link_libraries(${BIN_NAME}
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::DBus
Dtk${DTK_VERSION_MAJOR}::Core
PkgConfig::CAPNG
)

install(TARGETS ${BIN_NAME} DESTINATION bin)
install(FILES dde-oom-score-adj.desktop DESTINATION /etc/xdg/autostart/)
7 changes: 7 additions & 0 deletions tools/dde-oom-score-adj/dde-oom-score-adj.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[Desktop Entry]
Type=Application
Name=DDE OOM Score Adjuster
Comment=Adjust OOM score for critical DDE services
Exec=/usr/bin/dde-oom-score-adj
Terminal=false
NoDisplay=true
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The desktop file is missing the X-GNOME-Autostart-enabled field which is commonly used to control autostart behavior. Additionally, for proper XDG autostart specification compliance, consider adding OnlyShowIn or NotShowIn fields to ensure this only runs in appropriate desktop environments. Since this is DDE-specific, adding "OnlyShowIn=Deepin;" would be appropriate.

Suggested change
NoDisplay=true
NoDisplay=true
OnlyShowIn=Deepin;
X-GNOME-Autostart-enabled=true

Copilot uses AI. Check for mistakes.
32 changes: 32 additions & 0 deletions tools/dde-oom-score-adj/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "oomscoreadjuster.h"
#include <QCoreApplication>
#include <QDebug>
#include <cap-ng.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);

// 初始化 libcap-ng
capng_get_caps_process();

// 检查是否有 CAP_SYS_RESOURCE capability(仅用于调试信息)
if (!capng_have_capability(CAPNG_EFFECTIVE, CAP_SYS_RESOURCE)) {
qWarning() << "Warning: Missing CAP_SYS_RESOURCE capability!";
qWarning() << "The program may not be able to modify oom_score_adj.";
qWarning() << "When running as systemd service, capabilities are granted automatically.";
}
Comment on lines +18 to +23
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The capability check in main.cpp only logs a warning when CAP_SYS_RESOURCE is missing, but the program continues to run. This could lead to silent failures where the tool runs for 3 minutes but never successfully adjusts any OOM scores. Consider exiting immediately with a non-zero exit code if the capability is missing and this is not running as a systemd service, to provide faster feedback about the misconfiguration.

Copilot uses AI. Check for mistakes.

OomScoreAdjuster adjuster;

// 连接退出信号
QObject::connect(&adjuster, &OomScoreAdjuster::handleExit, &app, &QCoreApplication::quit);
QMetaObject::invokeMethod(&adjuster, "start", Qt::QueuedConnection);

return app.exec();
}
Loading