From f8bdd2b1bb909e3cd6b83ff0389e48f51bcd257c Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 20 Sep 2024 15:21:37 -0700 Subject: [PATCH] termio: killpg expected to fail on darwin, still go into waitpid loop Fixes #2273 On macOS, killpg is expected to fail with EPERM because of the way we launch a login process around it. Before this commit, this caused us to never call waitpid and reap the child process, which caused the child process to stick around as a zombie. This commit allows killpg to fail with EPERM on macOS and fall through to waitpid. --- src/termio/Exec.zig | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/termio/Exec.zig b/src/termio/Exec.zig index 1f7ac5c5e..5018ced33 100644 --- a/src/termio/Exec.zig +++ b/src/termio/Exec.zig @@ -1257,9 +1257,19 @@ 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. @@ -1267,6 +1277,7 @@ const Subprocess = struct { // 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); }