Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POSIX named semaphores are broken for sandboxed Mac apps #232

Open
JNMSFT opened this issue Sep 26, 2024 · 4 comments
Open

POSIX named semaphores are broken for sandboxed Mac apps #232

JNMSFT opened this issue Sep 26, 2024 · 4 comments

Comments

@JNMSFT
Copy link

JNMSFT commented Sep 26, 2024

The code below in interprocess/sync/posix/semaphore_wrapper.hpp is broken for sandboxed Mac apps:

   std::string name;
   #ifndef BOOST_INTERPROCESS_FILESYSTEM_BASED_POSIX_SEMAPHORES
   add_leading_slash(origname, name);
   #else
   create_shared_dir_cleaning_old_and_get_filepath(origname, name);
   #endif

For sandboxed apps, the name of the mutex must be < 32 characters and must be prefixed with an App Group the app is entitled to. For instance, "UBF9AAA6G9.Foo/Bar" is a valid mutex name, but "/UBF9AAA6G9.Foo/Bar" is not. However, add_leading_slash always prepends a slash, which causes sem_open to fail if the app is sandboxed.

Is there an existing preprocessor macro I can define to skip this behavior? It didn't look like it from a quick read of the code.

@igaztanaga
Copy link
Member

I don't know about MacOs sandboxed apps, but searching online it seems that we can detect a sandboxed application if the environment variable APP_SANDBOX_CONTAINER_ID exists. Can you confirm this? I don't know if the app group id can be obtained and Interprocess can just figure out the correct name...

@JNMSFT
Copy link
Author

JNMSFT commented Oct 14, 2024 via email

@igaztanaga
Copy link
Member

I don't see any fully compilable example online for the purpose (what is that " code signing entitlements" stuff?) and I don't have access to a MacOs machine so I definitely would need a patch from someone that detects the sandboxed state under apple or something and that avoids adding the first slash in that case:

   #ifndef BOOST_INTERPROCESS_FILESYSTEM_BASED_POSIX_SEMAPHORES
   #ifdef __APPLE__
   if (!is_sandboxed_app()
      add_leading_slash(origname, name);
   #else
      add_leading_slash(origname, name);
   #endif
   #else
   create_shared_dir_cleaning_old_and_get_filepath(origname, name);
   #endif

But I imagine we'll have the same problem with shared memory (shm_open) and other utilities.

@JNMSFT
Copy link
Author

JNMSFT commented Oct 15, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants