-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
syslog: fix crash when print localtime by syslog #4032
Conversation
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
@Donny9 What was the problem with this? I tried it, but I didn't have any kind of "crash", it worked OK for me. I am following the changes, but I don't understand the functional changes this PR brings. It seems to me only "styling" changes are made. Can you please elaborate on the issue and the solution? Also, to my understanding this PR introduces a bug. Also, why ingore the return code of the various calls in |
Hello @fjpanag , you need to enable follow config, then use syslog to output log with localtime in origin code base. The root cause of cash is that the localtime_r can't be called before OSINIT_HW_READY, because localtime_r will call sem_wait, but semaphore subsystem is uninitialized. |
The key change is move localtime_r/gmtime_r into if (OSINIT_HW_READY()).
ts and tm is initialized to zero at line 74-76 and 79-81.
The sane value(zero) set at the definition. |
@Donny9 I now understand the issue, thank you! @xiaoxiang781216 You are correct. |
Yes, CONFIG_LIBC_LOCATIME is enabled in our product to convert UTC to local time correclty, which is seldom selected in the demo project. That's why the problem is found until now. |
Summary
syslog: fix crash when print localtime by syslog
test need to enable config:
CONFIG_LIBC_LOCATIME=y
CONFIG_SYSLOG_TIMESTAMP_FORMATTED=y
CONFIG_SYSLOG_TIMESTAMP_LOCALTIME=y
CONFIG_SYSLOG_TIMESTAMP_REALTIME=y
Change-Id: I322830e0818237a7eb65a158a6a0dea8f9da9b6c
Signed-off-by: Jiuzhu Dong dongjiuzhu1@xiaomi.com
Impact
output local time in syslog.
Testing
daily test.