This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
pespin gerrit-no-reply at lists.osmocom.orgpespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/14429
Change subject: logging: Use reentrant ctime_r instead of ctime
......................................................................
logging: Use reentrant ctime_r instead of ctime
It was noticed that multithreaded processes like osmo-trx can crash upon
using ctime().
Related: OS#4055
Change-Id: I19ebf29a2f1fc855bb7d56766b338c7c3432dfd1
---
M src/logging.c
1 file changed, 7 insertions(+), 4 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/29/14429/1
diff --git a/src/logging.c b/src/logging.c
index 73a9c52..b8960f9 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -359,12 +359,15 @@
OSMO_SNPRINTF_RET(ret, rem, offset, len);
#endif
} else if (target->print_timestamp) {
- char *timestr;
+ /* man ctime: user-supplied buffer should have room for at least 26 bytes */
+ char ctime_buf[26];
time_t tm;
tm = time(NULL);
- timestr = ctime(&tm);
- timestr[strlen(timestr)-1] = '\0';
- ret = snprintf(buf + offset, rem, "%s ", timestr);
+ if (!ctime_r(&tm, ctime_buf))
+ goto err;
+ /* Remove new line char atthe end added by ctime */
+ ctime_buf[strlen(ctime_buf)-1] = '\0';
+ ret = snprintf(buf + offset, rem, "%s ", ctime_buf);
if (ret < 0)
goto err;
OSMO_SNPRINTF_RET(ret, rem, offset, len);
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/14429
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I19ebf29a2f1fc855bb7d56766b338c7c3432dfd1
Gerrit-Change-Number: 14429
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190612/3c06f2bd/attachment.htm>