From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E821EC433EF for ; Thu, 7 Apr 2022 11:21:41 +0000 (UTC) Received: from localhost ([::1]:38516 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncQCq-0001ry-Ji for qemu-devel@archiver.kernel.org; Thu, 07 Apr 2022 07:21:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51750) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncQB4-00013M-Il for qemu-devel@nongnu.org; Thu, 07 Apr 2022 07:19:50 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]:54959) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ncQB2-0002K5-Qi for qemu-devel@nongnu.org; Thu, 07 Apr 2022 07:19:50 -0400 Received: by mail-wm1-x329.google.com with SMTP id r64so3294999wmr.4 for ; Thu, 07 Apr 2022 04:19:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=67+z+D9ryalJ10Z55qagjozorBQEXake7yUTIn2EtaU=; b=PehIMvIIVXVhaummo8+dyErhahNmlhTf9zn/mR/4vhTurktaulQmpKHqtiuSRa8eIQ +lffHI3WeULFuUUjaVgzBRVfAIW7BaOyiVKVB0tF4avSh3QTtk++aC3/rI3O5bgqsFe4 fjCyQmykfZ8qMsCR5pv4u2RiFwW2OiBJmEaq5ZO7VKs9mXEPj7SszbASGl73U3SRqV2z fMVOEEcwiWPV4Li+db8yg11nO1t4lzZJzWcbOr0XTmKF2lBdMFjpoqyB2+WJ63k7qhYA NcUVqnNnLjOrfl88AvRFBzuD7UWpwIR+IUR0BhYc01147QGjKLUgPIZjnVSBNgG8flIo Z9Ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=67+z+D9ryalJ10Z55qagjozorBQEXake7yUTIn2EtaU=; b=vv4305lGVBkT10uSqTu3tXIK2CThI8G+DU/RvvLBOwY5j57QdTuTEZmyJDSAal3Cnr WBaVBK+LEeA0BqVQsyC/OkwMZw9jOdhVEeFpjnnYufIhtNpdrW8j12EO2mn8g4VucR9L typrCArOtU14jsO6w/NV/3PytQbYZkTdesnajridp2n90u8wQpvkxKV2Nzx/0Ysa2fUT LYmpZ69TZURcTVG93zq0tXurkCH7d+a3AdjbcggHzm6WDnkLEoWJQNcXBMuo2+WyrYew HuWlI2UlsIMeNB0Ay4Rxauq8ROgyB7S6uvi4elLlMEeBP06kQ+3dhLntwb1//Lj4lUeB CgIA== X-Gm-Message-State: AOAM5337knWKXSJXjhxKyoSHuswJRmveuUdDyt7dfEhviOWLbpe2EIJl mxWj6RExKUlNwqUVjvMrQ2CYCtaONEnoBP8pAEg= X-Google-Smtp-Source: ABdhPJxVBIje5JxoPeZXn08xbxv70BlQZX94nMs5h8EzdbWGUlHlAzKVL1+e5N7y1fB1z8oTz4hKNDt/Pwf1w8lU9Sw= X-Received: by 2002:a7b:c7c3:0:b0:389:cbf1:fadf with SMTP id z3-20020a7bc7c3000000b00389cbf1fadfmr12060297wmk.147.1649330387043; Thu, 07 Apr 2022 04:19:47 -0700 (PDT) MIME-Version: 1.0 References: <20220323155743.1585078-1-marcandre.lureau@redhat.com> <20220323155743.1585078-13-marcandre.lureau@redhat.com> <878rshla33.fsf@pond.sub.org> In-Reply-To: <878rshla33.fsf@pond.sub.org> From: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= Date: Thu, 7 Apr 2022 15:19:35 +0400 Message-ID: Subject: Re: [PATCH 12/32] qga: replace deprecated g_get_current_time() To: Markus Armbruster Content-Type: multipart/alternative; boundary="000000000000d646ed05dc0ea773" Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=marcandre.lureau@gmail.com; helo=mail-wm1-x329.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , QEMU Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" --000000000000d646ed05dc0ea773 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi On Thu, Apr 7, 2022 at 9:54 AM Markus Armbruster wrote: > marcandre.lureau@redhat.com writes: > > > From: Marc-Andr=C3=A9 Lureau > > > > According to GLib API: > > g_get_current_time has been deprecated since version 2.62 and should no= t > > be used in newly-written code. GTimeVal is not year-2038-safe. Use > > g_get_real_time() instead. > > > > Signed-off-by: Marc-Andr=C3=A9 Lureau > > --- > > qga/main.c | 7 ++++--- > > 1 file changed, 4 insertions(+), 3 deletions(-) > > > > diff --git a/qga/main.c b/qga/main.c > > index b9dd19918e47..1deb0ee2fbfe 100644 > > --- a/qga/main.c > > +++ b/qga/main.c > > @@ -314,7 +314,6 @@ static void ga_log(const gchar *domain, > GLogLevelFlags level, > > const gchar *msg, gpointer opaque) > > { > > GAState *s =3D opaque; > > - GTimeVal time; > > const char *level_str =3D ga_log_level_str(level); > > > > if (!ga_logging_enabled(s)) { > > @@ -329,9 +328,11 @@ static void ga_log(const gchar *domain, > GLogLevelFlags level, > > #else > > if (level & s->log_level) { > > #endif > > - g_get_current_time(&time); > > + gint64 t =3D g_get_real_time(); > > fprintf(s->log_file, > > - "%lu.%lu: %s: %s\n", time.tv_sec, time.tv_usec, > level_str, msg); > > The old code is kind of wrong. Say it's 1649309843.000001 seconds past > the epoch. Prints "1649309843.1". 9us later, it prints > "1649309843.10". Should really use %06lu for the microseconds part. > good idea > Whether you want to fix this in this patch, or just note it for later in > the commit message, or ignore it alltogether is up to you. > > > + "%" G_GINT64_FORMAT ".%" G_GINT64_FORMAT > > This gives me flashbacks to the 90s. Please use PRId64 like we do > everywhere else. > > I'd ditch gint64_t for int64_t, too. > ack, ack > > > + ": %s: %s\n", t / G_USEC_PER_SEC, t % G_USEC_PER_SEC, > > + level_str, msg); > > fflush(s->log_file); > > } > > } > > > --=20 Marc-Andr=C3=A9 Lureau --000000000000d646ed05dc0ea773 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi

On Thu, Apr 7, 2022 at 9:54 AM Mark= us Armbruster <armbru@redhat.com> wrote:
marcandre.lur= eau@redhat.com writes:

> From: Marc-Andr=C3=A9 Lureau <marcandre.lureau@redhat.com>
>
> According to GLib API:
> g_get_current_time has been deprecated since version 2.62 and should n= ot
> be used in newly-written code. GTimeVal is not year-2038-safe. Use
> g_get_real_time() instead.
>
> Signed-off-by: Marc-Andr=C3=A9 Lureau <marcandre.lureau@redhat.com> > ---
>=C2=A0 qga/main.c | 7 ++++---
>=C2=A0 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/qga/main.c b/qga/main.c
> index b9dd19918e47..1deb0ee2fbfe 100644
> --- a/qga/main.c
> +++ b/qga/main.c
> @@ -314,7 +314,6 @@ static void ga_log(const gchar *domain, GLogLevelF= lags level,
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0const gchar *msg, gpointer opaque)
>=C2=A0 {
>=C2=A0 =C2=A0 =C2=A0 GAState *s =3D opaque;
> -=C2=A0 =C2=A0 GTimeVal time;
>=C2=A0 =C2=A0 =C2=A0 const char *level_str =3D ga_log_level_str(level);=
>=C2=A0
>=C2=A0 =C2=A0 =C2=A0 if (!ga_logging_enabled(s)) {
> @@ -329,9 +328,11 @@ static void ga_log(const gchar *domain, GLogLevel= Flags level,
>=C2=A0 #else
>=C2=A0 =C2=A0 =C2=A0 if (level & s->log_level) {
>=C2=A0 #endif
> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 g_get_current_time(&time);
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 gint64 t =3D g_get_real_time();
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 fprintf(s->log_file,
> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "%lu.%lu= : %s: %s\n", time.tv_sec, time.tv_usec, level_str, msg);

The old code is kind of wrong.=C2=A0 Say it's 1649309843.000001 seconds= past
the epoch.=C2=A0 Prints "1649309843.1".=C2=A0 9us later, it print= s
"1649309843.10".=C2=A0 Should really use %06lu for the microsecon= ds part.

good idea

=

Whether you want to fix this in this patch, or just note it for later in the commit message, or ignore it alltogether is up to you.

> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "%"= G_GINT64_FORMAT ".%" G_GINT64_FORMAT

This gives me flashbacks to the 90s.=C2=A0 Please use PRId64 like we do
everywhere else.

I'd ditch gint64_t for int64_t, too.

ack, ack
=C2=A0

> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ": %s: %= s\n", t / G_USEC_PER_SEC, t % G_USEC_PER_SEC,
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 level_str, ms= g);
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 fflush(s->log_file);
>=C2=A0 =C2=A0 =C2=A0 }
>=C2=A0 }




--
Marc-Andr=C3=A9 Lureau
--000000000000d646ed05dc0ea773--