syslog() timestamps not respecting timezone

Dan Raymond draymond@foxvalley.net
Tue Mar 9 23:45:07 GMT 2021


I noticed an issue with syslog() timestamps.  When a client generates a 
timestamp inside a call to syslog() it uses localtime_r().  When the 
server (syslogd) generates a timestamp it uses localtime().  The 
observable difference is that localtime() checks the timezone settings 
while localtime_r() does not.  Hence if you change the timezone settings 
while syslogd is running: server-generated timestamps will be correct 
while client-generated timestamps will be incorrect.

Is this something that should be fixed?  There are various ways to 
mitigate the problem but none are ideal:

1) reboot or restart all processes using syslog() after changing the 
timezone (this may not be possible/practical)

2) call tzset() from all processes using syslog() after changing the 
timezone (not likely to be possible)

3) start syslogd with -t command line option to disable client-generated 
timestamps (timestamp accuracy is decreased)

On the other hand, switching from localtime_r() to localtime() inside 
syslog() could adversely impact performance.  For instance it could 
incur an additional call to stat('/etc/localtime', ...) for each call to 
syslog().  This cost would be avoided if the calling process sets the TZ 
environment variable, however, since only changes to TZ would 
subsequently trigger a filesystem access.  Thoughts?



More information about the Libc-alpha mailing list