Skip to content

Commit

Permalink
chore: move treeland to systemd service
Browse files Browse the repository at this point in the history
disable greeter in single wayland mode

Log:
  • Loading branch information
justforlxz authored and Groveer committed Dec 20, 2024
1 parent f452d3d commit d4f7fe8
Show file tree
Hide file tree
Showing 13 changed files with 191 additions and 35 deletions.
5 changes: 5 additions & 0 deletions data/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ install(FILES
RENAME ${DBUS_CONFIG_FILENAME}
)

install(FILES
"org.deepin.DisplayManager.conf"
DESTINATION "${DBUS_CONFIG_DIR}"
)

install(FILES
"faces/root.face.icon.png"
DESTINATION "${DATA_INSTALL_DIR}/faces"
Expand Down
18 changes: 18 additions & 0 deletions data/interfaces/org.deepin.DisplayManager.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.deepin.DisplayManager">
<method name="AuthInfo">
<arg type="s" name="auth socket" direction="out">
</arg>
</method>
<signal name="AuthInfoChanged">
</signal>
<method name="LastActivatedUser">
<arg type="s" name="last activated user" direction="out">
</arg>
</method>
<signal name="LastActivatedUserChanged">
</signal>
</interface>
</node>

26 changes: 26 additions & 0 deletions data/org.deepin.DisplayManager.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE busconfig PUBLIC
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>

<policy user="root">
<allow own="org.deepin.DisplayManager"/>
<allow send_destination="org.deepin.DisplayManager" send_interface="org.deepin.DisplayManager" send_member="AuthInfo"/>
</policy>

<policy user="dde">
<allow send_destination="org.deepin.DisplayManager" send_interface="org.deepin.DisplayManager" send_member="AuthInfo"/>
</policy>

<policy group="default">
<allow send_destination="org.deepin.DisplayManager" />
<allow send_destination="org.deepin.DisplayManager"
send_interface="org.deepin.DisplayManager"/>
<allow send_destination="org.deepin.DisplayManager"
send_interface="org.freedesktop.DBus.Properties"/>
<allow send_destination="org.deepin.DisplayManager"
send_interface="org.freedesktop.DBus.Introspectable"/>
<deny send_interface="org.deepin.DisplayManager" send_member="AuthInfo"/>
</policy>
</busconfig>

2 changes: 2 additions & 0 deletions services/ddm-sysuser.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
u dde - "DDM Greeter Account" ${STATE_DIR} -
g dde -
m dde dde
m dde video
m dde render
1 change: 1 addition & 0 deletions src/daemon/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ set(DAEMON_SOURCES
qt_add_dbus_adaptor(DAEMON_SOURCES "${CMAKE_SOURCE_DIR}/data/interfaces/org.freedesktop.DisplayManager.xml" "DisplayManager.h" DDM::DisplayManager)
qt_add_dbus_adaptor(DAEMON_SOURCES "${CMAKE_SOURCE_DIR}/data/interfaces/org.freedesktop.DisplayManager.Seat.xml" "DisplayManager.h" DDM::DisplayManagerSeat)
qt_add_dbus_adaptor(DAEMON_SOURCES "${CMAKE_SOURCE_DIR}/data/interfaces/org.freedesktop.DisplayManager.Session.xml" "DisplayManager.h" DDM::DisplayManagerSession)
qt_add_dbus_adaptor(DAEMON_SOURCES "${CMAKE_SOURCE_DIR}/data/interfaces/org.deepin.DisplayManager.xml" "DisplayManager.h" DDM::DisplayManager dbus_ddm_displaymanager DDMDisplayManagerAdaptor)

set_source_files_properties("${CMAKE_SOURCE_DIR}/data/interfaces/org.freedesktop.login1.Manager.xml" PROPERTIES
INCLUDE "LogindDBusTypes.h"
Expand Down
5 changes: 5 additions & 0 deletions src/daemon/Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@ namespace DDM {
// start socket server
m_socketServer->start(m_displayServer->display());

// Update dbus info
DaemonApp::instance()->displayManager()->setAuthInfo(m_socketServer->socketAddress());

if (!daemonApp->testing()) {
// change the owner and group of the socket to avoid permission denied errors
struct passwd *pw = getpwnam("dde");
Expand Down Expand Up @@ -595,6 +598,7 @@ namespace DDM {

m_currentAuth = auth;
m_greeter->setUserActivated(success);
DaemonApp::instance()->displayManager()->setLastActivatedUser(user);

if (success) {
if (!m_reuseSessionId.isNull()) {
Expand Down Expand Up @@ -671,6 +675,7 @@ namespace DDM {

if (m_currentAuth == auth) {
m_currentAuth = nullptr;
DaemonApp::instance()->displayManager()->setLastActivatedUser("");
}

m_auths.removeOne(auth);
Expand Down
33 changes: 33 additions & 0 deletions src/daemon/DisplayManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "DaemonApp.h"
#include "SeatManager.h"

#include "dbus_ddm_displaymanager.h"
#include "displaymanageradaptor.h"
#include "seatadaptor.h"
#include "sessionadaptor.h"
Expand All @@ -35,11 +36,15 @@ namespace DDM {
DisplayManager::DisplayManager(QObject *parent) : QObject(parent) {
// create adaptor
new DisplayManagerAdaptor(this);
new DDMDisplayManagerAdaptor(this);

// register object
QDBusConnection connection = (daemonApp->testing()) ? QDBusConnection::sessionBus() : QDBusConnection::systemBus();
connection.registerService(DISPLAYMANAGER_SERVICE);
connection.registerObject(DISPLAYMANAGER_PATH, this);

connection.registerService("org.deepin.DisplayManager");
connection.registerObject("/org/deepin/DisplayManager", this);
}

QString DisplayManager::seatPath(const QString &seatName) {
Expand Down Expand Up @@ -69,6 +74,34 @@ namespace DDM {
return sessions;
}

QString DisplayManager::AuthInfo() const {
return m_authSocket;
}

void DisplayManager::setAuthInfo(const QString &authSocket) {
if (m_authSocket == authSocket) {
return;
}

m_authSocket = authSocket;

Q_EMIT AuthInfoChanged();
}

QString DisplayManager::LastActivatedUser() const {
return m_lastActivatedUser;
}

void DisplayManager::setLastActivatedUser(const QString &lastActivatedUser) {
if (m_lastActivatedUser == lastActivatedUser) {
return;
}

m_lastActivatedUser = lastActivatedUser;

Q_EMIT LastActivatedUserChanged();
}

void DisplayManager::AddSeat(const QString &name) {
// create seat object
DisplayManagerSeat *seat = new DisplayManagerSeat(name, this);
Expand Down
13 changes: 13 additions & 0 deletions src/daemon/DisplayManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <QDBusObjectPath>
#include <QList>
#include <QDBusUnixFileDescriptor>

namespace DDM {
class DisplayManagerSeat;
Expand All @@ -41,6 +42,9 @@ namespace DDM {
Q_PROPERTY(QList<QDBusObjectPath> Seats READ Seats CONSTANT)
Q_PROPERTY(QList<QDBusObjectPath> Sessions READ Sessions CONSTANT)
Q_PROPERTY(QDBusObjectPath LastSession READ LastSession NOTIFY LastSessionChanged CONSTANT)
Q_PROPERTY(QString AuthInfo READ AuthInfo NOTIFY AuthInfoChanged)
Q_PROPERTY(QString LastActivatedUser READ LastActivatedUser NOTIFY LastActivatedUserChanged)

public:
DisplayManager(QObject *parent = 0);

Expand All @@ -53,24 +57,33 @@ namespace DDM {
return m_lastSession;
}

QString AuthInfo() const;
QString LastActivatedUser() const;

public slots:
void AddSeat(const QString &name);
void RemoveSeat(const QString &name);
void AddSession(const QString &name, const QString &seat, const QString &user);
void RemoveSession(const QString &name);
void setLastSession(const QString &session);
void setAuthInfo(const QString &authSocket);
void setLastActivatedUser(const QString &lastActivatedUser);

signals:
void SeatAdded(ObjectPath seat);
void SeatRemoved(ObjectPath seat);
void SessionAdded(ObjectPath session);
void SessionRemoved(ObjectPath session);
void LastSessionChanged(ObjectPath session);
void AuthInfoChanged();
void LastActivatedUserChanged();

private:
QList<DisplayManagerSeat *> m_seats;
QList<DisplayManagerSession *> m_sessions;
QDBusObjectPath m_lastSession;
QString m_authSocket;
QString m_lastActivatedUser;
};

/***************************************************************************
Expand Down
6 changes: 6 additions & 0 deletions src/daemon/Greeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ namespace DDM {
m_auth->setGreeter(true);
m_auth->setSession(cmd.join(QLatin1Char(' ')));
m_auth->setSingleMode(m_singleMode);

// TODO: single compositer mode not need greeter
if (m_singleMode) {
return true;
}

m_auth->start();

m_tryTimer->start();
Expand Down
75 changes: 61 additions & 14 deletions src/daemon/SingleWaylandDisplayServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
// SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "SingleWaylandDisplayServer.h"
#include "DaemonApp.h"
#include "DisplayManager.h"
#include "Messages.h"
#include "SocketServer.h"
#include "Constants.h"
#include "SocketWriter.h"
#include "Utils.h"
#include "Display.h"

#include <QDBusInterface>
#include <QDBusConnection>
#include <QStandardPaths>
#include <QChar>
#include <QLocalSocket>
Expand All @@ -23,22 +27,9 @@
using namespace DDM;

SingleWaylandDisplayServer::SingleWaylandDisplayServer(SocketServer *socketServer, Display *parent)
: DDM::WaylandDisplayServer(parent)
: DDM::DisplayServer(parent)
, m_socketServer(socketServer)
, m_helper(new QProcess(this))
{
connect(m_helper, &QProcess::readyReadStandardOutput, this, [this] {
qInfo() << m_helper->readAllStandardOutput();
});
connect(m_helper, &QProcess::readyReadStandardError, this, [this] {
qWarning() << m_helper->readAllStandardError();
});

QString socketName = QStringLiteral("treeland-helper-%1").arg(generateName(6));

// log message
qDebug() << "Socket server started.";

connect(m_socketServer, &SocketServer::connected, this, [this, parent](QLocalSocket *socket) {
m_greeterSockets << socket;
});
Expand All @@ -52,6 +43,62 @@ SingleWaylandDisplayServer::SingleWaylandDisplayServer(SocketServer *socketServe
});
}

SingleWaylandDisplayServer::~SingleWaylandDisplayServer() {
stop();
}

QString SingleWaylandDisplayServer::sessionType() const
{
return QStringLiteral("wayland");
}

void SingleWaylandDisplayServer::setDisplayName(const QString &displayName)
{
m_display = displayName;
}

bool SingleWaylandDisplayServer::start()
{
// Check flag
if (m_started)
return false;

// Start treeland service
QDBusInterface systemd("org.freedesktop.systemd1", "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", QDBusConnection::systemBus());
systemd.call("StartUnit", "treeland.service", "replace");

// TODO: check treeland service

// Set flag
m_started = true;
emit started();

return true;
}

void SingleWaylandDisplayServer::stop()
{
// Check flag
if (!m_started)
return;

// Stop treeland service
QDBusInterface systemd("org.freedesktop.systemd1", "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", QDBusConnection::systemBus());
systemd.call("StopUnit", "treeland.service", "replace");

// Reset flag
m_started = false;
emit stopped();
}

void SingleWaylandDisplayServer::finished()
{
}

void SingleWaylandDisplayServer::setupDisplay()
{
}

void SingleWaylandDisplayServer::activateUser(const QString &user) {
for (auto greeter : m_greeterSockets) {
if (user == "dde") {
Expand Down
14 changes: 11 additions & 3 deletions src/daemon/SingleWaylandDisplayServer.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (C) 2023 Dingyuan Zhang <lxz@mkacg.com>.
// SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "WaylandDisplayServer.h"
#include "DisplayServer.h"

#include <QMap>
#include <QDBusVariant>
Expand All @@ -13,17 +13,26 @@ namespace DDM {
class SocketServer;
}

class SingleWaylandDisplayServer : public DDM::WaylandDisplayServer
class SingleWaylandDisplayServer : public DDM::DisplayServer
{
Q_OBJECT
Q_DISABLE_COPY(SingleWaylandDisplayServer)
public:
explicit SingleWaylandDisplayServer(DDM::SocketServer *socketServer, DDM::Display *parent);
~SingleWaylandDisplayServer();

QString sessionType() const;

void setDisplayName(const QString &displayName);

Q_SIGNALS:
void createWaylandSocketFinished();

public Q_SLOTS:
bool start();
void stop();
void finished();
void setupDisplay();
void activateUser(const QString &user);
QString getUserWaylandSocket(const QString &user) const;
void onLoginFailed(const QString &user);
Expand All @@ -33,5 +42,4 @@ public Q_SLOTS:
DDM::SocketServer *m_socketServer;
QList<QLocalSocket*> m_greeterSockets;
QMap<QString, QString> m_waylandSockets;
QProcess *m_helper;
};
3 changes: 2 additions & 1 deletion src/helper/HelperApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <QtCore/QDebug>
#include <QtNetwork/QLocalSocket>

#include <fcntl.h>
#include <iostream>
#include <unistd.h>
#include <sys/socket.h>
Expand Down Expand Up @@ -133,7 +134,7 @@ namespace DDM {
connect(m_session, &UserSession::finished, this, &HelperApp::sessionFinished);
}

connect(new SignalHandler(this), &SignalHandler::sigtermReceived, this, [this] {
connect(new SignalHandler(this), &SignalHandler::sigtermReceived, this, [] {
qDebug() << "sigterm received.";
qApp->quit();
});
Expand Down
Loading

0 comments on commit d4f7fe8

Please sign in to comment.