-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Added std.os.linux.sigtimedwait #25946
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1919,6 +1919,39 @@ pub fn gettid() pid_t { | |
| return @intCast(@as(u32, @truncate(syscall0(.gettid)))); | ||
| } | ||
|
|
||
| pub const TimedWaitError = error{ | ||
| /// Timeout supplied was reached. | ||
| TimeElapsed, | ||
| /// Call was interrupted by a signal not in supplied sigset. | ||
| OtherSignal, | ||
| /// Value in timeout is invalid | ||
| InvalidTimeout, | ||
| }; | ||
|
|
||
| /// Suspends the calling thread until one of the signals in set is pending or the specified timeout is reached (If one | ||
| /// of the signals in set is already pending for the calling thread, returns immediately.) Removes the signal from the | ||
| /// set of pending signals and returns that signal. If the info argument is non-NULL, that buffer is used to return | ||
| /// siginfo_t of the signal. If multiple signals in set are pending for the caller, the signal returned is determined | ||
| /// according to the usual ordering rules | ||
| pub fn sigtimedwait( | ||
| sigset: sigset_t, | ||
| siginfo: ?*siginfo_t, | ||
| /// specifies a minimum interval for which the thread is suspended waiting for a signal. (This | ||
| /// interval will be rounded up to the system clock granularity, and kernel scheduling delays mean that the interval | ||
| /// may overrun by a small amount.) | ||
| timeout: *const timespec, | ||
| ) TimedWaitError!SIG { | ||
| const sig_num = syscall4(.rt_sigtimedwait, @intFromPtr(&sigset), @intFromPtr(siginfo), @intFromPtr(timeout), NSIG / 8); | ||
|
|
||
| return switch (E.init(sig_num)) { | ||
| .SUCCESS => @enumFromInt(sig_num), | ||
| .AGAIN => error.TimeoutElapsed, | ||
| .INTR => error.OtherSignal, | ||
| .ENVAL => error.InvalidTimeout, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this a classic case of programmer error?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to #6389 this
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That is more likely, but I'm not a fan of the current stdlib behavior of cutting it's own head off when something unexpected happens. I can replace this with Someone wanna make the call and I'll update the diff?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An alternative would be using something like |
||
| else => |err| return std.posix.unexpectedErrno(err), | ||
| }; | ||
| } | ||
|
|
||
| pub fn sigprocmask(flags: u32, noalias set: ?*const sigset_t, noalias oldset: ?*sigset_t) usize { | ||
| return syscall4(.rt_sigprocmask, flags, @intFromPtr(set), @intFromPtr(oldset), NSIG / 8); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functions in
std.os.linuxdo not to switch on errno values. This function should probably just returnsig_numas anusizeand another function instd.os.linux.wrappedorstd.posixcan then call this function and switch on the errno.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zig/lib/std/os/linux.zig
Line 1896 in 879ea27
zig/lib/std/os/linux.zig
Line 9908 in 73f863a
zig/lib/std/os/linux.zig
Line 9975 in 73f863a
I thought the exact same thing, but decided to keep it here mostly because posix as it is now isn't long for the repo.