4 ms·
Both of those are the wrong way to do it. :) O_TRUNC for the reasons you stated and unlink because it causes a race between the unlink and the copy when a new
by zrm 9y ago
Both of those are the wrong way to do it. :)
O_TRUNC for the reasons you stated and unlink because it causes a race between the unlink and the copy when a new process that tries to use the library will either fail because it doesn't exist or get a copy of the library that isn't completely written yet.
The correct way to do it is to write the new file to the same filesystem at a different path and then, once it's completely written, move it to the intended path. Move (i.e. rename(2)) is atomic on sane filesystems so anything that opens the file will get one complete copy or the other.