summaryrefslogtreecommitdiff
path: root/src/trace/ptrace.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/trace/ptrace.zig')
-rw-r--r--src/trace/ptrace.zig13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/trace/ptrace.zig b/src/trace/ptrace.zig
index fd7ebd1..ca3dc39 100644
--- a/src/trace/ptrace.zig
+++ b/src/trace/ptrace.zig
@@ -119,8 +119,19 @@ pub const Process = struct {
/// The next stop of one thread (-1: of any child), which becomes the current one.
pub fn wait(p: *Process, tid: linux.pid_t) !Stop {
+ return (try p.next(tid, WALL)).?;
+ }
+
+ /// The same without waiting: null while nothing has stopped.
+ pub fn poll(p: *Process, tid: linux.pid_t) !?Stop {
+ return p.next(tid, WALL | linux.W.NOHANG);
+ }
+
+ fn next(p: *Process, tid: linux.pid_t, flags: u32) !?Stop {
var status: u32 = 0;
- p.tid = @intCast(try check(linux.waitpid(tid, @ptrCast(&status), WALL)));
+ const stopped = try check(linux.waitpid(tid, @ptrCast(&status), flags));
+ if (stopped == 0) return null;
+ p.tid = @intCast(stopped);
if (linux.W.IFEXITED(status) or linux.W.IFSIGNALED(status)) {
if (p.tid == p.pid) p.gone = true else p.threads -= 1;
return if (linux.W.IFEXITED(status)) .{ .exited = linux.W.EXITSTATUS(status) } else .{ .killed = linux.W.TERMSIG(status) };