diff mbox series

error-report: Fix GDateTime usage

Message ID 20220425204136.2370585-1-farman@linux.ibm.com
State New
Headers show
Series error-report: Fix GDateTime usage | expand

Commit Message

Eric Farman April 25, 2022, 8:41 p.m. UTC
According to the glib manual:

 - g_date_time_new_from_unix_utc() takes a parameter of the number of
   SECONDS since the unix epoch
 - g_get_real_time() returns the number of MICROSECONDS since the
   unix epoch

Rather than convert the latter with G_USECS_PER_SEC, use the convenient
g_date_time_new_now_utc() routine to create the GDateTime object.
This fixes a userspace fault seen when messages get sent to monitor,
such as when a guest is destroyed.

Fixes: 73dab893b569 ("error-report: replace deprecated g_get_current_time() with glib >= 2.62")
Signed-off-by: Eric Farman <farman@linux.ibm.com>
---
 util/error-report.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Marc-André Lureau April 26, 2022, 6:41 a.m. UTC | #1
Hi

On Tue, Apr 26, 2022 at 12:43 AM Eric Farman <farman@linux.ibm.com> wrote:

> According to the glib manual:
>
>  - g_date_time_new_from_unix_utc() takes a parameter of the number of
>    SECONDS since the unix epoch
>  - g_get_real_time() returns the number of MICROSECONDS since the
>    unix epoch
>
> Rather than convert the latter with G_USECS_PER_SEC, use the convenient
> g_date_time_new_now_utc() routine to create the GDateTime object.
> This fixes a userspace fault seen when messages get sent to monitor,
> such as when a guest is destroyed.
>
> Fixes: 73dab893b569 ("error-report: replace deprecated
> g_get_current_time() with glib >= 2.62")
> Signed-off-by: Eric Farman <farman@linux.ibm.com>
>

Same patch as:
https://patchew.org/QEMU/20220424105036.291370-1-haiyue.wang@intel.com/

thanks

---
>  util/error-report.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/util/error-report.c b/util/error-report.c
> index dbadaf206d..5edb2e6040 100644
> --- a/util/error-report.c
> +++ b/util/error-report.c
> @@ -173,7 +173,7 @@ 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());
> +    g_autoptr(GDateTime) dt = g_date_time_new_now_utc();
>      /* ignore deprecation warning, since GLIB_VERSION_MAX_ALLOWED is 2.56
> */
>  #pragma GCC diagnostic push
>  #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
> --
> 2.32.0
>
>
>
diff mbox series

Patch

diff --git a/util/error-report.c b/util/error-report.c
index dbadaf206d..5edb2e6040 100644
--- a/util/error-report.c
+++ b/util/error-report.c
@@ -173,7 +173,7 @@  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());
+    g_autoptr(GDateTime) dt = g_date_time_new_now_utc();
     /* ignore deprecation warning, since GLIB_VERSION_MAX_ALLOWED is 2.56 */
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"