aboutsummaryrefslogtreecommitdiff
path: root/lib/std/start.zig
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2025-03-30 15:13:41 -0400
committerAndrew Kelley <andrew@ziglang.org>2025-10-29 06:20:48 -0700
commit08b609a79ff151e747c6b860c90b634daaa68f1c (patch)
tree2ac9a3ac308bd53125ef1770e9002c8274f2e734 /lib/std/start.zig
parent5041c9ad9cbf479e62416cd06ef8a178f3467127 (diff)
downloadzig-08b609a79ff151e747c6b860c90b634daaa68f1c.tar.gz
zig-08b609a79ff151e747c6b860c90b634daaa68f1c.zip
Io: implement sleep and fix cancel bugs
Diffstat (limited to 'lib/std/start.zig')
-rw-r--r--lib/std/start.zig34
1 files changed, 16 insertions, 18 deletions
diff --git a/lib/std/start.zig b/lib/std/start.zig
index 69207e690d..09c1f3b5c4 100644
--- a/lib/std/start.zig
+++ b/lib/std/start.zig
@@ -651,8 +651,8 @@ inline fn callMainWithArgs(argc: usize, argv: [*][*:0]u8, envp: [][*:0]u8) u8 {
std.os.argv = argv[0..argc];
std.os.environ = envp;
+ maybeIgnoreSignals();
std.debug.maybeEnableSegfaultHandler();
- maybeIgnoreSigpipe();
return callMain();
}
@@ -757,8 +757,8 @@ pub fn call_wWinMain() std.os.windows.INT {
return root.wWinMain(hInstance, null, lpCmdLine, nCmdShow);
}
-fn maybeIgnoreSigpipe() void {
- const have_sigpipe_support = switch (builtin.os.tag) {
+fn maybeIgnoreSignals() void {
+ switch (builtin.os.tag) {
.linux,
.plan9,
.illumos,
@@ -773,22 +773,20 @@ fn maybeIgnoreSigpipe() void {
.dragonfly,
.freebsd,
.serenity,
- => true,
-
- else => false,
- };
-
- if (have_sigpipe_support and !std.options.keep_sigpipe) {
- const posix = std.posix;
- const act: posix.Sigaction = .{
- // Set handler to a noop function instead of `SIG.IGN` to prevent
- // leaking signal disposition to a child process.
- .handler = .{ .handler = noopSigHandler },
- .mask = posix.sigemptyset(),
- .flags = 0,
- };
- posix.sigaction(posix.SIG.PIPE, &act, null);
+ => {},
+ else => return,
}
+ const posix = std.posix;
+ const act: posix.Sigaction = .{
+ // Set handler to a noop function instead of `SIG.IGN` to prevent
+ // leaking signal disposition to a child process.
+ .handler = .{ .handler = noopSigHandler },
+ .mask = posix.sigemptyset(),
+ .flags = 0,
+ };
+ if (!std.options.keep_sigpoll) posix.sigaction(posix.SIG.POLL, &act, null);
+ if (@hasField(posix.SIG, "IO") and posix.SIG.IO != posix.SIG.POLL and !std.options.keep_sigio) posix.sigaction(posix.SIG.IO, &act, null);
+ if (!std.options.keep_sigpipe) posix.sigaction(posix.SIG.PIPE, &act, null);
}
fn noopSigHandler(_: i32) callconv(.c) void {}