Sunday, March 06, 2016

[yosbwdgf] The danger of writing Unix time to a file

If a computer is configured to use the right counter instead of the POSIX counter, it must be very careful when interoperating with computers which use the POSIX counter, for example, if a timestamp (encoded as a counter value) is written to a file on removable storage or a network filesystem, then read by another computer.

The most conservative solution for the time() system call to always return the POSIX counter value regardless of what the kernel counts.  If the kernel counts with the right counter, then time() is kind of an expensive call, needing to look up the latest leap second information to do the conversion.  During a leap second, especially for subsecond precision, do whatever weird thing is deemed acceptable.

Applications which explicitly need the right counter should call a new system call to get that value.  Kernels which do not count the right counter can emulate the call, using the POSIX counter and a lookup of leap second information to calculate the value, or the call can simply fail as not provided.  It will necessarily not give a good answer during a leap second.

Instead of writing or transmitting the POSIX (or right) counter, consider using a more portable representation of date and time.

No comments :