lib/shared_memory: truncate semaphore length on macos

This commit is contained in:
Eli Mallon 2022-09-13 15:39:17 +02:00 committed by Thulinma
parent 7a4ac15fcf
commit 213128e82a
2 changed files with 14 additions and 2 deletions

View file

@ -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

View file

@ -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)