From e33faef861e9a43ae401fb0b0014c8c96a69fe51 Mon Sep 17 00:00:00 2001 From: Yorhel Date: Sun, 2 Mar 2025 21:37:54 +0100 Subject: [PATCH] ManUtils: Fix possible deadlock on groff I/O --- ManUtils/ManUtils.pm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ManUtils/ManUtils.pm b/ManUtils/ManUtils.pm index 261b274..88280a4 100644 --- a/ManUtils/ManUtils.pm +++ b/ManUtils/ManUtils.pm @@ -5,6 +5,7 @@ use IPC::Open3; use IO::Poll qw/POLLOUT POLLIN/; use Symbol 'gensym'; use XSLoader; +use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK); XSLoader::load('ManUtils'); sub fmt($input) { @@ -27,6 +28,10 @@ sub fmt($input) { my $pid = open3(my $in, my $out, my $err = gensym, @cmd); + # "POLLOUT" does NOT guarantee that a write will not block, we must set + # O_NONBLOCK to tell the kernel that we can handle short writes. + fcntl($in, F_SETFL, fcntl($in, F_GETFL, 0) | O_NONBLOCK); + my $inoff = 0; my $output = ''; my $poll = IO::Poll->new;