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 14, 2022
1 parent ea24da4 commit db29282
Show file tree
Hide file tree
Showing 4 changed files with 2,386 additions and 27 deletions.
19 changes: 7 additions & 12 deletions overlay_gl/overlay.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,24 +147,19 @@ static void newContext(Context *ctx) {
ctx->timeT = clock();
ctx->frameCount = 0;

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) {
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, home);
strcat(ctx->saName.sun_path, "/.MumbleOverlayPipe");
strcpy(ctx->saName.sun_path, "/run/user/");
strcat(ctx->saName.sun_path, uid);
strcat(ctx->saName.sun_path, "/mumble/MumbleOverlayPipe");
}

ods("OpenGL Version %s, Vendor %s, Renderer %s, Shader %s", glGetString(GL_VERSION), glGetString(GL_VENDOR),
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();
}

Loading

0 comments on commit db29282

Please sign in to comment.