From: Ben Pfaff Date: Tue, 30 May 2006 20:18:24 +0000 (+0000) Subject: When using -k, make sure to flush all of the subprocess's output to X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pintos-anon;a=commitdiff_plain;h=94e3568f3303b757f9e4133524b647163792662d When using -k, make sure to flush all of the subprocess's output to stdout, even after the subprocess has died. --- 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 ();