Re: savelog can lose data
Neil Schemenauer <firstname.lastname@example.org> writes:
>I think a better solution is to copy the data from the current
>log file and then truncate it. There is a race condition with
>this approach. If something is written to the log file between
>the copying and the truncating then that data will be lost. The
>time between these two operations should be very small (echo is
>built into bash). Attached is a patch that makes savelog do
>this (against slink).
>+ # there is a race here
>+ cp "$filename" "$newname.0"
>+ echo -n > "$filename"
Using echo is unnecessary. You can truncate the file with the command
I expect you could reduce the probability of losing data by
(1) doing the copy and truncate in a separate process, with large
(2) combining them in one line:
cp "$filename" "$newname.0" && > "$filename"
- Jim Van Zandt