Skip to content

fix(native): replace sandbox-incompatible IPC primitives on macOS#1644

Merged
mujacica merged 7 commits intomasterfrom
fix/macos-app-sandbox-ipc
Apr 14, 2026
Merged

fix(native): replace sandbox-incompatible IPC primitives on macOS#1644
mujacica merged 7 commits intomasterfrom
fix/macos-app-sandbox-ipc

Conversation

@mujacica
Copy link
Copy Markdown
Contributor

macOS App Sandbox blocks sem_open(), shm_open(), and fork() in sandboxed apps, causing the native backend to fail during init.

  • Replace sem_open/sem_wait with pthread_mutex_t for IPC synchronization
  • Replace shm_open with file-backed mmap using $TMPDIR (sandbox-safe)
  • Replace fork+exec with posix_spawn using POSIX_SPAWN_CLOEXEC_DEFAULT and explicit fd inheritance via posix_spawn_file_actions_addinherit_np
  • Pass shm_fd to daemon via posix_spawn instead of reopening by name
  • Add macOS App Sandbox integration tests verifying init, crash capture, minidump generation, and native stacktraces inside a sandboxed .app

mujacica and others added 3 commits April 14, 2026 11:26
macOS App Sandbox blocks sem_open(), shm_open(), and fork() in
sandboxed apps, causing the native backend to fail during init.

- Replace sem_open/sem_wait with pthread_mutex_t for IPC synchronization
- Replace shm_open with file-backed mmap using $TMPDIR (sandbox-safe)
- Replace fork+exec with posix_spawn using POSIX_SPAWN_CLOEXEC_DEFAULT
  and explicit fd inheritance via posix_spawn_file_actions_addinherit_np
- Pass shm_fd to daemon via posix_spawn instead of reopening by name
- Add macOS App Sandbox integration tests verifying init, crash capture,
  minidump generation, and native stacktraces inside a sandboxed .app

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The mutex is only used on Windows and Linux. On macOS,
g_ipc_sync_mutex is used instead, so the unguarded declaration
caused -Werror,-Wunused-variable on macOS CI builds.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mujacica mujacica marked this pull request as ready for review April 14, 2026 11:26
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Autofix Details

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Signal handler extracts first dash instead of last
    • Removed the break statement in the loop so it continues to find the last dash, matching the strrchr behavior in sentry_backend_native.c

Create PR

Or push these changes by commenting:

@cursor push cc21ef7b97
Preview (cc21ef7b97)
diff --git a/src/backends/native/sentry_crash_handler.c b/src/backends/native/sentry_crash_handler.c
--- a/src/backends/native/sentry_crash_handler.c
+++ b/src/backends/native/sentry_crash_handler.c
@@ -705,7 +705,6 @@
         for (const char *p = shm_id_src; *p; p++) {
             if (*p == '-') {
                 shm_id = p + 1;
-                break;
             }
         }

This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

The loop had a `break` that stopped at the first '-', which worked
for Linux's "/s-{id}" but gave "shm-{id}" on macOS's
"{tmpdir}/.sentry-shm-{id}". Removing the break lets it find the
last hyphen and extract just the hex ID.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
POSIX_SPAWN_CLOEXEC_DEFAULT closes all fds including stdin/stdout/
stderr. Without valid std fds, the daemon's fopen() for the log file
would get fd 0, which is then destroyed by the daemon's own
close(STDIN_FILENO). Pre-opening /dev/null on fds 0-2 via spawn
file actions ensures the log file gets a safe fd number.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
If the caller closed stdin/stdout/stderr before sentry_init(), the
IPC pipe/shm fds could land on fd 0/1/2. The addopen for /dev/null
would then overwrite them. Now we skip opening /dev/null on any fd
that's already used by an IPC descriptor.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 011aced. Configure here.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mujacica mujacica requested a review from jpnurmi April 14, 2026 12:49
@mujacica mujacica merged commit 2a6ec9d into master Apr 14, 2026
59 checks passed
@mujacica mujacica deleted the fix/macos-app-sandbox-ipc branch April 14, 2026 13:22
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

Successfully merging this pull request may close these issues.

2 participants