aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/glib-compat.h10
-rw-r--r--util/qemu-error.c17
2 files changed, 24 insertions, 3 deletions
diff --git a/include/glib-compat.h b/include/glib-compat.h
index 3113a7d..dc14d3e 100644
--- a/include/glib-compat.h
+++ b/include/glib-compat.h
@@ -145,6 +145,16 @@ qemu_g_test_slow(void)
#define g_test_thorough() qemu_g_test_slow()
#define g_test_quick() (!qemu_g_test_slow())
+#if GLIB_CHECK_VERSION(2,62,0)
+static inline gchar *
+g_date_time_format_iso8601_compat(GDateTime *datetime)
+{
+ return g_date_time_format_iso8601(datetime);
+}
+
+#define g_date_time_format_iso8601 g_date_time_format_iso8601_compat
+#endif
+
#pragma GCC diagnostic pop
#endif
diff --git a/util/qemu-error.c b/util/qemu-error.c
index 7769aee..71ce3ee 100644
--- a/util/qemu-error.c
+++ b/util/qemu-error.c
@@ -180,6 +180,19 @@ static void print_loc(void)
}
}
+static char *
+real_time_iso8601(void)
+{
+#if GLIB_CHECK_VERSION(2, 62, 0)
+ g_autoptr(GDateTime) dt = g_date_time_new_from_unix_utc(g_get_real_time());
+ return g_date_time_format_iso8601(dt);
+#else
+ GTimeVal tv;
+ g_get_current_time(&tv);
+ return g_time_val_to_iso8601(&tv);
+#endif
+}
+
/*
* Print a message to current monitor if we have one, else to stderr.
* @report_type is the type of message: error, warning or informational.
@@ -189,12 +202,10 @@ static void print_loc(void)
*/
static void vreport(report_type type, const char *fmt, va_list ap)
{
- GTimeVal tv;
gchar *timestr;
if (message_with_timestamp && !monitor_cur()) {
- g_get_current_time(&tv);
- timestr = g_time_val_to_iso8601(&tv);
+ timestr = real_time_iso8601();
error_printf("%s ", timestr);
g_free(timestr);
}