mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 16:56:09 +03:00
command: only spin on waitpid if it's non-blocking
This commit is contained in:

committed by
Mitchell Hashimoto

parent
aa9e12dac2
commit
2e54ad2cce
@ -187,17 +187,20 @@ fn setupFd(src: File.Handle, target: i32) !void {
|
|||||||
|
|
||||||
/// Wait for the command to exit and return information about how it exited.
|
/// Wait for the command to exit and return information about how it exited.
|
||||||
pub fn wait(self: Command, block: bool) !Exit {
|
pub fn wait(self: Command, block: bool) !Exit {
|
||||||
// We specify NOHANG because its not our fault if the process we launch
|
const res = if (block) std.os.waitpid(self.pid.?, 0) else res: {
|
||||||
// for the tty doesn't properly waitpid its children. We don't want
|
// We specify NOHANG because its not our fault if the process we launch
|
||||||
// to hang the terminal over it.
|
// for the tty doesn't properly waitpid its children. We don't want
|
||||||
// When NOHANG is specified, waitpid will return a pid of 0 if the process
|
// to hang the terminal over it.
|
||||||
// doesn't have a status to report. When that happens, it is as though the
|
// When NOHANG is specified, waitpid will return a pid of 0 if the process
|
||||||
// wait call has not been performed, so we need to keep trying until we get
|
// doesn't have a status to report. When that happens, it is as though the
|
||||||
// a non-zero pid back, otherwise we end up with zombie processes.
|
// wait call has not been performed, so we need to keep trying until we get
|
||||||
var res = std.os.WaitPidResult{ .pid = 0, .status = 0 };
|
// a non-zero pid back, otherwise we end up with zombie processes.
|
||||||
while (res.pid == 0) {
|
while (true) {
|
||||||
res = std.os.waitpid(self.pid.?, if (block) 0 else std.c.W.NOHANG);
|
const res = std.os.waitpid(self.pid.?, std.c.W.NOHANG);
|
||||||
}
|
if (res.pid != 0) break :res res;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return Exit.init(res.status);
|
return Exit.init(res.status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user