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 a new definition to src/core/dprint.h:
TIME_T_INT_FMT
If __USE_TIME_BITS64 is defined (by a time64 libc, see [1]), it is set
to the proper conversion for type int64_t, PRId64. If __USE_TIME_BITS64
is not defined, the status quo remains unchanged ("%ld" is used).
Note: In some places kamailio uses "%li" instead of "%ld". But in the
context of printf etc. there is no difference, so this commit replaces
"%li" with "%ld".
The new definition is used in the different parts of kamailio, where
appropriate.
These changes get rid of the new warnings that appeared with musl-1.2.0.
Below an example warning:
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(a)gmx.net>
<!-- Kamailio Pull Request Template -->
<!--
IMPORTANT:
- for detailed contributing guidelines, read:
https://github.com/kamailio/kamailio/blob/master/.github/CONTRIBUTING.md
- pull requests must be done to master branch, unless they are backports
of fixes from master branch to a stable branch
- backports to stable branches must be done with 'git cherry-pick -x ...'
- code is contributed under BSD for core and main components (tm, sl, auth, tls)
- code is contributed GPLv2 or a compatible license for the other components
- GPL code is contributed with OpenSSL licensing exception
-->
#### Pre-Submission Checklist
<!-- Go over all points below, and after creating the PR, tick all the checkboxes that apply -->
<!-- All points should be verified, otherwise, read the CONTRIBUTING guidelines from above-->
<!-- If you're unsure about any of these, don't hesitate to ask on sr-dev mailing list -->
- [x] Commit message has the format required by CONTRIBUTING guide
- [x] Commits are split per component (core, individual modules, libs, utils, ...)
- [x] Each component has a single commit (if not, squash them into one commit)
- [x] No commits to README files for modules (changes must be done to docbook files
in `doc/` subfolder, the README file is autogenerated)
#### Type Of Change
- [x] Small bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds new functionality)
- [ ] Breaking change (fix or feature that would change existing functionality)
#### Checklist:
<!-- Go over all points below, and after creating the PR, tick the checkboxes that apply -->
- [ ] PR should be backported to stable branches
- [x] Tested changes locally
- [ ] Related to issue #XXXX (replace XXXX with an open issue number)
#### Description
<!-- Describe your changes in detail -->
Hi all,
This adds time64 libc support. Should be non-breaking, status quo remains. I hope you don't mind a made up a new patch category, "time".
I did not run-test this (pretty busy right now). But the warnings go away.
If absolutely run-testing is needed for this, let me know.
Kind regards,
Seb
You can view, comment on, or merge this pull request online at:
https://github.com/kamailio/kamailio/pull/2894
-- Commit Summary --
* <a href="https://github.com/kamailio/kamailio/pull/2894/commits/27175614787f6b05795f…">time: add support for time64 libc</a>
-- File Changes --
M src/core/dprint.h (8)
M src/modules/auth_identity/auth_identity.c (2)
M src/modules/cdp/routing.c (4)
M src/modules/db_redis/redis_dbase.c (2)
M src/modules/ims_charging/ims_ro.c (2)
M src/modules/ims_dialog/dlg_handlers.c (2)
M src/modules/ims_icscf/scscf_list.c (4)
M src/modules/ims_registrar_pcscf/notify.c (2)
M src/modules/ims_registrar_pcscf/save.c (2)
M src/modules/ims_registrar_scscf/registrar_notify.c (3)
M src/modules/ims_registrar_scscf/save.c (2)
M src/modules/ims_usrloc_scscf/impurecord.c (4)
M src/modules/nat_traversal/nat_traversal.c (2)
M src/modules/xhttp_pi/xhttp_pi_fnc.c (4)
-- Patch Links --
https://github.com/kamailio/kamailio/pull/2894.patchhttps://github.com/kamailio/kamailio/pull/2894.diff
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/pull/2894
Module: kamailio
Branch: master
Commit: fe68c9aeb06f114afdc6c0b076b5163e34deeea5
URL: https://github.com/kamailio/kamailio/commit/fe68c9aeb06f114afdc6c0b076b5163…
Author: Sebastian Kemper <sebastian_ml(a)gmx.net>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2021-11-03T13:03:34+01:00
nat_traversal: use TIME_T_FMT
The size of the time_t destination is unknown as it is depending on the
platform. So we "read into a known-size integer (either int or long
long) and then assign the value to a time_t as a second step" (quote
from [1]).
[1] https://stackoverflow.com/questions/4171478/how-to-read-data-into-a-time-t-…
Signed-off-by: Sebastian Kemper <sebastian_ml(a)gmx.net>
---
Modified: src/modules/nat_traversal/nat_traversal.c
---
Diff: https://github.com/kamailio/kamailio/commit/fe68c9aeb06f114afdc6c0b076b5163…
Patch: https://github.com/kamailio/kamailio/commit/fe68c9aeb06f114afdc6c0b076b5163…
---
diff --git a/src/modules/nat_traversal/nat_traversal.c b/src/modules/nat_traversal/nat_traversal.c
index 4cfe8d4018..edaa6dfe3d 100644
--- a/src/modules/nat_traversal/nat_traversal.c
+++ b/src/modules/nat_traversal/nat_traversal.c
@@ -1707,6 +1707,7 @@ static void restore_keepalive_state(void)
unsigned h;
str host;
FILE *f;
+ long long ll_1, ll_2;
if(!keepalive_state_file)
return;
@@ -1724,7 +1725,9 @@ static void restore_keepalive_state(void)
res = fscanf(f, STATE_FILE_HEADER); // skip header
while(true) {
- res = fscanf(f, "%63s %63s %ld %ld", uri, socket, &rtime, &stime);
+ res = fscanf(f, "%63s %63s %" TIME_T_FMT " %" TIME_T_FMT, uri, socket, &ll_1, &ll_2);
+ rtime = ll_1;
+ stime = ll_2;
if(res == EOF) {
if(ferror(f))
LM_ERR("error while reading keepalive state file: %s\n",
Module: kamailio
Branch: master
Commit: 5d17337af532a03d3a36751c5d085dd542478e41
URL: https://github.com/kamailio/kamailio/commit/5d17337af532a03d3a36751c5d085dd…
Author: Sebastian Kemper <sebastian_ml(a)gmx.net>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2021-11-03T13:03:34+01:00
ims_registrar_pcscf: use TIME_T_FMT
Signed-off-by: Sebastian Kemper <sebastian_ml(a)gmx.net>
---
Modified: src/modules/ims_registrar_pcscf/notify.c
Modified: src/modules/ims_registrar_pcscf/save.c
---
Diff: https://github.com/kamailio/kamailio/commit/5d17337af532a03d3a36751c5d085dd…
Patch: https://github.com/kamailio/kamailio/commit/5d17337af532a03d3a36751c5d085dd…
---
diff --git a/src/modules/ims_registrar_pcscf/notify.c b/src/modules/ims_registrar_pcscf/notify.c
index 83c7a5c377..d8830fd2d5 100644
--- a/src/modules/ims_registrar_pcscf/notify.c
+++ b/src/modules/ims_registrar_pcscf/notify.c
@@ -209,8 +209,8 @@ int process_contact(udomain_t * _d, int expires, str contact_uri, int contact_st
/*TODO_LATEST - put this back */
} else {//state is active
//update this contact
- LM_DBG("This contact: <%.*s> is in state active and is in usrloc so just updating - old expires: %li, new expires: %i which is in %i seconds\n", contact_uri.len, contact_uri.s,
- pcontact->expires,
+ LM_DBG("This contact: <%.*s> is in state active and is in usrloc so just updating - old expires: %" TIME_T_FMT ", new expires: %i which is in %i seconds\n", contact_uri.len, contact_uri.s,
+ TIME_T_CAST(pcontact->expires),
expires,
expires - local_time_now);
if (ul.update_pcontact(_d, &ci, pcontact) != 0) {
diff --git a/src/modules/ims_registrar_pcscf/save.c b/src/modules/ims_registrar_pcscf/save.c
index 9432574005..b33a596cd2 100644
--- a/src/modules/ims_registrar_pcscf/save.c
+++ b/src/modules/ims_registrar_pcscf/save.c
@@ -223,8 +223,9 @@ static inline int update_contacts(struct sip_msg *req,struct sip_msg *rpl, udoma
}
//TODO_LATEST replace above
} else { //update contact
- LM_DBG("Updating contact: <%.*s>, old expires: %li, new expires: %i which is in %i seconds\n", c->uri.len, c->uri.s,
- pcontact->expires-local_time_now,
+ LM_DBG("Updating contact: <%.*s>, old expires: %" TIME_T_FMT ", new expires: %i which is in %i seconds\n",
+ c->uri.len, c->uri.s,
+ TIME_T_CAST(pcontact->expires-local_time_now),
expires,
expires-local_time_now);
ci.reg_state = PCONTACT_REGISTERED;
Module: kamailio
Branch: master
Commit: 71d92b26105a4e88f4fba3986a0ba306e89adc4f
URL: https://github.com/kamailio/kamailio/commit/71d92b26105a4e88f4fba3986a0ba30…
Author: Sebastian Kemper <sebastian_ml(a)gmx.net>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2021-11-03T13:03:34+01:00
ims_charging: use TIME_T_FMT
Signed-off-by: Sebastian Kemper <sebastian_ml(a)gmx.net>
---
Modified: src/modules/ims_charging/ims_ro.c
---
Diff: https://github.com/kamailio/kamailio/commit/71d92b26105a4e88f4fba3986a0ba30…
Patch: https://github.com/kamailio/kamailio/commit/71d92b26105a4e88f4fba3986a0ba30…
---
diff --git a/src/modules/ims_charging/ims_ro.c b/src/modules/ims_charging/ims_ro.c
index 0a8c53f9d9..d93d565a65 100644
--- a/src/modules/ims_charging/ims_ro.c
+++ b/src/modules/ims_charging/ims_ro.c
@@ -858,7 +858,8 @@ void send_ccr_stop_with_param(struct ro_session *ro_session, unsigned int code,
LM_DBG("Final used number of seconds for session is %ld\n", used);
}
- LM_DBG("Call started at %ld and ended at %ld and lasted %d seconds and so far we have billed for %ld seconds\n", ro_session->start_time, stop_time,
+ LM_DBG("Call started at %" TIME_T_FMT " and ended at %" TIME_T_FMT " and lasted %d seconds and so far we have billed for %ld seconds\n",
+ TIME_T_CAST(ro_session->start_time), TIME_T_CAST(stop_time),
actual_time_seconds, ro_session->billed + used);
if (ro_session->billed + used < actual_time_seconds) {
LM_DBG("Making adjustment by adding %ld seconds\n", actual_time_seconds - (ro_session->billed + used));