From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 0FCFB5A024D for ; Tue, 14 Mar 2023 11:36:12 +0100 (CET) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4PbVLJ1XvCz4xFN; Tue, 14 Mar 2023 21:36:08 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1678790168; bh=NusF3Bl0HVh2jO5KOXd7tL6dLJ4Cu1RDRM7EjNcnOJ8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=TkHLNDV0ZbTSfPjqQry0/CXXUsiWpftrrxNvTGV0loyGrS392Ek6jiTdFVL5EUNk/ SDqut68yNShhovfEAgqkFQyRPGZCuR4nSrCkUe2W6dEC5LSPJ9S8Vm8LQRvDjXpeMK YV6yG2k/OFhAxpnVYBwCzyt2kbqDkyZKDHkdKHXM= Date: Tue, 14 Mar 2023 21:25:39 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH] log: Avoid time_t/__syscall_slong_t format mismatch with long int on X32 ABI Message-ID: References: <20230313120715.3639260-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="icLietFQoc8iSrjb" Content-Disposition: inline In-Reply-To: <20230313120715.3639260-1-sbrivio@redhat.com> Message-ID-Hash: MUQIHML53KOU67IK2YWTGI6U5VFIOE43 X-Message-ID-Hash: MUQIHML53KOU67IK2YWTGI6U5VFIOE43 X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --icLietFQoc8iSrjb Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Mar 13, 2023 at 01:07:15PM +0100, Stefano Brivio wrote: > On X32 (ILP32 using AMD64 system call ABI) and glibc, > struct timespec::tv_nsec is __syscall_slong_t and not a long int, see > also https://sourceware.org/bugzilla/show_bug.cgi?id=3D16437 and > timespec(3type). Fine, we could cast that down to long and be done > with it. >=20 > But it turns out that also time_t (not guaranteed to be equivalent to > any type) is a long long int, and there we can't downcast. >=20 > To keep it simple, cast both to long long int, and change formats to > %lli, to avoid format warnings from gcc. >=20 > Signed-off-by: Stefano Brivio Reviewed-by: David Gibson > --- > log.c | 22 ++++++++++++---------- > 1 file changed, 12 insertions(+), 10 deletions(-) >=20 > diff --git a/log.c b/log.c > index d2f08fa..d7411ba 100644 > --- a/log.c > +++ b/log.c > @@ -53,9 +53,9 @@ void name(const char *format, ...) { \ > \ > if (setlogmask(0) & LOG_MASK(LOG_DEBUG) && log_file =3D=3D -1) { \ > clock_gettime(CLOCK_REALTIME, &tp); \ > - fprintf(stderr, "%li.%04li: ", \ > - tp.tv_sec - log_start, \ > - tp.tv_nsec / (100L * 1000)); \ > + fprintf(stderr, "%lli.%04lli: ", \ > + (long long int)tp.tv_sec - log_start, \ > + (long long int)tp.tv_nsec / (100L * 1000)); \ > } \ > \ > if ((LOG_MASK(LOG_PRI(level)) & log_mask) || BEFORE_DAEMON) { \ > @@ -225,8 +225,9 @@ static void logfile_rotate_fallocate(int fd, struct t= imespec *ts) > return; > =20 > n =3D snprintf(buf, BUFSIZ, > - "%s - log truncated at %li.%04li", log_header, > - ts->tv_sec - log_start, ts->tv_nsec / (100L * 1000)); > + "%s - log truncated at %lli.%04lli", log_header, > + (long long int)(ts->tv_sec - log_start), > + (long long int)(ts->tv_nsec / (100L * 1000))); > =20 > /* Avoid partial lines by padding the header with spaces */ > nl =3D memchr(buf + n + 1, '\n', BUFSIZ - n - 1); > @@ -256,9 +257,9 @@ static void logfile_rotate_move(int fd, struct timesp= ec *ts) > char buf[BUFSIZ], *nl; > =20 > header_len =3D snprintf(buf, BUFSIZ, > - "%s - log truncated at %li.%04li\n", log_header, > - ts->tv_sec - log_start, > - ts->tv_nsec / (100L * 1000)); > + "%s - log truncated at %lli.%04lli\n", log_header, > + (long long int)(ts->tv_sec - log_start), > + (long long int)(ts->tv_nsec / (100L * 1000))); > if (lseek(fd, 0, SEEK_SET) =3D=3D -1) > return; > if (write(fd, buf, header_len) =3D=3D -1) > @@ -349,8 +350,9 @@ void logfile_write(int pri, const char *format, va_li= st ap) > if (clock_gettime(CLOCK_REALTIME, &ts)) > return; > =20 > - n =3D snprintf(buf, BUFSIZ, "%li.%04li: %s", > - ts.tv_sec - log_start, ts.tv_nsec / (100L * 1000), > + n =3D snprintf(buf, BUFSIZ, "%lli.%04lli: %s", > + (long long int)(ts.tv_sec - log_start), > + (long long int)(ts.tv_nsec / (100L * 1000)), > logfile_prefix[pri]); > =20 > n +=3D vsnprintf(buf + n, BUFSIZ - n, format, ap); --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --icLietFQoc8iSrjb Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmQQS50ACgkQzQJF27ox 2GfnpRAAkWMKAxDp9L+75Tx8ohXBDQPchIB+nii2SectJjmn8cgKTjmoLlBIsmUA uJrW0wClffGyhooysQ3A9UADPg5NcK2NJibtEfAg0q065NlhcIpkWIWrB9VAWS6u MeUmtvVw+uTS3dCyNFjpACcGJtwDTcwRWnGY/vHo6xBO+zxDcz9fJ/SAuEiD642o ApEvTpxVdO4AJkkSY+CSfjelTKDNSLQl8JS/nQGKNMnaeiNpRKowGB3Fm22FbPtg 9OgmsgIGSteww4JDKcucSElgTqqdKuyE6aIOga7mX9panyCV96nBb3yy28KVRET7 zYy2l8DsiE1luWHFjEJDVy/V10eJGFKdMdCA9nitD9HmI0oL1maAaB97k3Rv8+L9 szNOxw9/khs2pnhwiUW1FfPTgLpQBaxMeEXD0zwtQLegArakfFh8NCJhmYAmR1ms RuWiAkRqedUQYsMFcrvwy5A4nAp69JIBMaN18UmoNtXyrYSvF1gDAjuTjyfFg4KK 6Zno8uu7Ea8e7xLIdbXKEuRVrZumfDePtHcvrDnT+p0e83d5JSCjXLcQpUlUDPOr uXBrOgzHr3KFRlUuITfcNvMu9SESnHjVoTZX/UKkhbScSGMOnOdN7z3ZApS9VVd9 GDabHKcSULyO5D43rfCAPVB45jweUKtYGtfD1ADOI/wbTvobZIE= =NaXT -----END PGP SIGNATURE----- --icLietFQoc8iSrjb--