Skip to content

Commit

Permalink
Merge pull request #2277 from ghostty-org/kill
Browse files Browse the repository at this point in the history
termio: killpg expected to fail on darwin, still go into waitpid loop
  • Loading branch information
mitchellh authored Sep 21, 2024
2 parents f5c83d6 + f8bdd2b commit 5af3d84
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/termio/Exec.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1257,16 +1257,27 @@ const Subprocess = struct {
// descendents are well and truly dead. We will not rest
// until the entire family tree is obliterated.
while (true) {
if (c.killpg(pgid, c.SIGHUP) < 0) {
log.warn("error killing process group pgid={}", .{pgid});
return error.KillFailed;
switch (posix.errno(c.killpg(pgid, c.SIGHUP))) {
.SUCCESS => log.debug("process group killed pgid={}", .{pgid}),
else => |err| killpg: {
if ((comptime builtin.target.isDarwin()) and
err == .PERM)
{
log.debug("killpg failed with EPERM, expected on Darwin and ignoring", .{});
break :killpg;
}

log.warn("error killing process group pgid={} err={}", .{ pgid, err });
return error.KillFailed;
},
}

// See Command.zig wait for why we specify WNOHANG.
// The gist is that it lets us detect when children
// are still alive without blocking so that we can
// kill them again.
const res = posix.waitpid(pid, std.c.W.NOHANG);
log.debug("waitpid result={}", .{res.pid});
if (res.pid != 0) break;
std.time.sleep(10 * std.time.ns_per_ms);
}
Expand Down

0 comments on commit 5af3d84

Please sign in to comment.