[klibc] kinit: before exiting, tcdrain() any output

If kinit returns, the kernel will usually panic.  Often the serial port
driver will not flush data out the port before it does so.  Do tcdrain()
on file descriptors 2 and 1 before exiting, so the user has a better
chance of seeing the error.

After a bug report from Bjorn Helgaas <bjorn.helgaas@hp.com>.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
diff --git a/usr/kinit/kinit.c b/usr/kinit/kinit.c
index bd7c60e..ce4725c 100644
--- a/usr/kinit/kinit.c
+++ b/usr/kinit/kinit.c
@@ -8,6 +8,7 @@
 #include <alloca.h>
 #include <limits.h>
 #include <ctype.h>
+#include <termios.h>
 
 #include "kinit.h"
 #include "ipconfig.h"
@@ -317,5 +318,13 @@
 	if (mnt_sysfs)
 		umount2("/sys", 0);
 
-	exit(ret);
+	/*
+	 * If we get here, something bad probably happened, and the kernel
+	 * will most likely panic.  Drain console output so the user can
+	 * figure out what happened.
+	 */
+	tcdrain(2);
+	tcdrain(1);
+
+	return ret;
 }