From 02e41fa61ec13cf2c59c9632bb67dcc2168c2c01 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Tue, 30 May 2006 20:18:24 +0000 Subject: [PATCH] When using -k, make sure to flush all of the subprocess's output to stdout, even after the subprocess has died. --- src/utils/pintos | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/utils/pintos b/src/utils/pintos index b18693b..079ab5a 100755 --- a/src/utils/pintos +++ b/src/utils/pintos @@ -702,11 +702,16 @@ sub xsystem { my ($buf) = ""; my ($boots) = 0; local ($|) = 1; - while (waitpid ($pid, WNOHANG) == 0) { + for (;;) { + if (waitpid ($pid, WNOHANG) == 0) { + # Subprocess died. Pass through any remaining data. + print $buf while sysread ($in, $buf, 4096) > 0; + last; + } + # Read and print out pipe data. my ($len) = length ($buf); - waitpid ($pid, 0), last - if sysread ($in, $buf, 4096, $len) <= 0; + last if sysread ($in, $buf, 4096, $len) <= 0; print substr ($buf, $len); # Remove full lines from $buf and scan them for keywords. @@ -725,9 +730,8 @@ sub xsystem { } } } - } else { - waitpid ($pid, 0); } + waitpid ($pid, 0); alarm (0); &$cleanup (); -- 2.30.2