Is there any reason the drift file should be mode 600?
Eric S. Raymond
esr at thyrsus.com
Thu Dec 14 01:33:33 UTC 2017
Hal Murray via devel <devel at ntpsec.org>:
> Big picture. What if we just wrote to the existing file? Are there any
> guarantees that writes that don't cross page boundaries are atomic?
Yes. A Unix write(2) under 512 bytes is atomic, and (when to a local
filesystem) can't be signal-interrupted either. There's a constant PIPE_BUF
which is historically 512 but may be larger on modern Unixes - I
haven't looked in a long time. Technically it pertains to pipe reads,
but writes that length or below are also atomic on disk filesystems.
Note that POSIX has zero guarantees on write atomicity to a file,
so this is a historical Unix property that is not guaranteed. However,
in this case we are not actually worried about contention with another
process, we just wqnt the write to not get interrupted by signal.
Don't use stdio, you can get hosed by its buffering.
> It also uses snprintf to a string buffer and then writes that to the file.
> Is there any reason not to use dprintf?
>
> My Linux man page says:
> The dprintf() and vdprintf() functions were originally GNU extensions
> that were later standardized in POSIX.1-2008.
That should be safe. Since it's going to an fd, each call probably generates
a single write(2).
Curiously, I didn't know of it before. Only standardized in 2008.
--
<a href="http://www.catb.org/~esr/">Eric S. Raymond</a>
My work is funded by the Internet Civil Engineering Institute: https://icei.org
Please visit their site and donate: the civilization you save might be your own.
More information about the devel
mailing list