5 ms·
[pulled up from some levels of reply down] No, the behavior is not correct, because changing /etc/localtime is an asynchronous operation. You're changing a fi
by eqvinox 4y ago
[pulled up from some levels of reply down]
No, the behavior is not correct, because changing /etc/localtime is an asynchronous operation. You're changing a file in the file system and expecting to observe a change in a running process. It's, by design, racy — and that's OK.
Taking this into account, the correct behavior is to keep a timestamp of when the last stat() call was, and only stat() again if it was longer than X ago. Even a few seonds would clamp down the stat syscall rate to ambient noise.
(NB: changing /etc/localtime, and then starting a new process is not asynchronous. But that's not the issue here. Two processes are doing things here — changing /etc/localtime and invoking localtime() without synchronization. You shouldn't, can't and mustn't rely on ordering of such unsynchronized events.)
- zajio1am 4y ago> No, the behavior is not correct, because changing /etc/localtime is an asynchronous operation Well, technically you can do both from the same process (i.e. localtime(), unlink() + symlink() to change /etc/localtime, another localtime()), in that case it would be synchronous. But in general i agree, if the timeout was small enough (say < 100 ms) i guess nobody would object.