Skip to content
Open
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
23 changes: 4 additions & 19 deletions src/greeter/greeterproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@
#include <Messages.h>
#include <SocketWriter.h>
#include <security/pam_appl.h>
#include <pwd.h>

Check warning on line 36 in src/greeter/greeterproxy.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <pwd.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <DDBusSender>

Check warning on line 38 in src/greeter/greeterproxy.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DDBusSender> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <DThreadUtils>

#include <QCommandLineOption>

Check warning on line 40 in src/greeter/greeterproxy.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QCommandLineOption> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QCommandLineParser>

Check warning on line 41 in src/greeter/greeterproxy.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QCommandLineParser> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QGuiApplication>
#include <QLocalSocket>
#include <QVariantMap>
Expand Down Expand Up @@ -212,20 +211,6 @@
"SessionRemoved",
this,
SLOT(onSessionRemoved(QString, QDBusObjectPath)));

// Use async call to avoid blocking
QThreadPool::globalInstance()->start([this, conn]() {
OrgFreedesktopLogin1ManagerInterface manager(Logind::serviceName(),
Logind::managerPath(),
conn);
auto reply = manager.ListSessions();
reply.waitForFinished();
if (reply.isValid()) {
auto sessions = reply.value();
for (const auto &session : sessions)
onSessionNew(session.sessionId, session.sessionPath);
}
});
}

void GreeterProxy::login(const QString &user, const QString &password, const int sessionIndex)
Expand Down Expand Up @@ -306,12 +291,12 @@

void GreeterProxy::updateUserLoginState(const QDBusObjectPath &path, bool loggedIn)
{
QThreadPool ::globalInstance()->start([this, path, loggedIn] {
QThreadPool::globalInstance()->start([this, path, loggedIn] {
Copy link

Copilot AI Dec 31, 2025

Choose a reason for hiding this comment

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

Missing include for QThreadPool. The code uses QThreadPool::globalInstance() but does not include the necessary header. Add #include <QThreadPool> to the includes section to ensure proper compilation.

缺少 QThreadPool 的头文件包含。代码使用了 QThreadPool::globalInstance() 但没有包含必要的头文件。请在包含部分添加 #include <QThreadPool> 以确保正确编译。

Copilot uses AI. Check for mistakes.
OrgFreedesktopLogin1SessionInterface session(Logind::serviceName(),
path.path(),
QDBusConnection ::systemBus());
QString username = QString::fromLocal8Bit(getpwuid(session.user().userId)->pw_name);
DThreadUtils::gui().run(this, [this, username, loggedIn]() {
QDBusConnection::systemBus());
QString username = session.name();
Copy link

Copilot AI Dec 31, 2025

Choose a reason for hiding this comment

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

Missing error handling for DBus property access. The call to session.name() may fail or return an empty/invalid value if the DBus session object is invalid or the Name property cannot be retrieved. Consider checking if the returned username is valid before invoking the GUI update, or handle potential DBus errors to prevent unexpected behavior.

缺少对 DBus 属性访问的错误处理。如果 DBus 会话对象无效或无法检索 Name 属性,对 session.name() 的调用可能会失败或返回空/无效值。建议在调用 GUI 更新之前检查返回的用户名是否有效,或处理潜在的 DBus 错误以防止意外行为。

Suggested change
QString username = session.name();
if (!session.isValid()) {
qCWarning(treelandGreeter) << "Failed to create logind session interface for path"
<< path.path();
return;
}
const QString username = session.name();
if (username.isEmpty()) {
qCWarning(treelandGreeter) << "Received empty username from logind session for path"
<< path.path();
return;
}

Copilot uses AI. Check for mistakes.
QMetaObject::invokeMethod(this, [this, username, loggedIn]() {
userModel()->updateUserLoginState(username, loggedIn);
updateLocketState();
});
Expand Down