From c73ba40ce9d7380cf6c2a91277f2b3087049a470 Mon Sep 17 00:00:00 2001 From: Carlo Castoldi Date: Sun, 13 Nov 2022 22:36:02 +0100 Subject: [PATCH] CHANGE(ipc): move Socket and OverlayPipe to $XDG_RUNTIME_DIR/mumble/ Moving MumbleSocket and MumbleOverlayPipe to a dedicated subdirectory keeps the runtime directory clean and allows flatpak applications to use the overlay by giving access only to Mumble's subdirectory. It also moves the default directory to /run/user/$UID/mumble/ when $XDG_RUNTIME_DIR is not set. Fixes #5951 --- overlay_gl/CMakeLists.txt | 15 +++++++++++---- overlay_gl/overlay.c | 28 +++++++++++++++++++--------- src/mumble/Overlay.cpp | 12 +++++++----- src/mumble/SocketRPC.cpp | 25 +++++++++++++++---------- src/tests/OverlayTest.cpp | 16 ++++++++++++++-- 5 files changed, 66 insertions(+), 30 deletions(-) diff --git a/overlay_gl/CMakeLists.txt b/overlay_gl/CMakeLists.txt index 4a0a2dc67ac..d510be6d31d 100644 --- a/overlay_gl/CMakeLists.txt +++ b/overlay_gl/CMakeLists.txt @@ -31,11 +31,18 @@ if(NOT APPLE) "-Wl,-z,lazy" ) - set_target_properties(overlay_gl - PROPERTIES - COMPILE_DEFINITIONS + if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + target_compile_definitions(overlay_gl + PRIVATE + "TARGET_LINUX" "TARGET_UNIX" - ) + ) + else() + target_compile_definitions(overlay_gl + PRIVATE + "TARGET_UNIX" + ) + endif() if(overlay-xcompile) # Just check for this header file while using a 32bit target as a really small and incomplete check whether g++-multilib seems to be diff --git a/overlay_gl/overlay.c b/overlay_gl/overlay.c index 54149268b1e..ddcb1ce9cb5 100644 --- a/overlay_gl/overlay.c +++ b/overlay_gl/overlay.c @@ -147,6 +147,22 @@ static void newContext(Context *ctx) { ctx->timeT = clock(); ctx->frameCount = 0; +#if defined(TARGET_LINUX) + char *xdgRuntimeDir = getenv("XDG_RUNTIME_DIR"); + + if (xdgRuntimeDir != NULL) { + ctx->saName.sun_family = PF_UNIX; + strcpy(ctx->saName.sun_path, xdgRuntimeDir); + strcat(ctx->saName.sun_path, "mumble/MumbleOverlayPipe"); + } else { + char uid[10]; + sprintf(uid, "%d", getuid()); + ctx->saName.sun_family = PF_UNIX; + strcpy(ctx->saName.sun_path, "/run/user/"); + strcat(ctx->saName.sun_path, uid); + strcat(ctx->saName.sun_path, "/mumble/MumbleOverlayPipe"); + } +#else char *home = getenv("HOME"); if (home == NULL) { struct passwd *pwent = getpwuid(getuid()); @@ -154,18 +170,12 @@ static void newContext(Context *ctx) { home = pwent->pw_dir; } } - - char *xdgRuntimeDir = getenv("XDG_RUNTIME_DIR"); - - if (xdgRuntimeDir != NULL) { - ctx->saName.sun_family = PF_UNIX; - strcpy(ctx->saName.sun_path, xdgRuntimeDir); - strcat(ctx->saName.sun_path, "/MumbleOverlayPipe"); - } else if (home) { + if (home) { ctx->saName.sun_family = PF_UNIX; strcpy(ctx->saName.sun_path, home); - strcat(ctx->saName.sun_path, "/.MumbleOverlayPipe"); + strcat(ctx->saName.sun_path, "/MumbleOverlayPipe"); } +#endif ods("OpenGL Version %s, Vendor %s, Renderer %s, Shader %s", glGetString(GL_VERSION), glGetString(GL_VENDOR), glGetString(GL_RENDERER), glGetString(GL_SHADING_LANGUAGE_VERSION)); diff --git a/src/mumble/Overlay.cpp b/src/mumble/Overlay.cpp index 10786752540..ed8c5f5d026 100644 --- a/src/mumble/Overlay.cpp +++ b/src/mumble/Overlay.cpp @@ -244,13 +244,15 @@ void Overlay::createPipe() { #else { QString xdgRuntimePath = QProcessEnvironment::systemEnvironment().value(QLatin1String("XDG_RUNTIME_DIR")); - QDir xdgRuntimeDir = QDir(xdgRuntimePath); - - if (!xdgRuntimePath.isNull() && xdgRuntimeDir.exists()) { - pipepath = xdgRuntimeDir.absoluteFilePath(QLatin1String("MumbleOverlayPipe")); + QString mumbleRuntimePath; + if (!xdgRuntimePath.isNull()) { + mumbleRuntimePath = QDir(xdgRuntimePath).absolutePath() + QLatin1String("/mumble/"); } else { - pipepath = QDir::home().absoluteFilePath(QLatin1String(".MumbleOverlayPipe")); + mumbleRuntimePath = QLatin1String("/run/user/") + QString::number(getuid()) + QLatin1String("/mumble/"); } + QDir mumbleRuntimeDir = QDir(mumbleRuntimePath); + mumbleRuntimeDir.mkpath("."); + pipepath = mumbleRuntimeDir.absoluteFilePath(QLatin1String("MumbleOverlayPipe")); } { diff --git a/src/mumble/SocketRPC.cpp b/src/mumble/SocketRPC.cpp index 0aabc8b1528..bf1bcb6c6ad 100644 --- a/src/mumble/SocketRPC.cpp +++ b/src/mumble/SocketRPC.cpp @@ -236,13 +236,15 @@ SocketRPC::SocketRPC(const QString &basename, QObject *p) : QObject(p) { #else { QString xdgRuntimePath = QProcessEnvironment::systemEnvironment().value(QLatin1String("XDG_RUNTIME_DIR")); - QDir xdgRuntimeDir = QDir(xdgRuntimePath); - - if (!xdgRuntimePath.isNull() && xdgRuntimeDir.exists()) { - pipepath = xdgRuntimeDir.absoluteFilePath(basename + QLatin1String("Socket")); + QString mumbleRuntimePath; + if (!xdgRuntimePath.isNull()) { + mumbleRuntimePath = QDir(xdgRuntimePath).absolutePath() + QLatin1String("/mumble/"); } else { - pipepath = QDir::home().absoluteFilePath(QLatin1String(".") + basename + QLatin1String("Socket")); + mumbleRuntimePath = QLatin1String("/run/user/") + QString::number(getuid()) + QLatin1String("/mumble/"); } + QDir mumbleRuntimeDir = QDir(mumbleRuntimePath); + mumbleRuntimeDir.mkpath("."); + pipepath = mumbleRuntimeDir.absoluteFilePath(basename + QLatin1String("Socket")); } { @@ -280,13 +282,15 @@ bool SocketRPC::send(const QString &basename, const QString &request, const QMap #else { QString xdgRuntimePath = QProcessEnvironment::systemEnvironment().value(QLatin1String("XDG_RUNTIME_DIR")); - QDir xdgRuntimeDir = QDir(xdgRuntimePath); - - if (!xdgRuntimePath.isNull() && xdgRuntimeDir.exists()) { - pipepath = xdgRuntimeDir.absoluteFilePath(basename + QLatin1String("Socket")); + QString mumbleRuntimePath; + if (!xdgRuntimePath.isNull()) { + mumbleRuntimePath = QDir(xdgRuntimePath).absolutePath() + QLatin1String("/mumble/"); } else { - pipepath = QDir::home().absoluteFilePath(QLatin1String(".") + basename + QLatin1String("Socket")); + mumbleRuntimePath = QLatin1String("/run/user/") + QString::number(getuid()) + QLatin1String("/mumble/"); } + QDir mumbleRuntimeDir = QDir(mumbleRuntimePath); + mumbleRuntimeDir.mkpath("."); + pipepath = mumbleRuntimeDir.absoluteFilePath(basename + QLatin1String("Socket")); } #endif @@ -325,3 +329,4 @@ bool SocketRPC::send(const QString &basename, const QString &request, const QMap return QVariant(succ.text()).toBool(); } + diff --git a/src/tests/OverlayTest.cpp b/src/tests/OverlayTest.cpp index a565d54e97d..8d8e8e4a732 100644 --- a/src/tests/OverlayTest.cpp +++ b/src/tests/OverlayTest.cpp @@ -16,6 +16,7 @@ # include "win.h" #endif +#include #include #include #include @@ -96,7 +97,18 @@ void OverlayWidget::paintEvent(QPaintEvent *) { #ifdef Q_OS_WIN qlsSocket->connectToServer(QLatin1String("MumbleOverlayPipe")); #else - qlsSocket->connectToServer(QDir::home().absoluteFilePath(QLatin1String(".MumbleOverlayPipe"))); + QString xdgRuntimePath = QProcessEnvironment::systemEnvironment().value(QLatin1String("XDG_RUNTIME_DIR")); + QString mumbleRuntimePath; + if (!xdgRuntimePath.isNull()) { + mumbleRuntimePath = QDir(xdgRuntimePath).absolutePath() + QLatin1String("/mumble/"); + } else { + mumbleRuntimePath = QLatin1String("/run/user/") + QString::number(getuid()) + QLatin1String("/mumble/"); + } + QDir mumbleRuntimeDir = QDir(mumbleRuntimePath); + mumbleRuntimeDir.mkpath("."); + QString pipepath = mumbleRuntimeDir.absoluteFilePath(QLatin1String("MumbleOverlayPipe")); + qWarning() << "connectToServer(" << pipepath << ")"; + qlsSocket->connectToServer(pipepath); #endif } @@ -166,7 +178,7 @@ void OverlayWidget::disconnected() { } void OverlayWidget::error(QLocalSocket::LocalSocketError) { - qWarning() << "error"; + perror("error"); disconnected(); }