From 213128e82a18aebdaf0f33829d69e27f2458b860 Mon Sep 17 00:00:00 2001 From: Eli Mallon Date: Tue, 13 Sep 2022 15:39:17 +0200 Subject: [PATCH] lib/shared_memory: truncate semaphore length on macos --- lib/defines.h | 8 +++++++- lib/shared_memory.cpp | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/defines.h b/lib/defines.h index d08d1d04..037e2659 100644 --- a/lib/defines.h +++ b/lib/defines.h @@ -229,7 +229,7 @@ static inline void show_stackframe(){} #define SEM_LIVE "/MstLIVE%s" //%s stream name #define SEM_INPUT "/MstInpt%s" //%s stream name #define SEM_TRACKLIST "/MstTRKS%s" //%s stream name -#define SEM_SESSION "MstSess%s" +#define SEM_SESSION "/MstSess%s" #define SEM_SESSCACHE "/MstSessCacheLock" #define SESS_TIMEOUT 600 // Session timeout in seconds #define SHM_CAPA "MstCapa" @@ -243,6 +243,12 @@ static inline void show_stackframe(){} #define SHM_SESSIONS_ITEM 165 // 4 byte crc, 100b streamname, 20b connector, 40b host, 1b sync #define SHM_SESSIONS_SIZE 5248000 // 5MiB = almost 32k sessions +#if defined(__APPLE__) +#define IPC_MAX_LEN 30 // macos allows a maximum of 31, including terminating null +#else +#define IPC_MAX_LEN 250 // most other implementation a maximum of 251, including terminating null +#endif + #define SHM_STREAM_ENCRYPT "MstCRYP%s" //%s stream name #define SIMUL_TRACKS 40 diff --git a/lib/shared_memory.cpp b/lib/shared_memory.cpp index 0cc78f19..fc1e838c 100644 --- a/lib/shared_memory.cpp +++ b/lib/shared_memory.cpp @@ -75,8 +75,14 @@ namespace IPC{ ///\param mode The mode in which to create the semaphore, if O_CREAT is given in oflag, ignored /// otherwise \param value The initial value of the semaphore if O_CREAT is given in oflag, /// ignored otherwise - void semaphore::open(const char *name, int oflag, mode_t mode, unsigned int value, bool noWait){ + void semaphore::open(const char *sname, int oflag, mode_t mode, unsigned int value, bool noWait){ close(); + char *name = (char*)sname; + if (strlen(sname) >= IPC_MAX_LEN) { + name = (char*)malloc(IPC_MAX_LEN + 1); + memcpy(name, sname, IPC_MAX_LEN); + name[IPC_MAX_LEN] = 0; + } int timer = 0; while (!(*this) && timer++ < 10){ #if defined(__CYGWIN__) || defined(_WIN32)