Hello,
For educational purpose, I try to use a POSIX semaphore sem_t instead of a dispatch_semaphore_t in a sandbox macOS Obj-C app.
When using sandbox, the semaphore code creation :
sem_t * _unixSemaphore;
char nameSemaphore[64] = {0};
snprintf(nameSemaphore, 22, "/UnixSemaphore_sample");
_unixSemaphore = sem_open(nameSemaphore, O_CREAT, 0644, 0);
fails, receiving SEM_FAILED and the errno is 78 (not implemented)
However, the sem_t _unixSemaphore is created and works fine when I disable sandbox I my entitlements.
Is there a way to fix this?
Thank you in advance
Jean Marie
This worked for me:
-
Using Xcode 15.4 on macOS 14.4.1, I created a new test project from the macOS > App template.
-
In Signing & Capabilities, I added the App Groups capability with an
SKMME9E2Y8.Test756420
entry, whereSKMME9E2Y8
is my Team ID. -
I added a button wired up to this code:
- (IBAction)testAction:(id)sender { fprintf(stderr, "will open\n"); sem_t * sem = sem_open("SKMME9E2Y8.Test756420/MySem", O_CREAT, DEFFILEMODE, 0); if (sem == SEM_FAILED) { int err = errno; fprintf(stderr, "did not open, err: %d\n", err); return; } fprintf(stderr, "did open\n"); (void) sem_close(sem); }
-
I ran the app and clicked the button.
It printed:
will open
did open
I then you’re missed my use of slash (/
) in the GGG/NNN
in my earlier post.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"