Skip to content

Commit

Permalink
CHANGE(ipc): move Socket and OverlayPipe to $XDG_RUNTIME_DIR/mumble/
Browse files Browse the repository at this point in the history
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 mumble-voip#5951
  • Loading branch information
carlocastoldi committed Nov 15, 2022
1 parent ea24da4 commit c73ba40
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 30 deletions.
15 changes: 11 additions & 4 deletions overlay_gl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 19 additions & 9 deletions overlay_gl/overlay.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,25 +147,35 @@ 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());
if (pwent && pwent->pw_dir && pwent->pw_dir[0]) {
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));
Expand Down
12 changes: 7 additions & 5 deletions src/mumble/Overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}

{
Expand Down
25 changes: 15 additions & 10 deletions src/mumble/SocketRPC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}

{
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -325,3 +329,4 @@ bool SocketRPC::send(const QString &basename, const QString &request, const QMap

return QVariant(succ.text()).toBool();
}

16 changes: 14 additions & 2 deletions src/tests/OverlayTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# include "win.h"
#endif

#include <unistd.h>
#include <QtCore>
#include <QtGui>
#include <QtNetwork>
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -166,7 +178,7 @@ void OverlayWidget::disconnected() {
}

void OverlayWidget::error(QLocalSocket::LocalSocketError) {
qWarning() << "error";
perror("error");
disconnected();
}

Expand Down

0 comments on commit c73ba40

Please sign in to comment.