From 6d319389299b6557e004070ea057e344e6532981 Mon Sep 17 00:00:00 2001 From: Bart Ribbers Date: Tue, 31 Mar 2020 12:46:03 +0200 Subject: [PATCH] Fix Musl incompabilities Without including libgen.h, basename is not available on Musl. sourceArgv[0] is a const char* which can not be converted to char*, so cast it instead RTLD_DEEPBIND is not available on Musl, only on glibc (since 2.3.4) ARG_MAX is already defined so it has to be renamed Even according to glibc itself, should never be included directly and should, which is already done anyway --- src/invoker/invoker.c | 1 - src/launcherlib/booster.cpp | 8 ++++++-- src/launcherlib/connection.cpp | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/invoker/invoker.c b/src/invoker/invoker.c index ba81f7b..1a806d9 100644 --- a/src/invoker/invoker.c +++ b/src/invoker/invoker.c @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include diff --git a/src/launcherlib/booster.cpp b/src/launcherlib/booster.cpp index 235f2a0..3495503 100644 --- a/src/launcherlib/booster.cpp +++ b/src/launcherlib/booster.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #include "coverage.h" @@ -327,9 +328,12 @@ void Booster::renameProcess(int parentArgc, char** parentArgv, } // Set the process name using prctl, 'killall' and 'top' use it - if ( prctl(PR_SET_NAME, basename(sourceArgv[0])) == -1 ) + char* processName = strdup(sourceArgv[0]); + if ( prctl(PR_SET_NAME, basename(processName)) == -1 ) Logger::logError("Booster: on set new process name: %s ", strerror(errno)); + std::free(processName); + setenv("_", sourceArgv[0], true); } } @@ -583,7 +587,7 @@ void* Booster::loadMain() else dlopenFlags |= RTLD_LOCAL; -#if (PLATFORM_ID == Linux) +#if (PLATFORM_ID == Linux) && defined(__GLIBC__) if (m_appData->dlopenDeep()) dlopenFlags |= RTLD_DEEPBIND; #endif diff --git a/src/launcherlib/connection.cpp b/src/launcherlib/connection.cpp index b5dd89d..71bd405 100644 --- a/src/launcherlib/connection.cpp +++ b/src/launcherlib/connection.cpp @@ -281,8 +281,8 @@ bool Connection::receiveArgs() { // Get argc recvMsg(&m_argc); - const uint32_t ARG_MAX = 1024; - if (m_argc > 0 && m_argc < ARG_MAX) + const uint32_t argMax = 1024; + if (m_argc > 0 && m_argc < argMax) { // Reserve memory for argv m_argv = new const char * [m_argc];