From e7cbeba1406004d0dae63178c3eeefddc97e8785 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 31 Aug 2024 14:52:55 -0700 Subject: [PATCH] pty: reset all signals after fork --- src/crash/sentry.zig | 6 ++++-- src/pty.zig | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/crash/sentry.zig b/src/crash/sentry.zig index 4e244d71f..fbb508f8b 100644 --- a/src/crash/sentry.zig +++ b/src/crash/sentry.zig @@ -78,8 +78,10 @@ fn initThread(gpa: Allocator) !void { cache_dir.len, ); - // Debug logging for Sentry - sentry.c.sentry_options_set_debug(opts, @intFromBool(true)); + if (comptime builtin.mode == .Debug) { + // Debug logging for Sentry + sentry.c.sentry_options_set_debug(opts, @intFromBool(true)); + } // Initialize if (sentry.c.sentry_init(opts) != 0) return error.SentryInitFailed; diff --git a/src/pty.zig b/src/pty.zig index 0bb1aff67..47fd239c4 100644 --- a/src/pty.zig +++ b/src/pty.zig @@ -137,6 +137,25 @@ const PosixPty = struct { /// This should be called prior to exec in the forked child process /// in order to setup the tty properly. pub fn childPreExec(self: Pty) !void { + // Reset our signals + var sa: posix.Sigaction = .{ + .handler = .{ .handler = posix.SIG.DFL }, + .mask = posix.empty_sigset, + .flags = 0, + }; + try posix.sigaction(posix.SIG.ABRT, &sa, null); + try posix.sigaction(posix.SIG.ALRM, &sa, null); + try posix.sigaction(posix.SIG.BUS, &sa, null); + try posix.sigaction(posix.SIG.CHLD, &sa, null); + try posix.sigaction(posix.SIG.FPE, &sa, null); + try posix.sigaction(posix.SIG.HUP, &sa, null); + try posix.sigaction(posix.SIG.ILL, &sa, null); + try posix.sigaction(posix.SIG.INT, &sa, null); + try posix.sigaction(posix.SIG.SEGV, &sa, null); + try posix.sigaction(posix.SIG.TRAP, &sa, null); + try posix.sigaction(posix.SIG.TERM, &sa, null); + try posix.sigaction(posix.SIG.QUIT, &sa, null); + // Create a new process group if (setsid() < 0) return error.ProcessGroupFailed;