Another posix file system question

Kevin D. Clark kevin_d_clark at comcast.net
Wed Feb 27 14:02:35 EST 2013


Bill Freeman writes:

> Scenario,
> 
> Apache or nginx is serving a file, in response to an AJAX request, because
> serving static files is fast.  The file contains data to be displayed on a
> web page (via jQueryUI bar graphs, among, if that's of interest).
> 
> While I might come up with a scheme for updating file contents in place
> (open for writing,don't truncate, seek, write), I would feel less as hazard
> if I wrote a new file and swapped it in under the the same directory entry.
> 
> (Hopefully, if the server tends to cache static files in memory, it at
> least does a stat on the file name at each request, to see if the
> modification time has changed.)
> 
> The plan is to create a new file under a different name, then hard link the
> critical name to the new file.
> 
> I know that I can use 'ln -f' on the command line, but I don't know whether
> that turns into an unlink followed by a link, leaving a tiny window during
> which the critical name doesn't exist, or whether (other than updating link
> counts) this just does the equivalent of writing a new inode number into
> the directory entry.

This plan isn't going to work, because the call to link() is going to
fail with EEXIST.

Instead of using link(), you should use rename(), which has all of the
atomic semantics that you seem to be looking for.  Think of this as
being like double-buffering, on your fs.

Regards,

--kevin
-- 
alumni.unh.edu!kdc / http://kdc-blog.blogspot.com/
GnuPG: D87F DAD6 0291 289C EB1E 781C 9BF8 A7D8 B280 F24E

And the Army Ants, they leave nothin' but the bones...
   -- Tom Waits


More information about the gnhlug-discuss mailing list