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 submitted this change and it was merged. ( 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, 8 insertions(+), 5 deletions(-)
Approvals:
pespin: Looks good to me, approved
laforge: Looks good to me, but someone else must approve
fixeria: Looks good to me, but someone else must approve
Jenkins Builder: Verified
diff --git a/src/logging.c b/src/logging.c
index 4c86473..1c3544f 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -359,15 +359,18 @@
OSMO_SNPRINTF_RET(ret, rem, offset, len);
#endif
} else if (target->print_timestamp) {
- char *timestr;
time_t tm;
if ((tm = time(NULL)) == (time_t) -1)
goto err;
- timestr = ctime(&tm);
- timestr[strlen(timestr)-1] = '\0';
- ret = snprintf(buf + offset, rem, "%s ", timestr);
- if (ret < 0)
+ /* Get human-readable representation of time.
+ man ctime: we need at least 26 bytes in buf */
+ if (rem < 26 || !ctime_r(&tm, buf + offset))
goto err;
+ ret = strlen(buf + offset);
+ if (ret <= 0)
+ goto err;
+ /* Get rid of useless final '\n' added by ctime_r. We want a space instead. */
+ buf[offset + ret - 1] = ' ';
OSMO_SNPRINTF_RET(ret, rem, offset, len);
}
if (target->print_category) {
--
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: 4
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <axilirator at gmail.com>
Gerrit-Reviewer: laforge <laforge at gnumonks.org>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190613/e3071d4c/attachment.htm>