[tpm] Renaming a file with multiple scripts having opened filehandles on it
Madison Kelly
linux at alteeve.com
Fri Oct 2 20:53:48 PDT 2009
Uri Guttman wrote:
>>>>>> "LREQ" == Liam R E Quin <liam at holoweb.net> writes:
>
> LREQ> On Fri, 2009-10-02 at 20:44 -0400, Madison Kelly wrote:
> >> [...] I noticed that if a second program/thread
> >> had an open file handle on the log file being 'rename'ed, it would
> >> follow the log file to the new name. This makes sense, now that I think
> >> of it (I am guessing it tracks the inode?).
>
>
> LREQ> This is platform specific, but yes, on Unix-like systems, if you
> LREQ> rename a file, something writing to that file will continue to write
> LREQ> to it under the new name. On a Unix (and Linux) file system,
> LREQ> the directory entries (e.g. for "/etc/group" I mean the "group"
> LREQ> entry in the "/etc" directory) just point to where the data is
> LREQ> stored - this is why when you use "ln group fizz", there are
> LREQ> now two names for the same data, and if you remove either one,
> LREQ> the other remains behind. This is different from symbolic links,
> LREQ> ln -s, of course.
>
> >>
> >> What I want to do though is have some way for other threads recognize
> >> that the file name has changed.
>
> LREQ> You'd have to notify them, e.g. with a shared variable or a signal of
> LREQ> some sort.
>
> this is also why the best loggers use a server to do the logging and the
> programs send log message to it. then you only have one program opening
> and writing to the log files and you can manage/rotate them
> cleanly. having multiple processes logging to the same file is a poor
> design. one other way around it besides a shared variable or such is to
> mark the log dir with a flag file. this can be checked each time a
> process wants to write to the log file. it will slow things down but
> allow for the current design to work with log rotation.
>
> uri
>
Thank you both. I think I might try setting up a DBus-based server that
does nothing more that listen for messages and triggers
cycle'ing/truncating/whatever.
Madi
More information about the toronto-pm
mailing list