]> git.itanic.dy.fi Git - rrdd/commit
rrdtool_draw_image: Avoid corrupting image files
authorTimo Kokkonen <timo.t.kokkonen@iki.fi>
Wed, 11 Apr 2012 17:46:29 +0000 (20:46 +0300)
committerTimo Kokkonen <timo.t.kokkonen@iki.fi>
Wed, 11 Apr 2012 18:00:47 +0000 (21:00 +0300)
commit0ca317f750710a96dd1f8dffe1c6d05eb258bb2e
tree7bcacf6fb827f6b2f21991686bc0a989cc26f40e
parent3c45ddba581f306628e0df9ac7dc3a1c5c508f95
rrdtool_draw_image: Avoid corrupting image files

As rrdtool is creating the image file it does appear to modify always
the contents of the existing file. This leads to a potential race
condition where someone is reading the current image contents and then
rrdtool changes the contents while the reader is still in the process
of the reading the old contents. If that happens, the image file
appears to be corrupted due to the fact that it contains a mixture of
the old and new image data.

Fix the issue by creating a temporary file where the image is created
and then replacing the target file with the temp file only after
rrdtool has finished drawing all of the image. This ensures reader
will be accessing either the old or new image contents, newer
something that is a mixture of those two.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
rrdtool.c