wayland: Avoid creating abstract socket for Xwayland on FreeBSD

FreeBSD does not support abstract sockets.
This commit is contained in:
Vlad Zahorodnii 2021-12-15 19:10:33 +02:00
parent e71fe9ba79
commit 34a0813567
4 changed files with 27 additions and 22 deletions

View file

@ -99,8 +99,10 @@ void KWinWrapper::run()
args << "--socket" << QString::fromUtf8(wl_socket_get_display_name(m_socket));
if (m_xwlSocket) {
args << "--xwayland-fd" << QString::number(m_xwlSocket->abstractFileDescriptor());
args << "--xwayland-fd" << QString::number(m_xwlSocket->unixFileDescriptor());
const auto xwaylandFileDescriptors = m_xwlSocket->fileDescriptors();
for (const int &fileDescriptor : xwaylandFileDescriptors) {
args << "--xwayland-fd" << QString::number(fileDescriptor);
}
args << "--xwayland-display" << m_xwlSocket->name();
if (m_xauthorityFile.open()) {
args << "--xwayland-xauthority" << m_xauthorityFile.fileName();

View file

@ -9,6 +9,7 @@
#include <QCoreApplication>
#include <QFile>
#include <QScopeGuard>
#include <errno.h>
#include <signal.h>
@ -176,24 +177,35 @@ XwaylandSocket::XwaylandSocket(OperationMode mode)
continue;
}
QVector<int> fileDescriptors;
auto socketCleanup = qScopeGuard([&fileDescriptors]() {
for (const int &fileDescriptor : qAsConst(fileDescriptors)) {
close(fileDescriptor);
}
});
const int unixFileDescriptor = listen_helper(socketFilePath, UnixSocketAddress::Type::Unix, mode);
if (unixFileDescriptor == -1) {
QFile::remove(lockFilePath);
continue;
}
fileDescriptors << unixFileDescriptor;
#if defined(Q_OS_LINUX)
const int abstractFileDescriptor = listen_helper(socketFilePath, UnixSocketAddress::Type::Abstract, mode);
if (abstractFileDescriptor == -1) {
QFile::remove(lockFilePath);
QFile::remove(socketFilePath);
close(unixFileDescriptor);
continue;
}
fileDescriptors << abstractFileDescriptor;
#endif
m_fileDescriptors = fileDescriptors;
socketCleanup.dismiss();
m_socketFilePath = socketFilePath;
m_lockFilePath = lockFilePath;
m_unixFileDescriptor = unixFileDescriptor;
m_abstractFileDescriptor = abstractFileDescriptor;
m_display = display;
return;
}
@ -203,11 +215,8 @@ XwaylandSocket::XwaylandSocket(OperationMode mode)
XwaylandSocket::~XwaylandSocket()
{
if (m_unixFileDescriptor != -1) {
close(m_unixFileDescriptor);
}
if (m_abstractFileDescriptor != -1) {
close(m_abstractFileDescriptor);
for (const int &fileDescriptor : qAsConst(m_fileDescriptors)) {
close(fileDescriptor);
}
if (!m_socketFilePath.isEmpty()) {
QFile::remove(m_socketFilePath);
@ -222,14 +231,9 @@ bool XwaylandSocket::isValid() const
return m_display != -1;
}
int XwaylandSocket::unixFileDescriptor() const
QVector<int> XwaylandSocket::fileDescriptors() const
{
return m_unixFileDescriptor;
}
int XwaylandSocket::abstractFileDescriptor() const
{
return m_abstractFileDescriptor;
return m_fileDescriptors;
}
int XwaylandSocket::display() const

View file

@ -8,6 +8,7 @@
#include <QByteArray>
#include <QString>
#include <QVector>
namespace KWin
{
@ -27,12 +28,10 @@ public:
int display() const;
QString name() const;
int unixFileDescriptor() const;
int abstractFileDescriptor() const;
QVector<int> fileDescriptors() const;
private:
int m_unixFileDescriptor = -1;
int m_abstractFileDescriptor = -1;
QVector<int> m_fileDescriptors;
int m_display = -1;
QString m_socketFilePath;
QString m_lockFilePath;

View file

@ -87,8 +87,8 @@ void Xwayland::start()
if (!m_socket->isValid()) {
qFatal("Failed to establish X11 socket");
}
setListenFDs({m_socket->unixFileDescriptor(), m_socket->abstractFileDescriptor()});
m_displayName = m_socket->name();
m_listenFds = m_socket->fileDescriptors();
}
startInternal();