[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[logrotate] File handling questions.

I'm looking at the source to `logrotate'.  It opens the log file, and
then creates a new file, and does a read/write loop to copy the log
file over to the new one, then uses `ftrunctate' to truncate the log

Tell me if I'm wrong... but if the `logrotate' process runs out of
time, a process switch happens, (or just happens at the same time, on
an SMP box), then `syslogd' runs and writes to the file, right after
the copy, but before the truncate, won't there be data loss?

I thought what you're supposed to do is `rename(3)' the log file,
since `rename(3)' is atomic, then create a new file with the original
name, and then HUP the daemon, which MUST have a signal handler for
SIGHUP that flags it to close the file descriptor on that logfile,
then reopen it under the same name.  Since the fd is a pointer into
the file table... (it goes not through the name of the file, but
straight to it's inode, which `rename' obviously doesn't modify), the
syslogd or other daemon won't lose any data; it can keep on writing,
and the data will still go to the original, now renamed, file.

Perhaps they wanted to make it so a SIGHUP handler wouldn't be needed
in every daemon... but that's what `syslogd' was invented for.

Any comments or ideas?


Reply to: