[sr-dev] git:master:bfe95c90: core: add support for time64 libcs

Daniel-Constantin Mierla miconda at gmail.com
Wed Nov 3 13:03:40 CET 2021


Module: kamailio
Branch: master
Commit: bfe95c90e91a0bc33a769967a5841a4ab43a6553
URL: https://github.com/kamailio/kamailio/commit/bfe95c90e91a0bc33a769967a5841a4ab43a6553

Author: Sebastian Kemper <sebastian_ml at gmx.net>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2021-11-03T13:03:34+01:00

core: add support for time64 libcs

libcs are implementing changes to fix the year 2038 issue on 32 bit
platforms (see [1]). musl libc already went ahead and implemented it,
starting with musl-1.2.0 (see [2]).

This commit adds the groundwork for always using the "lld" format when
dealing with time_t and casting the values to be formatted to (long
long). The aim is to be future proof and portable.

Example warning when not using TIME_T_FMT while compiling for a 32 bit
target using a time64 libc:

In file included from auth_identity.c:50:
auth_identity.c: In function 'check_date':
../../core/dprint.h:316:73: warning: format '%ld' expects argument of type 'long int', but argument 11 has type 'time_t' {aka 'long long int'} [-Wformat=]
  316 |                                                         fprintf(stderr, "%2d(%d) %s: %.*s%s%s%s" fmt, \
      |                                                                         ^~~~~~~~~~~~~~~~~~~~~~~~
../../core/dprint.h:340:25: note: in expansion of macro 'LOG_FX'
  340 |                         LOG_FX(facility, level, lname, prefix, _FUNC_NAME_, fmt, ## args)
      |                         ^~~~~~
../../core/dprint.h:346:25: note: in expansion of macro 'LOG_FL'
  346 |                         LOG_FL(facility, level, NULL, prefix, fmt, ## args)
      |                         ^~~~~~
../../core/dprint.h:349:25: note: in expansion of macro 'LOG_FP'
  349 |                         LOG_FP(DEFAULT_FACILITY, (level), LOC_INFO, fmt, ## args)
      |                         ^~~~~~
auth_identity.c:594:17: note: in expansion of macro 'LOG'
  594 |                 LOG(L_INFO, "AUTH_IDENTITY VERIFIER: Outdated date header value (%ld sec)\n", tnow - tmsg + glb_iauthval);
      |                 ^~~

[1] https://sourceware.org/glibc/wiki/Y2038ProofnessDesign
[2] https://musl.libc.org/time64.html

Signed-off-by: Sebastian Kemper <sebastian_ml at gmx.net>

---

Modified: src/core/dprint.h

---

Diff:  https://github.com/kamailio/kamailio/commit/bfe95c90e91a0bc33a769967a5841a4ab43a6553.diff
Patch: https://github.com/kamailio/kamailio/commit/bfe95c90e91a0bc33a769967a5841a4ab43a6553.patch

---

diff --git a/src/core/dprint.h b/src/core/dprint.h
index 65fcc6fc3c..fbdd349acb 100644
--- a/src/core/dprint.h
+++ b/src/core/dprint.h
@@ -35,6 +35,8 @@
 #include "compiler_opt.h"
 #include "cfg_core.h"
 
+#define TIME_T_FMT "lld"
+#define TIME_T_CAST(x) ((long long)(x))
 
 /** dicover the function name */
 /* C >= 99 has __func__, older gcc versions have __FUNCTION__ */




More information about the sr-dev mailing list