Threaded.sleepPosix: fix libc error handling

Confusingly, the POSIX spec for clock_nanosleep() says it returns
*positive* error values directly and does not touch `errno`. Not
detecting EINTR properly here was breaking the cancellation of
threads blocked in this call when linking libc.
This commit is contained in:
Brandon Black 2026-01-28 16:54:04 -06:00 committed by Andrew Kelley
parent 9b415761dd
commit ecb9ddf267

View file

@ -10083,10 +10083,12 @@ fn sleepPosix(timeout: Io.Timeout) Io.SleepError!void {
var timespec: posix.timespec = timestampToPosix(deadline_nanoseconds);
const syscall: Syscall = try .start();
while (true) {
switch (posix.errno(posix.system.clock_nanosleep(clock_id, .{ .ABSTIME = switch (timeout) {
const rc = posix.system.clock_nanosleep(clock_id, .{ .ABSTIME = switch (timeout) {
.none, .duration => false,
.deadline => true,
} }, &timespec, &timespec))) {
} }, &timespec, &timespec);
// POSIX-standard libc clock_nanosleep() returns *positive* errno values directly
switch (if (builtin.link_libc) @as(posix.E, @enumFromInt(rc)) else posix.errno(rc)) {
.SUCCESS => {
syscall.finish();
return;