| ... | ... | @@ -253,6 +253,25 @@ pub var argv: [][*:0]u8 = if (builtin.link_libc) undefined else switch (builtin. |
| 253 | 253 | else => undefined, |
| 254 | 254 | }; |
| 255 | 255 | |
| 256 | pub const have_sigpipe_support = @hasDecl(@This(), "SIG") and @hasDecl(SIG, "PIPE"); |
| 257 | |
| 258 | fn noopSigHandler(_: c_int) callconv(.C) void {} |
| 259 | |
| 260 | /// On default executed by posix startup code before main(), if SIGPIPE is supported. |
| 261 | pub fn maybeIgnoreSigpipe() void { |
| 262 | if (have_sigpipe_support and !std.options.keep_sigpipe) { |
| 263 | const act = Sigaction{ |
| 264 | // We set handler to a noop function instead of SIG.IGN so we don't leak our |
| 265 | // signal disposition to a child process |
| 266 | .handler = .{ .handler = noopSigHandler }, |
| 267 | .mask = empty_sigset, |
| 268 | .flags = 0, |
| 269 | }; |
| 270 | sigaction(SIG.PIPE, &act, null) catch |err| |
| 271 | std.debug.panic("failed to install noop SIGPIPE handler with '{s}'", .{@errorName(err)}); |
| 272 | } |
| 273 | } |
| 274 | |
| 256 | 275 | /// To obtain errno, call this function with the return value of the |
| 257 | 276 | /// system function call. For some systems this will obtain the value directly |
| 258 | 277 | /// from the return code; for others it will use a thread-local errno variable. |
| ... | ... | @@ -4306,6 +4325,8 @@ pub const MMapError = error{ |
| 4306 | 4325 | /// a filesystem that was mounted no-exec. |
| 4307 | 4326 | PermissionDenied, |
| 4308 | 4327 | LockedMemoryLimitExceeded, |
| 4328 | ProcessFdQuotaExceeded, |
| 4329 | SystemFdQuotaExceeded, |
| 4309 | 4330 | OutOfMemory, |
| 4310 | 4331 | } || UnexpectedError; |
| 4311 | 4332 | |
| ... | ... | @@ -4347,6 +4368,8 @@ pub fn mmap( |
| 4347 | 4368 | .OVERFLOW => unreachable, // The number of pages used for length + offset would overflow. |
| 4348 | 4369 | .NODEV => return error.MemoryMappingNotSupported, |
| 4349 | 4370 | .INVAL => unreachable, // Invalid parameters to mmap() |
| 4371 | .MFILE => return error.ProcessFdQuotaExceeded, |
| 4372 | .NFILE => return error.SystemFdQuotaExceeded, |
| 4350 | 4373 | .NOMEM => return error.OutOfMemory, |
| 4351 | 4374 | else => return unexpectedErrno(err), |
| 4352 | 4375 | } |
| ... | ... | @@ -7081,21 +7104,3 @@ pub fn timerfd_gettime(fd: i32) TimerFdGetError!linux.itimerspec { |
| 7081 | 7104 | else => |err| return unexpectedErrno(err), |
| 7082 | 7105 | }; |
| 7083 | 7106 | } |
| 7084 | | |
| 7085 | | pub const have_sigpipe_support = @hasDecl(@This(), "SIG") and @hasDecl(SIG, "PIPE"); |
| 7086 | | |
| 7087 | | fn noopSigHandler(_: c_int) callconv(.C) void {} |
| 7088 | | |
| 7089 | | pub fn maybeIgnoreSigpipe() void { |
| 7090 | | if (have_sigpipe_support and !std.options.keep_sigpipe) { |
| 7091 | | const act = Sigaction{ |
| 7092 | | // We set handler to a noop function instead of SIG.IGN so we don't leak our |
| 7093 | | // signal disposition to a child process |
| 7094 | | .handler = .{ .handler = noopSigHandler }, |
| 7095 | | .mask = empty_sigset, |
| 7096 | | .flags = 0, |
| 7097 | | }; |
| 7098 | | sigaction(SIG.PIPE, &act, null) catch |err| |
| 7099 | | std.debug.panic("failed to install noop SIGPIPE handler with '{s}'", .{@errorName(err)}); |
| 7100 | | } |
| 7101 | | } |