[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 18/53] error-report: replace deprecated g_get_current_time() with
From: |
Paolo Bonzini |
Subject: |
[PULL 18/53] error-report: replace deprecated g_get_current_time() with glib >= 2.62 |
Date: |
Tue, 19 Apr 2022 07:50:34 +0200 |
From: Marc-André Lureau <marcandre.lureau@redhat.com>
According to GLib API:
g_get_current_time has been deprecated since version 2.62 and should not
be used in newly-written code. GTimeVal is not year-2038-safe. Use
g_get_real_time() instead.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20220323155743.1585078-14-marcandre.lureau@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
include/glib-compat.h | 10 ++++++++++
util/qemu-error.c | 17 ++++++++++++++---
2 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/include/glib-compat.h b/include/glib-compat.h
index 3113a7d2af..dc14d3ec0d 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 7769aee8e7..71ce3ee700 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);
}
--
2.35.1
- [PULL 33/53] Move CPU softfloat unions to cpu-float.h, (continued)
- [PULL 33/53] Move CPU softfloat unions to cpu-float.h, Paolo Bonzini, 2022/04/19
- [PULL 34/53] Move fcntl_setfl() to oslib-posix, Paolo Bonzini, 2022/04/19
- [PULL 35/53] qga: remove explicit environ argument from exec/spawn, Paolo Bonzini, 2022/04/19
- [PULL 28/53] include: move target page bits declaration to page-vary.h, Paolo Bonzini, 2022/04/19
- [PULL 29/53] include: move progress API to qemu-progress.h, Paolo Bonzini, 2022/04/19
- [PULL 45/53] hyperv: Add definitions for syndbg, Paolo Bonzini, 2022/04/19
- [PULL 46/53] hyperv: Add support to process syndbg commands, Paolo Bonzini, 2022/04/19
- [PULL 36/53] Remove qemu-common.h include from most units, Paolo Bonzini, 2022/04/19
- [PULL 48/53] s390x: follow qdev tree to detect SCSI device on a CCW bus, Paolo Bonzini, 2022/04/19
- [PULL 22/53] include: move qemu_write_full() declaration to osdep.h, Paolo Bonzini, 2022/04/19
- [PULL 18/53] error-report: replace deprecated g_get_current_time() with glib >= 2.62,
Paolo Bonzini <=
- [PULL 43/53] thread-posix: optimize qemu_sem_timedwait with zero timeout, Paolo Bonzini, 2022/04/19
- [PULL 50/53] virtio-ccw: move device type declarations to .c files, Paolo Bonzini, 2022/04/19
- [PULL 53/53] target/i386: Remove unused XMMReg, YMMReg types and CPUState fields, Paolo Bonzini, 2022/04/19
- [PULL 25/53] include: move dump_in_progress() to runstate.h, Paolo Bonzini, 2022/04/19
- [PULL 26/53] include: move C/util-related declarations to cutils.h, Paolo Bonzini, 2022/04/19
- [PULL 32/53] include: move page_size_init() to include/hw/core/cpu.h, Paolo Bonzini, 2022/04/19
- [PULL 42/53] thread-posix: implement Semaphore with QemuCond and QemuMutex, Paolo Bonzini, 2022/04/19
- [PULL 39/53] whpx: Added support for breakpoints and stepping, Paolo Bonzini, 2022/04/19
- [PULL 47/53] hw: hyperv: Initial commit for Synthetic Debugging device, Paolo Bonzini, 2022/04/19
- [PULL 49/53] virtio-ccw: move vhost_ccw_scsi to a separate file, Paolo Bonzini, 2022/04/19