Skip to content

Commit da213ba

Browse files
committed
Remove unused handler_path from shared memory
The handler_path field in sentry_crash_context_t was being written to shared memory by the parent process but was never read by the daemon process. The daemon only uses the handler_path parameter passed to sentry__crash_daemon_start(). This change: - Removes the handler_path field from sentry_crash_context_t, saving SENTRY_CRASH_MAX_PATH bytes (4096 on Linux, 260 on Windows) - Passes options->handler_path->path directly to the daemon start function instead of storing it in shared memory first - Updates tests to reflect the simplified behavior Unlike ca_certs, proxy, and user_agent (which the daemon reads from shared memory in init_daemon), handler_path is now passed directly where it's actually needed.
1 parent 6a57a35 commit da213ba

File tree

3 files changed

+11
-44
lines changed

3 files changed

+11
-44
lines changed

src/backends/native/sentry_crash_context.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@ typedef struct {
284284
char ca_certs[SENTRY_CRASH_MAX_PATH]; // CA certificates file path for SSL
285285
char proxy[SENTRY_CRASH_MAX_PATH]; // HTTP proxy URL
286286
char user_agent[256]; // User-Agent header for HTTP requests
287-
char handler_path[SENTRY_CRASH_MAX_PATH]; // Path to sentry-crash executable
288287

289288
// Minidump output path (filled by daemon)
290289
char minidump_path[SENTRY_CRASH_MAX_PATH];

src/backends/sentry_backend_native.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -234,18 +234,6 @@ native_backend_startup(
234234
#endif
235235
}
236236

237-
// Store handler path for daemon executable lookup
238-
if (options->handler_path) {
239-
#ifdef _WIN32
240-
strncpy_s(ctx->handler_path, sizeof(ctx->handler_path),
241-
options->handler_path->path, _TRUNCATE);
242-
#else
243-
strncpy(ctx->handler_path, options->handler_path->path,
244-
sizeof(ctx->handler_path) - 1);
245-
ctx->handler_path[sizeof(ctx->handler_path) - 1] = '\0';
246-
#endif
247-
}
248-
249237
state->event_path = sentry__path_join_str(run_path, "__sentry-event");
250238
state->breadcrumb1_path
251239
= sentry__path_join_str(run_path, "__sentry-breadcrumb1");
@@ -330,9 +318,8 @@ native_backend_startup(
330318
#else
331319
// Other platforms: Use out-of-process daemon
332320
// Pass the notification handles (eventfd/pipe on Unix, events on Windows)
333-
// handler_path from crash context (empty string if not set by user)
334321
const char *daemon_handler_path
335-
= ctx->handler_path[0] != '\0' ? ctx->handler_path : NULL;
322+
= options->handler_path ? options->handler_path->path : NULL;
336323
# if defined(SENTRY_PLATFORM_LINUX) || defined(SENTRY_PLATFORM_ANDROID)
337324
uint64_t tid = (uint64_t)pthread_self();
338325
state->daemon_pid = sentry__crash_daemon_start(getpid(), tid,

tests/unit/test_native_backend.c

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -357,18 +357,11 @@ SENTRY_TEST(crash_context_transport_fields)
357357
ctx.user_agent[sizeof(ctx.user_agent) - 1] = '\0';
358358
TEST_CHECK_STRING_EQUAL(ctx.user_agent, test_ua);
359359

360-
// Verify handler_path field exists and can hold a typical path
361-
const char *test_handler = "/usr/local/bin/sentry-crash";
362-
strncpy(ctx.handler_path, test_handler, sizeof(ctx.handler_path) - 1);
363-
ctx.handler_path[sizeof(ctx.handler_path) - 1] = '\0';
364-
TEST_CHECK_STRING_EQUAL(ctx.handler_path, test_handler);
365-
366360
// Verify fields are zero-initialized when memset to 0
367361
memset(&ctx, 0, sizeof(ctx));
368362
TEST_CHECK(ctx.ca_certs[0] == '\0');
369363
TEST_CHECK(ctx.proxy[0] == '\0');
370364
TEST_CHECK(ctx.user_agent[0] == '\0');
371-
TEST_CHECK(ctx.handler_path[0] == '\0');
372365
#else
373366
SKIP_TEST();
374367
#endif
@@ -425,7 +418,10 @@ SENTRY_TEST(crash_context_options_propagation)
425418
}
426419

427420
/**
428-
* Test that handler_path option is propagated to crash context
421+
* Test that handler_path option is set correctly in options.
422+
* Note: handler_path is now passed directly to the daemon start function
423+
* instead of being stored in shared memory, since the daemon never reads
424+
* it from shared memory.
429425
*/
430426
SENTRY_TEST(crash_context_handler_path_propagation)
431427
{
@@ -435,25 +431,15 @@ SENTRY_TEST(crash_context_handler_path_propagation)
435431
// Set handler path
436432
sentry_options_set_handler_path(options, "/opt/sentry/sentry-crash");
437433

438-
// Simulate what native_backend_startup does
439-
sentry_crash_context_t ctx;
440-
memset(&ctx, 0, sizeof(ctx));
441-
442-
if (options->handler_path) {
443-
strncpy(ctx.handler_path, options->handler_path->path,
444-
sizeof(ctx.handler_path) - 1);
445-
ctx.handler_path[sizeof(ctx.handler_path) - 1] = '\0';
446-
}
447-
448-
TEST_CHECK_STRING_EQUAL(ctx.handler_path, "/opt/sentry/sentry-crash");
434+
// Verify handler_path option is set correctly
435+
TEST_ASSERT(!!options->handler_path);
436+
TEST_CHECK_STRING_EQUAL(
437+
options->handler_path->path, "/opt/sentry/sentry-crash");
449438

450-
// Without handler_path set, field should remain empty
439+
// Without handler_path set, it should be NULL
451440
sentry_options_t *options2 = sentry_options_new();
452441
TEST_ASSERT(!!options2);
453-
sentry_crash_context_t ctx2;
454-
memset(&ctx2, 0, sizeof(ctx2));
455-
// Don't set handler_path - verify it stays empty
456-
TEST_CHECK(ctx2.handler_path[0] == '\0');
442+
TEST_CHECK(options2->handler_path == NULL);
457443

458444
sentry_options_free(options);
459445
sentry_options_free(options2);
@@ -481,15 +467,10 @@ SENTRY_TEST(crash_context_null_options)
481467
if (options->proxy) {
482468
strncpy(ctx.proxy, options->proxy, sizeof(ctx.proxy) - 1);
483469
}
484-
if (options->handler_path) {
485-
strncpy(ctx.handler_path, options->handler_path->path,
486-
sizeof(ctx.handler_path) - 1);
487-
}
488470

489471
// All should remain empty (zero-initialized)
490472
TEST_CHECK(ctx.ca_certs[0] == '\0');
491473
TEST_CHECK(ctx.proxy[0] == '\0');
492-
TEST_CHECK(ctx.handler_path[0] == '\0');
493474

494475
sentry_options_free(options);
495476
#else

0 commit comments

Comments
 (0)