From 15936a9bbfeacd3290b3c0f926c4c712b1880bc3 Mon Sep 17 00:00:00 2001 From: Carlo Castoldi Date: Sun, 13 Nov 2022 22:36:02 +0100 Subject: [PATCH 1/6] 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 | 7 +++---- overlay_gl/overlay.c | 30 +++++++++++++++++++++--------- src/mumble/Overlay.cpp | 12 +++++++----- src/mumble/SocketRPC.cpp | 25 +++++++++++++++---------- src/tests/OverlayTest.cpp | 16 ++++++++++++++-- 5 files changed, 60 insertions(+), 30 deletions(-) diff --git a/overlay_gl/CMakeLists.txt b/overlay_gl/CMakeLists.txt index f8e16a2afdf..9951c70c22d 100644 --- a/overlay_gl/CMakeLists.txt +++ b/overlay_gl/CMakeLists.txt @@ -31,10 +31,9 @@ if(NOT APPLE) "-Wl,-z,lazy" ) - set_target_properties(overlay_gl - PROPERTIES - COMPILE_DEFINITIONS - "TARGET_UNIX" + target_compile_definitions(overlay_gl + PRIVATE + "TARGET_UNIX" ) if(overlay-xcompile) diff --git a/overlay_gl/overlay.c b/overlay_gl/overlay.c index de36c85b3a4..5fbc493ce03 100644 --- a/overlay_gl/overlay.c +++ b/overlay_gl/overlay.c @@ -147,6 +147,24 @@ static void newContext(Context *ctx) { ctx->timeT = clock(); ctx->frameCount = 0; +#ifdef __linux__ + char *xdgRuntimeDir = getenv("XDG_RUNTIME_DIR"); + + if (xdgRuntimeDir != NULL) { + ctx->saName.sun_family = PF_UNIX; + strcpy(ctx->saName.sun_path, xdgRuntimeDir); + if(xdgRuntimeDir[(strlen(xdgRuntimeDir)-1)] != '/') + strcat(ctx->saName.sun_path, "/"); + 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 +172,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 30543ef1acd..59bc5786c41 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 c2ed743a175..acf70e7927e 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 cc35973284e..7720d786abe 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(); } From 7212c49c5cc37a3cafd070d72b0fbc9fb359536f Mon Sep 17 00:00:00 2001 From: Carlo Castoldi Date: Tue, 15 Nov 2022 00:12:13 +0100 Subject: [PATCH 2/6] TEST: move TestOverlay.cpp into a tests/ subdir --- src/tests/{ => OverlayTest}/OverlayTest.cpp | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/tests/{ => OverlayTest}/OverlayTest.cpp (100%) diff --git a/src/tests/OverlayTest.cpp b/src/tests/OverlayTest/OverlayTest.cpp similarity index 100% rename from src/tests/OverlayTest.cpp rename to src/tests/OverlayTest/OverlayTest.cpp From aa15c61673f045c07327127d877341622e6b4103 Mon Sep 17 00:00:00 2001 From: Carlo Castoldi Date: Tue, 15 Nov 2022 00:59:40 +0100 Subject: [PATCH 3/6] TEST(overlay): adds build files for OverlayTest adds a test application that connects to MumbleOverlayPipe and displays the overlay as configured. It's disabled by default as it is designed to be a check for humans --- src/tests/CMakeLists.txt | 1 + src/tests/OverlayTest/CMakeLists.txt | 18 ++++++++++++++++++ src/tests/OverlayTest/OverlayTest.cpp | 20 ++++++++++++-------- 3 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 src/tests/OverlayTest/CMakeLists.txt diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 0e780859517..fa83ff099cb 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -20,6 +20,7 @@ if(client) # For some reason Qt segfaults when executing this test on FreeBSD without a display (even when using the offscreen plugin) use_test("TestSettingsJSONSerialization") endif() + use_test("OverlayTest") endif() if(server) diff --git a/src/tests/OverlayTest/CMakeLists.txt b/src/tests/OverlayTest/CMakeLists.txt new file mode 100644 index 00000000000..c47fa6a2c57 --- /dev/null +++ b/src/tests/OverlayTest/CMakeLists.txt @@ -0,0 +1,18 @@ +# Copyright 2020-2022 The Mumble Developers. All rights reserved. +# Use of this source code is governed by a BSD-style license +# that can be found in the LICENSE file at the root of the +# Mumble source tree or at . + +add_executable(OverlayTest OverlayTest.cpp) + +set_target_properties(OverlayTest PROPERTIES AUTOMOC ON) + +find_pkg(Qt5 COMPONENTS Gui Widgets REQUIRED) + +target_link_libraries(OverlayTest PRIVATE mumble_client_object_lib) +target_link_libraries(OverlayTest PRIVATE shared Qt5::Test Qt5::Widgets) + +add_test(NAME OverlayTest COMMAND $) + +# OverlayTest is disabled because it can only be tested by humans checking that the application is correctly displaying the overlay +set_tests_properties(OverlayTest PROPERTIES DISABLED TRUE) diff --git a/src/tests/OverlayTest/OverlayTest.cpp b/src/tests/OverlayTest/OverlayTest.cpp index 7720d786abe..0eb59716323 100644 --- a/src/tests/OverlayTest/OverlayTest.cpp +++ b/src/tests/OverlayTest/OverlayTest.cpp @@ -14,14 +14,18 @@ #ifdef Q_OS_WIN # include "win.h" +#else +# include #endif -#include #include #include #include -#include +#include +#include +#include + class OverlayWidget : public QWidget { Q_OBJECT @@ -33,7 +37,7 @@ class OverlayWidget : public QWidget { SharedMemory2 *smMem; QTimer *qtTimer; QRect qrActive; - QTime qtWall; + QElapsedTimer qtWall; unsigned int iFrameCount; int iLastFpsUpdate; @@ -185,7 +189,6 @@ void OverlayWidget::error(QLocalSocket::LocalSocketError) { void OverlayWidget::update() { ++iFrameCount; - clock_t t = clock(); float elapsed = static_cast< float >(qtWall.elapsed() - iLastFpsUpdate) / 1000.0f; if (elapsed > OVERLAY_FPS_INTERVAL) { @@ -216,12 +219,12 @@ void OverlayWidget::readyRead() { int ready = qlsSocket->bytesAvailable(); if (om.omh.iLength == -1) { - if (ready < sizeof(OverlayMsgHeader)) + if ((size_t)ready < sizeof(OverlayMsgHeader)) break; else { qlsSocket->read(reinterpret_cast< char * >(om.headerbuffer), sizeof(OverlayMsgHeader)); if ((om.omh.uiMagic != OVERLAY_MAGIC_NUMBER) || (om.omh.iLength < 0) - || (om.omh.iLength > sizeof(OverlayMsgShmem))) { + || ((size_t)om.omh.iLength > sizeof(OverlayMsgShmem))) { detach(); return; } @@ -264,11 +267,12 @@ void OverlayWidget::readyRead() { if (!smMem) break; - if (((omb->x + omb->w) > img.width()) || ((omb->y + omb->h) > img.height())) + if (((omb->x + omb->w) > (unsigned int)img.width()) + || ((omb->y + omb->h) > (unsigned int)img.height())) break; - for (int y = 0; y < omb->h; ++y) { + for (unsigned int y = 0; y < omb->h; ++y) { unsigned char *src = reinterpret_cast< unsigned char * >(smMem->data()) + 4 * (width() * (y + omb->y) + omb->x); unsigned char *dst = img.scanLine(y + omb->y) + omb->x * 4; From bb6b2de34b503fd292177e3e88d9e3f151605b6f Mon Sep 17 00:00:00 2001 From: Carlo Castoldi Date: Tue, 15 Nov 2022 12:23:47 +0100 Subject: [PATCH 4/6] REFAC(ipc): extract IPCUtils for Socket and OverlayPipe --- overlay/CMakeLists.txt | 2 + overlay/ipc_utils.c | 107 ++++++++++++++++++++++++++ overlay/ipc_utils.h | 13 ++++ overlay_gl/overlay.c | 37 ++------- src/mumble/CMakeLists.txt | 4 + src/mumble/IPCUtils.cpp | 51 ++++++++++++ src/mumble/IPCUtils.h | 30 ++++++++ src/mumble/Overlay.cpp | 28 ++----- src/mumble/SocketRPC.cpp | 50 +++--------- src/tests/OverlayTest/OverlayTest.cpp | 43 +++++------ 10 files changed, 248 insertions(+), 117 deletions(-) create mode 100644 overlay/ipc_utils.c create mode 100644 overlay/ipc_utils.h create mode 100644 src/mumble/IPCUtils.cpp create mode 100644 src/mumble/IPCUtils.h diff --git a/overlay/CMakeLists.txt b/overlay/CMakeLists.txt index 17ce52e9a7f..7c7f74cd879 100644 --- a/overlay/CMakeLists.txt +++ b/overlay/CMakeLists.txt @@ -94,6 +94,8 @@ target_sources(overlay "dxgi.cpp" "excludecheck.cpp" "excludecheck.h" + "ipc_utils.h" + "ipc_utils.c" "lib.cpp" "lib.h" "ods.cpp" diff --git a/overlay/ipc_utils.c b/overlay/ipc_utils.c new file mode 100644 index 00000000000..30d0b6736b9 --- /dev/null +++ b/overlay/ipc_utils.c @@ -0,0 +1,107 @@ +// Copyright 2022 The Mumble Developers. All rights reserved. +// Use of this source code is governed by a BSD-style license +// that can be found in the LICENSE file at the root of the +// Mumble source tree or at . + +#include "ipc_utils.h" +#include + +#ifdef _WIN32 +# include +# include +# include +#else +# include +# include +# include +# include +# include +# include +#endif + +char *getRuntimePath__() { + size_t n = 0; + char *path = NULL; + +#ifdef __linux__ + char *xdgRuntimeDir = getenv("XDG_RUNTIME_DIR"); + + if (xdgRuntimeDir != NULL) { + if (xdgRuntimeDir) + n += strlen(xdgRuntimeDir); + if (xdgRuntimeDir[(strlen(xdgRuntimeDir) - 1)] != '/') + n++; + n += strlen("mumble/"); + + if ((path = malloc(n + 1)) == NULL) + return path; + *path = '\0'; + + strcpy(path, xdgRuntimeDir); + if (xdgRuntimeDir[(strlen(xdgRuntimeDir) - 1)] != '/') + strcat(path, "/"); + strcat(path, "mumble/"); + } else { + char uid[10]; + n += strlen("/run/user//mumble/"); + sprintf(uid, "%d", getuid()); + n += strlen(uid); + + if ((path = malloc(n + 1)) == NULL) + return path; + *path = '\0'; + + strcpy(path, "/run/user/"); + strcat(path, uid); + strcat(path, "/mumble/"); + } +#elif defined(_WIN32) + path = strdup(""); +#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; + } + if (home == NULL) + return NULL; + n += strlen(home); + if (home[(strlen(home) - 1)] != '/') + n++; + if ((path = malloc(n + 1)) == NULL) + return path; + strcpy(path, home); + if (home[(strlen(home) - 1)] != '/') + strcat(path, "/"); +#endif + return path; +} + +char *getAndCreateOverlayPipePath__() { + char *runtimePath = getRuntimePath__(); + char *path = NULL; + if (runtimePath == NULL) + return runtimePath; +#if _WIN32 +/* + * on Windows we don't create the directory as getRuntimePath__() returns an empty string. + _mkdir(runtimePath); +*/ +#else + mkdir(runtimePath, 0755); +#endif + size_t n = 1; + n += strlen(runtimePath); + n += strlen("MumbleOverlayPipe"); + path = (char *) malloc(n + 1); + if (path == NULL) + return path; +#if !defined __linux__ && !defined _WIN32 + strcat(path, "."); +#endif + strcpy(path, runtimePath); + strcat(path, "MumbleOverlayPipe"); + free(runtimePath); + return path; +} \ No newline at end of file diff --git a/overlay/ipc_utils.h b/overlay/ipc_utils.h new file mode 100644 index 00000000000..2fc91d0cb33 --- /dev/null +++ b/overlay/ipc_utils.h @@ -0,0 +1,13 @@ +// Copyright 2022 The Mumble Developers. All rights reserved. +// Use of this source code is governed by a BSD-style license +// that can be found in the LICENSE file at the root of the +// Mumble source tree or at . + +#ifndef MUMBLE_OVERLAY_IPC_UTILS_H__ +#define MUMBLE_OVERLAY_IPC_UTILS_H__ + +char *getRuntimePath__(); + +char *getAndCreateOverlayPipePath__(); + +#endif // MUMBLE_OVERLAY_IPC_UTILS_H__ \ No newline at end of file diff --git a/overlay_gl/overlay.c b/overlay_gl/overlay.c index 5fbc493ce03..34a97a2f81a 100644 --- a/overlay_gl/overlay.c +++ b/overlay_gl/overlay.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -53,6 +52,7 @@ typedef unsigned char bool; # include "avail_mac.h" #endif +#include "../overlay/ipc_utils.h" #include "../overlay/overlay.h" static bool bDebug = false; @@ -147,37 +147,10 @@ static void newContext(Context *ctx) { ctx->timeT = clock(); ctx->frameCount = 0; -#ifdef __linux__ - char *xdgRuntimeDir = getenv("XDG_RUNTIME_DIR"); - - if (xdgRuntimeDir != NULL) { - ctx->saName.sun_family = PF_UNIX; - strcpy(ctx->saName.sun_path, xdgRuntimeDir); - if(xdgRuntimeDir[(strlen(xdgRuntimeDir)-1)] != '/') - strcat(ctx->saName.sun_path, "/"); - 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; - } - } - if (home) { - ctx->saName.sun_family = PF_UNIX; - strcpy(ctx->saName.sun_path, home); - strcat(ctx->saName.sun_path, "/MumbleOverlayPipe"); - } -#endif + char *path = getAndCreateOverlayPipePath__(); + strcpy(ctx->saName.sun_path, path); + free(path); + ctx->saName.sun_family = PF_UNIX; 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/CMakeLists.txt b/src/mumble/CMakeLists.txt index dbbbada4f46..ad07bda55c3 100644 --- a/src/mumble/CMakeLists.txt +++ b/src/mumble/CMakeLists.txt @@ -156,6 +156,10 @@ set(MUMBLE_SOURCES "GlobalShortcutButtons.ui" "GlobalShortcutTarget.ui" "GlobalShortcutTypes.h" + "IPCUtils.cpp" + "IPCUtils.h" + "${CMAKE_SOURCE_DIR}/overlay/ipc_utils.c" + "${CMAKE_SOURCE_DIR}/overlay/ipc_utils.h" "JSONSerialization.cpp" "JSONSerialization.h" "LCD.cpp" diff --git a/src/mumble/IPCUtils.cpp b/src/mumble/IPCUtils.cpp new file mode 100644 index 00000000000..de186360e5f --- /dev/null +++ b/src/mumble/IPCUtils.cpp @@ -0,0 +1,51 @@ +// Copyright 2021-2022 The Mumble Developers. All rights reserved. +// Use of this source code is governed by a BSD-style license +// that can be found in the LICENSE file at the root of the +// Mumble source tree or at . + +#include "IPCUtils.h" +extern "C" { +#include "../../overlay/ipc_utils.h" +} + +#include +#include +#include + +namespace Mumble { +const std::string getRuntimePath(void) { + char *c_mumbleRuntimePath = getRuntimePath__(); + if (c_mumbleRuntimePath == NULL) + return ""; + std::string mumbleRuntimePath = c_mumbleRuntimePath; + std::free(c_mumbleRuntimePath); + return mumbleRuntimePath; +} + +const std::string getAndCreateOverlayPipePath(void) { + char *c_pipepath = getAndCreateOverlayPipePath__(); + if (c_pipepath == NULL) + return ""; + std::string pipepath = c_pipepath; + std::free(c_pipepath); + return pipepath; +} + +const std::string getAndCreateSocketPath(const std::string &basename) { + const std::string mumbleRuntimePath = getRuntimePath(); +#ifdef Q_OS_WIN + return basename; +#endif + if (mumbleRuntimePath.empty()) + return ""; + QString qMumbleRuntimePath = QString::fromUtf8(mumbleRuntimePath.data(), int(mumbleRuntimePath.size())); + QDir(qMumbleRuntimePath).mkpath("."); +#ifdef Q_OS_LINUX + std::string pipepath = mumbleRuntimePath + basename + "Socket"; +#else // MAC or BSD + const std::string pipepath = mumbleRuntimePath + "." + basename + "Socket"; +#endif + return pipepath; +} + +}; // namespace Mumble diff --git a/src/mumble/IPCUtils.h b/src/mumble/IPCUtils.h new file mode 100644 index 00000000000..1c682c1c95a --- /dev/null +++ b/src/mumble/IPCUtils.h @@ -0,0 +1,30 @@ +// Copyright 2021-2022 The Mumble Developers. All rights reserved. +// Use of this source code is governed by a BSD-style license +// that can be found in the LICENSE file at the root of the +// Mumble source tree or at . + +#ifndef MUMBLE_MUMBLE_IPCUTILS_H_ +#define MUMBLE_MUMBLE_IPCUTILS_H_ + +#include + +namespace Mumble { + +/** + * @returns The path to MumbleOverlayPipe + */ +const std::string getAndCreateOverlayPipePath(); + +/** + * @returns The path to MumbleSocket + */ +const std::string getAndCreateSocketPath(const std::string &); + +/** + * @returns The path where Mumble sets up MumbleOverlayPipe and MumbleSocket + */ +const std::string getRuntimePath(); + +}; // namespace Mumble + +#endif // MUMBLE_MUMBLE_IPCUTILS_H_ diff --git a/src/mumble/Overlay.cpp b/src/mumble/Overlay.cpp index 59bc5786c41..939484d1726 100644 --- a/src/mumble/Overlay.cpp +++ b/src/mumble/Overlay.cpp @@ -8,6 +8,7 @@ #include "Channel.h" #include "ClientUser.h" #include "Database.h" +#include "IPCUtils.h" #include "MainWindow.h" #include "OverlayClient.h" #include "OverlayText.h" @@ -238,36 +239,21 @@ void Overlay::createPipe() { // Allow anyone to access the pipe in order to communicate with the overlay qlsServer->setSocketOptions(QLocalServer::WorldAccessOption); - QString pipepath; -#ifdef Q_OS_WIN - pipepath = QLatin1String("MumbleOverlayPipe"); -#else - { - 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("."); - pipepath = mumbleRuntimeDir.absoluteFilePath(QLatin1String("MumbleOverlayPipe")); - } + const std::string pipepath = Mumble::getAndCreateOverlayPipePath(); + QString qPipepath = QString::fromUtf8(pipepath.data(), int(pipepath.size())); { - QFile f(pipepath); + QFile f(qPipepath); if (f.exists()) { - qWarning() << "Overlay: Removing old socket on" << pipepath; + qWarning() << "Overlay: Removing old socket on" << qPipepath; f.remove(); } } -#endif - if (!qlsServer->listen(pipepath)) { + if (!qlsServer->listen(qPipepath)) { QMessageBox::warning(nullptr, QLatin1String("Mumble"), tr("Failed to create communication with overlay at %2: %1. No overlay will be available.") - .arg(qlsServer->errorString().toHtmlEscaped(), pipepath.toHtmlEscaped()), + .arg(qlsServer->errorString().toHtmlEscaped(), qPipepath.toHtmlEscaped()), QMessageBox::Ok, QMessageBox::NoButton); } else { qWarning() << "Overlay: Listening on" << qlsServer->fullServerName(); diff --git a/src/mumble/SocketRPC.cpp b/src/mumble/SocketRPC.cpp index acf70e7927e..5b4b3c0dcac 100644 --- a/src/mumble/SocketRPC.cpp +++ b/src/mumble/SocketRPC.cpp @@ -7,6 +7,7 @@ #include "Channel.h" #include "ClientUser.h" +#include "IPCUtils.h" #include "MainWindow.h" #include "ServerHandler.h" #include "Global.h" @@ -229,34 +230,18 @@ void SocketRPCClient::processXml() { SocketRPC::SocketRPC(const QString &basename, QObject *p) : QObject(p) { qlsServer = new QLocalServer(this); - QString pipepath; + const std::string pipepath = Mumble::getAndCreateSocketPath(basename.toStdString()); + QString qPipepath = QString::fromUtf8(pipepath.data(), int(pipepath.size())); -#ifdef Q_OS_WIN - pipepath = basename; -#else { - 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("."); - pipepath = mumbleRuntimeDir.absoluteFilePath(basename + QLatin1String("Socket")); - } - - { - QFile f(pipepath); + QFile f(qPipepath); if (f.exists()) { - qWarning() << "SocketRPC: Removing old socket on" << pipepath; + qWarning() << "SocketRPC: Removing old socket on" << qPipepath; f.remove(); } } -#endif - if (!qlsServer->listen(pipepath)) { + if (!qlsServer->listen(qPipepath)) { qWarning() << "SocketRPC: Listen failed"; delete qlsServer; qlsServer = nullptr; @@ -275,27 +260,11 @@ void SocketRPC::newConnection() { } bool SocketRPC::send(const QString &basename, const QString &request, const QMap< QString, QVariant > ¶m) { - QString pipepath; - -#ifdef Q_OS_WIN - pipepath = basename; -#else - { - 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("."); - pipepath = mumbleRuntimeDir.absoluteFilePath(basename + QLatin1String("Socket")); - } -#endif + const std::string pipepath = Mumble::getAndCreateSocketPath(basename.toStdString()); + QString qPipepath = QString::fromUtf8(pipepath.data(), int(pipepath.size())); QLocalSocket qls; - qls.connectToServer(pipepath); + qls.connectToServer(qPipepath); if (!qls.waitForConnected(1000)) { return false; } @@ -329,4 +298,3 @@ bool SocketRPC::send(const QString &basename, const QString &request, const QMap return QVariant(succ.text()).toBool(); } - diff --git a/src/tests/OverlayTest/OverlayTest.cpp b/src/tests/OverlayTest/OverlayTest.cpp index 0eb59716323..bd834d3bb9c 100644 --- a/src/tests/OverlayTest/OverlayTest.cpp +++ b/src/tests/OverlayTest/OverlayTest.cpp @@ -8,6 +8,9 @@ */ #include "../../overlay/overlay.h" +extern "C" { +#include "../../overlay/ipc_utils.h" +} #include "SharedMemory.h" #include "Timer.h" @@ -15,17 +18,16 @@ #ifdef Q_OS_WIN # include "win.h" #else -# include +# include #endif #include #include #include -#include -#include #include - +#include +#include class OverlayWidget : public QWidget { Q_OBJECT @@ -98,22 +100,17 @@ void OverlayWidget::paintEvent(QPaintEvent *) { connect(qlsSocket, SIGNAL(readyRead()), this, SLOT(readyRead())); connect(qlsSocket, SIGNAL(error(QLocalSocket::LocalSocketError)), this, SLOT(error(QLocalSocket::LocalSocketError))); -#ifdef Q_OS_WIN - qlsSocket->connectToServer(QLatin1String("MumbleOverlayPipe")); -#else - 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/"); + + char *c_pipepath = getAndCreateOverlayPipePath__(); + if (c_pipepath == NULL) { + perror("Could not create MumbleOverlayPipe."); + return; } - QDir mumbleRuntimeDir = QDir(mumbleRuntimePath); - mumbleRuntimeDir.mkpath("."); - QString pipepath = mumbleRuntimeDir.absoluteFilePath(QLatin1String("MumbleOverlayPipe")); - qWarning() << "connectToServer(" << pipepath << ")"; - qlsSocket->connectToServer(pipepath); -#endif + const std::string pipepath = c_pipepath; + + QString qPipepath = QString::fromUtf8(pipepath.data(), int(pipepath.size())); + qWarning() << "connectToServer(" << qPipepath << ")"; + qlsSocket->connectToServer(qPipepath); } QPainter painter(this); @@ -219,12 +216,12 @@ void OverlayWidget::readyRead() { int ready = qlsSocket->bytesAvailable(); if (om.omh.iLength == -1) { - if ((size_t)ready < sizeof(OverlayMsgHeader)) + if ((size_t) ready < sizeof(OverlayMsgHeader)) break; else { qlsSocket->read(reinterpret_cast< char * >(om.headerbuffer), sizeof(OverlayMsgHeader)); if ((om.omh.uiMagic != OVERLAY_MAGIC_NUMBER) || (om.omh.iLength < 0) - || ((size_t)om.omh.iLength > sizeof(OverlayMsgShmem))) { + || ((size_t) om.omh.iLength > sizeof(OverlayMsgShmem))) { detach(); return; } @@ -267,8 +264,8 @@ void OverlayWidget::readyRead() { if (!smMem) break; - if (((omb->x + omb->w) > (unsigned int)img.width()) - || ((omb->y + omb->h) > (unsigned int)img.height())) + if (((omb->x + omb->w) > (unsigned int) img.width()) + || ((omb->y + omb->h) > (unsigned int) img.height())) break; From 04bc3aff2c085b28a23d4487a5b4b4730193f0ed Mon Sep 17 00:00:00 2001 From: Carlo Castoldi Date: Sun, 8 Oct 2023 23:08:44 +0200 Subject: [PATCH 5/6] CHANGE(ipc): ipc_utils now internally uses cwalk library --- .gitmodules | 3 ++ 3rdparty/cwalk | 1 + overlay/ipc_utils.c | 80 +++++++++++++++------------------------ overlay/ipc_utils.h | 5 +++ src/mumble/CMakeLists.txt | 10 +++++ 5 files changed, 49 insertions(+), 50 deletions(-) create mode 160000 3rdparty/cwalk diff --git a/.gitmodules b/.gitmodules index c19da4099cd..18a0104cfb1 100644 --- a/.gitmodules +++ b/.gitmodules @@ -25,3 +25,6 @@ [submodule "3rdparty/SPSCQueue"] path = 3rdparty/SPSCQueue url = https://github.com/rigtorp/SPSCQueue.git +[submodule "3rdparty/cwalk"] + path = 3rdparty/cwalk + url = https://github.com/likle/cwalk.git diff --git a/3rdparty/cwalk b/3rdparty/cwalk new file mode 160000 index 00000000000..cfe8282fce9 --- /dev/null +++ b/3rdparty/cwalk @@ -0,0 +1 @@ +Subproject commit cfe8282fce9dcf14cfabe53a253084ff967cfbed diff --git a/overlay/ipc_utils.c b/overlay/ipc_utils.c index 30d0b6736b9..061d8c6e9c2 100644 --- a/overlay/ipc_utils.c +++ b/overlay/ipc_utils.c @@ -4,6 +4,7 @@ // Mumble source tree or at . #include "ipc_utils.h" +#include #include #ifdef _WIN32 @@ -20,41 +21,23 @@ #endif char *getRuntimePath__() { - size_t n = 0; char *path = NULL; #ifdef __linux__ + char buffer[MUMBLE_MAX_PATH]; char *xdgRuntimeDir = getenv("XDG_RUNTIME_DIR"); - - if (xdgRuntimeDir != NULL) { - if (xdgRuntimeDir) - n += strlen(xdgRuntimeDir); - if (xdgRuntimeDir[(strlen(xdgRuntimeDir) - 1)] != '/') - n++; - n += strlen("mumble/"); - - if ((path = malloc(n + 1)) == NULL) - return path; - *path = '\0'; - - strcpy(path, xdgRuntimeDir); - if (xdgRuntimeDir[(strlen(xdgRuntimeDir) - 1)] != '/') - strcat(path, "/"); - strcat(path, "mumble/"); - } else { + if (xdgRuntimeDir == NULL || !xdgRuntimeDir) { char uid[10]; - n += strlen("/run/user//mumble/"); sprintf(uid, "%d", getuid()); - n += strlen(uid); - - if ((path = malloc(n + 1)) == NULL) - return path; - *path = '\0'; - - strcpy(path, "/run/user/"); - strcat(path, uid); - strcat(path, "/mumble/"); + xdgRuntimeDir = "/run/user/"; + cwk_path_join(xdgRuntimeDir, uid, buffer, sizeof(buffer)); } + size_t path_len = cwk_path_join(xdgRuntimeDir, "mumble", buffer, sizeof(buffer)); + // if (path_len != strlen(buffer)) + // buffer is too small. Result is truncated + if ((path = malloc(path_len)) == NULL) + return NULL; + strcpy(path, buffer); #elif defined(_WIN32) path = strdup(""); #else @@ -63,45 +46,42 @@ char *getRuntimePath__() { struct passwd *pwent = getpwuid(getuid()); if (pwent && pwent->pw_dir && pwent->pw_dir[0]) home = pwent->pw_dir; + else + return NULL; } - if (home == NULL) + if ((path = malloc(strlen(home))) == NULL) return NULL; - n += strlen(home); - if (home[(strlen(home) - 1)] != '/') - n++; - if ((path = malloc(n + 1)) == NULL) - return path; strcpy(path, home); - if (home[(strlen(home) - 1)] != '/') - strcat(path, "/"); #endif return path; } char *getAndCreateOverlayPipePath__() { - char *runtimePath = getRuntimePath__(); - char *path = NULL; + char buffer[MUMBLE_MAX_PATH]; + char *runtimePath = getRuntimePath__(); + char *overlapyPipeFile = NULL; + char *path = NULL; if (runtimePath == NULL) - return runtimePath; + return NULL; #if _WIN32 /* * on Windows we don't create the directory as getRuntimePath__() returns an empty string. - _mkdir(runtimePath); -*/ + * _mkdir(runtimePath); + */ #else mkdir(runtimePath, 0755); #endif - size_t n = 1; - n += strlen(runtimePath); - n += strlen("MumbleOverlayPipe"); - path = (char *) malloc(n + 1); - if (path == NULL) - return path; #if !defined __linux__ && !defined _WIN32 - strcat(path, "."); + overlapyPipeFile = ".MumbleOverlayPipe"; +#else + overlapyPipeFile = "MumbleOverlayPipe"; #endif - strcpy(path, runtimePath); - strcat(path, "MumbleOverlayPipe"); + size_t path_len = cwk_path_join(runtimePath, overlapyPipeFile, buffer, sizeof(buffer)); + // if (path_len != strlen(path)) + // path is too small. Result is truncated + if ((path = malloc(path_len)) == NULL) + return NULL; + strcpy(path, buffer); free(runtimePath); return path; } \ No newline at end of file diff --git a/overlay/ipc_utils.h b/overlay/ipc_utils.h index 2fc91d0cb33..a303bb3f35e 100644 --- a/overlay/ipc_utils.h +++ b/overlay/ipc_utils.h @@ -6,6 +6,11 @@ #ifndef MUMBLE_OVERLAY_IPC_UTILS_H__ #define MUMBLE_OVERLAY_IPC_UTILS_H__ +// can't trust POSIX's nor Window's PATH_MAX constants +// see: https://eklitzke.org/path-max-is-tricky +// https://stackoverflow.com/a/56385296 +const int MUMBLE_MAX_PATH = 1024; + char *getRuntimePath__(); char *getAndCreateOverlayPipePath__(); diff --git a/src/mumble/CMakeLists.txt b/src/mumble/CMakeLists.txt index ad07bda55c3..88001dd213a 100644 --- a/src/mumble/CMakeLists.txt +++ b/src/mumble/CMakeLists.txt @@ -26,6 +26,7 @@ option(bundled-speex "Build the included version of Speex instead of looking for option(rnnoise "Use RNNoise for machine learning noise reduction." ON) option(bundled-rnnoise "Build the included version of RNNoise instead of looking for one on the system." ${rnnoise}) option(bundled-json "Build the included version of nlohmann_json instead of looking for one on the system" ON) +option(bundled-cwalk "Build the included version of CWalk instead of looking for one on the system." ON) option(manual-plugin "Include the built-in \"manual\" positional audio plugin." ON) @@ -512,6 +513,15 @@ else() find_pkg("nlohmann_json" REQUIRED) endif() +if(bundled-cwalk) + add_subdirectory("${3RDPARTY_DIR}/cwalk" "${CMAKE_CURRENT_BINARY_DIR}/cwalk" EXCLUDE_FROM_ALL) + target_link_libraries(mumble_client_object_lib PUBLIC cwalk) + install_library(cwalk mumble_client) +else() + find_pkg(Cwalk REQUIRED) + target_link_libraries(mumble_client_object_lib PUBLIC cwalk) +endif() + target_link_libraries(mumble_client_object_lib PUBLIC nlohmann_json::nlohmann_json) find_pkg("SndFile;LibSndFile;sndfile" REQUIRED) From 98fab94e0637f9f3769f0d8819bc122a780bd79c Mon Sep 17 00:00:00 2001 From: Carlo Castoldi Date: Mon, 9 Oct 2023 13:18:02 +0200 Subject: [PATCH 6/6] CHANGE(ipc): cwalk is hard to compile for both 32bit and 64bit. Now using snprintf() --- CMakeLists.txt | 25 ++++++++++++++++ overlay/ipc_utils.c | 62 +++++++++++++++++++++++---------------- overlay/ipc_utils.h | 5 ---- overlay_gl/CMakeLists.txt | 12 ++++++-- src/mumble/CMakeLists.txt | 11 +------ 5 files changed, 71 insertions(+), 44 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 877cfe023ae..e5cd2ee5369 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,6 +98,8 @@ endif() option(lto "Enables link-time optimizations for release builds" ${LTO_DEFAULT}) +# option(bundled-cwalk "Build the included version of CWalk instead of looking for one on the system." ON) + include(compiler) include(os) @@ -165,6 +167,29 @@ if(client OR server) add_subdirectory(src) endif() +# if(client OR overlay) +# if(bundled-cwalk) +# add_subdirectory("${3RDPARTY_DIR}/cwalk" "${CMAKE_CURRENT_BINARY_DIR}/cwalk" EXCLUDE_FROM_ALL) +# 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 +# # installed. If we don't find it, we can assume it's not there but if we do find it, we still don't know. Thus we still print the +# # message about the 32bit target potentially failing due to missing g++-multilib. +# CHECK_INCLUDE_FILE("sys/cdefs.h" FOUND_CDEFS "-m32") +# if(NOT FOUND_CDEFS) +# message(FATAL_ERROR "Can't find the 32bit version of sys/cdefs.h - did you install g++-multilib?") +# else() +# message(STATUS "\nIf the 32 bit overlay library fails to compile, make sure the requirements are installed (\"g++-multilib\" package on Debian-based distributions).\n") +# endif() + + +# add_subdirectory("${3RDPARTY_DIR}/cwalk" "${CMAKE_CURRENT_BINARY_DIR}/cwalk_x86" EXCLUDE_FROM_ALL) +# set_target_properties(cwalk PROPERTIES COMPILE_OPTIONS "-m32" LINK_OPTIONS "-m32") +# endif() +# else() +# find_pkg(Cwalk REQUIRED) +# endif() +# endif() + if(g15 AND WIN32) add_subdirectory("helpers/g15helper") endif() diff --git a/overlay/ipc_utils.c b/overlay/ipc_utils.c index 061d8c6e9c2..d235b0543b5 100644 --- a/overlay/ipc_utils.c +++ b/overlay/ipc_utils.c @@ -4,7 +4,7 @@ // Mumble source tree or at . #include "ipc_utils.h" -#include +// #include #include #ifdef _WIN32 @@ -20,26 +20,28 @@ # include #endif +// can't trust POSIX's nor Window's PATH_MAX constants +// see: https://eklitzke.org/path-max-is-tricky +// https://stackoverflow.com/a/56385296 +#define MUMBLE_MAX_PATH 1024 + char *getRuntimePath__() { + char buffer[MUMBLE_MAX_PATH]; char *path = NULL; -#ifdef __linux__ - char buffer[MUMBLE_MAX_PATH]; +#ifdef _WIN32 + path = strdup("\0"); +#elif __linux__ char *xdgRuntimeDir = getenv("XDG_RUNTIME_DIR"); if (xdgRuntimeDir == NULL || !xdgRuntimeDir) { - char uid[10]; - sprintf(uid, "%d", getuid()); + // char uid[10]; + // sprintf(uid, "%d", getuid()); xdgRuntimeDir = "/run/user/"; - cwk_path_join(xdgRuntimeDir, uid, buffer, sizeof(buffer)); + // cwk_path_join(xdgRuntimeDir, uid, buffer, sizeof(buffer)); + snprintf(buffer, sizeof(buffer), "%s/%d", xdgRuntimeDir, getuid()); } - size_t path_len = cwk_path_join(xdgRuntimeDir, "mumble", buffer, sizeof(buffer)); - // if (path_len != strlen(buffer)) - // buffer is too small. Result is truncated - if ((path = malloc(path_len)) == NULL) - return NULL; - strcpy(path, buffer); -#elif defined(_WIN32) - path = strdup(""); + // size_t path_len = cwk_path_join(xdgRuntimeDir, "mumble", buffer, sizeof(buffer)); + int path_len = snprintf(buffer, sizeof(buffer), "%s/mumble/", xdgRuntimeDir); #else char *home = getenv("HOME"); if (home == NULL) { @@ -49,20 +51,32 @@ char *getRuntimePath__() { else return NULL; } - if ((path = malloc(strlen(home))) == NULL) + if ((path = malloc(strlen(home) + 1)) == NULL) + return NULL; + int path_len = snprintf(buffer, sizeof(buffer), "%s/", home); +#endif +#if !defined _WIN32 + // if (path_len != strlen(buffer)) + // buffer is too small. Result is truncated + if ((path = malloc(path_len + 1)) == NULL) return NULL; - strcpy(path, home); + strcpy(path, buffer); #endif return path; } char *getAndCreateOverlayPipePath__() { char buffer[MUMBLE_MAX_PATH]; - char *runtimePath = getRuntimePath__(); - char *overlapyPipeFile = NULL; + char *overlapyPipeFile = "MumbleOverlayPipe"; char *path = NULL; + char *runtimePath = getRuntimePath__(); if (runtimePath == NULL) return NULL; +#if !defined __linux__ && !defined _WIN32 + char *path_template = "%s.%s"; +#else + char *path_template = "%s%s"; +#endif #if _WIN32 /* * on Windows we don't create the directory as getRuntimePath__() returns an empty string. @@ -71,17 +85,13 @@ char *getAndCreateOverlayPipePath__() { #else mkdir(runtimePath, 0755); #endif -#if !defined __linux__ && !defined _WIN32 - overlapyPipeFile = ".MumbleOverlayPipe"; -#else - overlapyPipeFile = "MumbleOverlayPipe"; -#endif - size_t path_len = cwk_path_join(runtimePath, overlapyPipeFile, buffer, sizeof(buffer)); + // size_t path_len = cwk_path_join(runtimePath, overlapyPipeFile, buffer, sizeof(buffer)); + int path_len = snprintf(buffer, sizeof(buffer), path_template, runtimePath, overlapyPipeFile); // if (path_len != strlen(path)) // path is too small. Result is truncated - if ((path = malloc(path_len)) == NULL) + if ((path = malloc(path_len + 1)) == NULL) return NULL; strcpy(path, buffer); free(runtimePath); return path; -} \ No newline at end of file +} diff --git a/overlay/ipc_utils.h b/overlay/ipc_utils.h index a303bb3f35e..2fc91d0cb33 100644 --- a/overlay/ipc_utils.h +++ b/overlay/ipc_utils.h @@ -6,11 +6,6 @@ #ifndef MUMBLE_OVERLAY_IPC_UTILS_H__ #define MUMBLE_OVERLAY_IPC_UTILS_H__ -// can't trust POSIX's nor Window's PATH_MAX constants -// see: https://eklitzke.org/path-max-is-tricky -// https://stackoverflow.com/a/56385296 -const int MUMBLE_MAX_PATH = 1024; - char *getRuntimePath__(); char *getAndCreateOverlayPipePath__(); diff --git a/overlay_gl/CMakeLists.txt b/overlay_gl/CMakeLists.txt index 9951c70c22d..0bf4ec269d1 100644 --- a/overlay_gl/CMakeLists.txt +++ b/overlay_gl/CMakeLists.txt @@ -13,7 +13,13 @@ if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64" OR ${CMAKE_SYSTEM_PROCESSOR} STRE endif() endif() -add_library(overlay_gl SHARED "overlay.c") +set(OVERLAY_SOURCES + "${CMAKE_SOURCE_DIR}/overlay/ipc_utils.c" + "overlay.c" +) +add_library(overlay_gl SHARED ${OVERLAY_SOURCES}) + +# target_link_libraries(overlay_gl PRIVATE cwalk) set_target_properties(overlay_gl PROPERTIES @@ -46,13 +52,13 @@ if(NOT APPLE) else() message(STATUS "\nIf the 32 bit overlay library fails to compile, make sure the requirements are installed (\"g++-multilib\" package on Debian-based distributions).\n") endif() - set_target_properties(overlay_gl PROPERTIES OUTPUT_NAME "mumbleoverlay.x86_64" ) - add_library(overlay_gl_x86 SHARED "overlay.c") + add_library(overlay_gl_x86 SHARED ${OVERLAY_SOURCES}) + # target_link_libraries(overlay_gl_x86 PRIVATE cwalk) target_compile_definitions(overlay_gl_x86 PRIVATE diff --git a/src/mumble/CMakeLists.txt b/src/mumble/CMakeLists.txt index 88001dd213a..5b62e71458f 100644 --- a/src/mumble/CMakeLists.txt +++ b/src/mumble/CMakeLists.txt @@ -26,7 +26,6 @@ option(bundled-speex "Build the included version of Speex instead of looking for option(rnnoise "Use RNNoise for machine learning noise reduction." ON) option(bundled-rnnoise "Build the included version of RNNoise instead of looking for one on the system." ${rnnoise}) option(bundled-json "Build the included version of nlohmann_json instead of looking for one on the system" ON) -option(bundled-cwalk "Build the included version of CWalk instead of looking for one on the system." ON) option(manual-plugin "Include the built-in \"manual\" positional audio plugin." ON) @@ -513,15 +512,7 @@ else() find_pkg("nlohmann_json" REQUIRED) endif() -if(bundled-cwalk) - add_subdirectory("${3RDPARTY_DIR}/cwalk" "${CMAKE_CURRENT_BINARY_DIR}/cwalk" EXCLUDE_FROM_ALL) - target_link_libraries(mumble_client_object_lib PUBLIC cwalk) - install_library(cwalk mumble_client) -else() - find_pkg(Cwalk REQUIRED) - target_link_libraries(mumble_client_object_lib PUBLIC cwalk) -endif() - +# target_link_libraries(mumble_client_object_lib PUBLIC cwalk) target_link_libraries(mumble_client_object_lib PUBLIC nlohmann_json::nlohmann_json) find_pkg("SndFile;LibSndFile;sndfile" REQUIRED)