kup-server: use IO::Handle to explicitly set autoflushing

Use IO::Handle to explicitly set autoflushing for specific
file handles as needed (STDERR for displaying a progress bar,
STDOUT after dir.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
diff --git a/kup-server b/kup-server
index ecd2271..3992aa5 100755
--- a/kup-server
+++ b/kup-server
@@ -59,6 +59,7 @@
 use BSD::Resource;
 use Fcntl qw(:DEFAULT :flock :mode);
 use POSIX;
+use IO::Handle;
 
 use Sys::Syslog qw(:standard :macros);
 use Git;
@@ -387,6 +388,9 @@
 
 	$left -= $blk;
 
+	# STDERR needs to be flushed
+	STDERR->autoflush(1);
+
 	my $now  = time();
 	my $perc = int((($len-$left)*100)/$len);
 	if ($left == 0 ?
@@ -1106,9 +1110,9 @@
     closedir($dh);
 
     # Termination marker to make output machine-readable
-    $| = 1;		# At least try to flush stdout after this line
+    STDOUT->autoflush(1);	# At least try to flush stdout after this line
     print "\n";
-    $| = 0;
+    STDOUT->autoflush(0);
 }
 
 sub get_command()