summaryrefslogtreecommitdiffstats
path: root/lib/puppet/util/autoload.rb
diff options
context:
space:
mode:
authorBrice Figureau <brice-puppet@daysofwonder.com>2010-10-16 15:10:28 +0200
committerJames Turnbull <james@lovedthanlost.net>2010-11-10 12:56:38 +1100
commit9ba0c8a22c6f9ca856851ef6c2d38242754a7a00 (patch)
treed88e59636def09219d5fd1b8ac159b7e91b43482 /lib/puppet/util/autoload.rb
parentcb16d3dcbad47e832890fe869e3d4f9c7224434c (diff)
downloadpuppet-9ba0c8a22c6f9ca856851ef6c2d38242754a7a00.tar.gz
puppet-9ba0c8a22c6f9ca856851ef6c2d38242754a7a00.tar.xz
puppet-9ba0c8a22c6f9ca856851ef6c2d38242754a7a00.zip
Fix #4923 - close process race when truncating existing file
Using File.open(file, "w") calls open(2) with O_CREAT|O_TRUNC which means when the file exists it is immediately truncated. But the file is not locked yet, so another process can either write or read to the file, leading to file corruption. The fix is to truncate only when the file is exclusively locked. This can be done on some operating system with O_EXLOCK open(2) flag. I chose the more portable option of: * open * flock * truncate * write * close It might also be good to flush and fsync the file after writing it, otherwise in case of crash an incomplete file can stay on disk. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
Diffstat (limited to 'lib/puppet/util/autoload.rb')
0 files changed, 0 insertions, 0 deletions