From 91bc21c4895764c4fe9e39a4bcc76e6484ff5188 Mon Sep 17 00:00:00 2001 From: def Date: Tue, 30 Aug 2022 10:09:35 +0200 Subject: [PATCH] No need for lengthy semaphore names on macOS, pointer address is enough Also check on init failure and at least log, same as on UNIX --- src/base/system.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/base/system.cpp b/src/base/system.cpp index 0a4fe1cbf..97de85ee6 100644 --- a/src/base/system.cpp +++ b/src/base/system.cpp @@ -905,8 +905,10 @@ void sphore_destroy(SEMAPHORE *sem) { CloseHandle((HANDLE)*sem); } void sphore_init(SEMAPHORE *sem) { char aBuf[64]; - str_format(aBuf, sizeof(aBuf), "/%d-ddnet.tw-%p", pid(), (void *)sem); + str_format(aBuf, sizeof(aBuf), "%p", (void *)sem); *sem = sem_open(aBuf, O_CREAT | O_EXCL, S_IRWXU | S_IRWXG, 0); + if(*sem == SEM_FAILED) + dbg_msg("sphore", "init failed: %d", errno); } void sphore_wait(SEMAPHORE *sem) { sem_wait(*sem); } void sphore_signal(SEMAPHORE *sem) { sem_post(*sem); } @@ -914,7 +916,7 @@ void sphore_destroy(SEMAPHORE *sem) { char aBuf[64]; sem_close(*sem); - str_format(aBuf, sizeof(aBuf), "/%d-ddnet.tw-%p", pid(), (void *)sem); + str_format(aBuf, sizeof(aBuf), "%p", (void *)sem); sem_unlink(aBuf); } #elif defined(CONF_FAMILY_UNIX)