Skip to content

Commit 6d92b77

Browse files
committed
feat: Use string for logind session id instead of int
Although the logind session id is exactly an integer in current systemd-logind, but this is an UB according to systemd documentation. Systemd advertise us to treat it as a string and we shall adapt it.
1 parent 95a4c91 commit 6d92b77

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

src/greeter/usermodel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class UserModel : public QAbstractListModel
8585
void currentUserNameChanged();
8686
void updateTranslations(const QLocale &locale);
8787
void countChanged();
88-
void userLoggedIn(const QString &username, int sessionId);
88+
void userLoggedIn(const QString &username, const QString &session);
8989

9090
private Q_SLOTS:
9191
void onUserAdded(quint64 uid);

src/session/session.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Session::~Session()
6161
}
6262
}
6363

64-
int Session::id() const
64+
QString Session::id() const
6565
{
6666
return m_id;
6767
}
@@ -187,7 +187,7 @@ void SessionManager::removeSession(std::shared_ptr<Session> session)
187187
* @param username Username to ensure session for
188188
* @returns Session for the given username, or nullptr on failure
189189
*/
190-
std::shared_ptr<Session> SessionManager::ensureSession(int id, QString username)
190+
std::shared_ptr<Session> SessionManager::ensureSession(QString id, QString username)
191191
{
192192
// Helper lambda to create WSocket and WXWayland
193193
auto createWSocket = [this]() {
@@ -314,7 +314,7 @@ std::shared_ptr<Session> SessionManager::ensureSession(int id, QString username)
314314
* @param id Session ID to find session for
315315
* @returns Session for the given id, or nullptr if not found
316316
*/
317-
std::shared_ptr<Session> SessionManager::sessionForId(int id) const
317+
std::shared_ptr<Session> SessionManager::sessionForId(const QString &id) const
318318
{
319319
for (auto session : m_sessions) {
320320
if (session && session->m_id == id)
@@ -389,8 +389,9 @@ std::shared_ptr<Session> SessionManager::sessionForSocket(WSocket *socket) const
389389
* active session changed.
390390
*
391391
* @param username Username to set as active session
392+
* @param session Logind session ID to set as active session
392393
*/
393-
void SessionManager::updateActiveUserSession(const QString &username, int id)
394+
void SessionManager::updateActiveUserSession(const QString &username, const QString &id)
394395
{
395396
// Get previous active session
396397
auto previous = m_activeSession.lock();

src/session/session.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Session : public QObject {
2121
public:
2222
~Session();
2323

24-
int id() const;
24+
QString id() const;
2525
uid_t uid() const;
2626
const QString &username() const;
2727
WSocket *socket() const;
@@ -34,7 +34,7 @@ class Session : public QObject {
3434
private:
3535
friend class SessionManager;
3636

37-
int m_id = 0;
37+
QString m_id = {};
3838
uid_t m_uid = 0;
3939
QString m_username = {};
4040
WSocket *m_socket = nullptr;
@@ -61,9 +61,9 @@ class SessionManager : public QObject {
6161
bool activeSocketEnabled() const;
6262
void setActiveSocketEnabled(bool newEnabled);
6363

64-
void updateActiveUserSession(const QString &username, int id);
64+
void updateActiveUserSession(const QString &username, const QString &id);
6565
void removeSession(std::shared_ptr<Session> session);
66-
std::shared_ptr<Session> sessionForId(int id) const;
66+
std::shared_ptr<Session> sessionForId(const QString &id) const;
6767
std::shared_ptr<Session> sessionForUid(uid_t uid) const;
6868
std::shared_ptr<Session> sessionForUser(const QString &username) const;
6969
std::shared_ptr<Session> sessionForXWayland(WXWayland *xwayland) const;
@@ -74,7 +74,7 @@ class SessionManager : public QObject {
7474
void sessionChanged();
7575

7676
private:
77-
std::shared_ptr<Session> ensureSession(int id, QString username);
77+
std::shared_ptr<Session> ensureSession(QString id, QString username);
7878

7979
std::weak_ptr<Session> m_activeSession;
8080
QList<std::shared_ptr<Session>> m_sessions;

0 commit comments

Comments
 (0)