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;