Skip to content

Commit

Permalink
CHANGE(ipc): cwalk is hard to compile for both 32bit and 64bit. Now u…
Browse files Browse the repository at this point in the history
…sing snprintf()
  • Loading branch information
carlocastoldi committed Oct 9, 2023
1 parent 04bc3af commit 98fab94
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 44 deletions.
25 changes: 25 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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()
Expand Down
62 changes: 36 additions & 26 deletions overlay/ipc_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Mumble source tree or at <https://www.mumble.info/LICENSE>.

#include "ipc_utils.h"
#include <cwalk.h>
// #include <cwalk.h>
#include <string.h>

#ifdef _WIN32
Expand All @@ -20,26 +20,28 @@
# include <unistd.h>
#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) {
Expand All @@ -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.
Expand All @@ -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;
}
}
5 changes: 0 additions & 5 deletions overlay/ipc_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__();
Expand Down
12 changes: 9 additions & 3 deletions overlay_gl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 1 addition & 10 deletions src/mumble/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

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

0 comments on commit 98fab94

Please sign in to comment.