From 4840a9664526980d20bffb22c6266a38ce216994 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Arrufat?= Date: Thu, 23 Jul 2026 12:16:19 +0200 Subject: [PATCH] cli: fix help pager broken by lp.io's failing allocator std.Io.Threaded.init_single_threaded sets .allocator = .failing, which spawnPosix uses to build the child's argv/env, so std.process.spawn(lp.io, ...) always returns OutOfMemory and printPaged silently fell back to plain output. Spawn the pager through a local Threaded instance with a real allocator and the real environ (the single-threaded one is empty, breaking PATH lookup of the less fallback). --- src/Config.zig | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Config.zig b/src/Config.zig index 9609642b0..fbdfd9553 100644 --- a/src/Config.zig +++ b/src/Config.zig @@ -922,22 +922,27 @@ fn printPaged(allocator: Allocator, text: []const u8) void { var environ_map = lp.environMap(allocator) catch return printPlain(text); defer environ_map.deinit(); - var child = std.process.spawn(lp.io, .{ + // lp.io cannot spawn children: failing allocator, empty environ (no PATH). + var pager_threaded: std.Io.Threaded = .init(allocator, .{ .environ = lp.environ() }); + defer pager_threaded.deinit(); + const pager_io = pager_threaded.io(); + + var child = std.process.spawn(pager_io, .{ .argv = argv, .environ_map = &environ_map, .stdin = .pipe, }) catch return printPlain(text); if (child.stdin) |stdin| { - var writer = stdin.writerStreaming(lp.io, &.{}); + var writer = stdin.writerStreaming(pager_io, &.{}); // A write error here is the pager exiting early (user quit, or the // command failed) — wait() below decides which. writer.interface.writeAll(text) catch {}; - stdin.close(lp.io); + stdin.close(pager_io); child.stdin = null; } - const term_result = child.wait(lp.io) catch return printPlain(text); + const term_result = child.wait(pager_io) catch return printPlain(text); const clean_exit = term_result == .exited and term_result.exited == 0; // Quitting the pager early is still exit 0; a non-zero exit means the // pager failed (e.g. $PAGER not found) and the help was never shown.