libavb: add new configuration for print log to kmsg

It's difficult to analyze when problem with first stage init's avb logic.
If you want to see log at kmsg, please add configuration in Android.bp
    "AVB_USE_PRINTF_LOGS"
    "USE_KMSG_AS_LOG_TARGET"

$adb shell cat /proc/kmsg
//-- snip --
[    0.842199] [6:           init:    1] avb_slot_verify.c:692: DEBUG:
Loading vbmeta struct from partition 'vbmeta'.

Test: Build Test, Check klog, atest --test-mapping external/avb
Change-Id: I0b585f4f6bcae45a55b48cf6a52e0ee0330f5e99
Signed-off-by: JeongHyeon Lee <jhs2.lee@samsung.com>
diff --git a/libavb/avb_sysdeps_posix.c b/libavb/avb_sysdeps_posix.c
index a954869..186daa1 100644
--- a/libavb/avb_sysdeps_posix.c
+++ b/libavb/avb_sysdeps_posix.c
@@ -58,10 +58,27 @@
   abort();
 }
 
+static FILE* get_log_stream() {
+#ifdef USE_KMSG_AS_LOG_TARGET
+  static FILE* fp = NULL;
+
+  if (fp == NULL) {
+    fp = fopen("/dev/kmsg", "ae");
+    if (fp == NULL || setvbuf(fp, NULL, _IONBF, 0) != 0) {
+      fp = stderr;
+    }
+  }
+
+  return fp;
+#else
+  return stderr;
+#endif
+}
+
 void avb_printf(const char* fmt, ...) {
   va_list ap;
   va_start(ap, fmt);
-  vfprintf(stderr, fmt, ap);
+  vfprintf(get_log_stream(), fmt, ap);
   va_end(ap);
 }