From: Manuel Luis SanmartĂ­n Rozada Date: Wed, 20 May 2015 15:10:41 +0000 (+0200) Subject: In rrd synchronous file creation use lock_file X-Git-Tag: collectd-5.5.1~110^2~6 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=84f5f5923d8109366b2c3caf66ad7c2d89be38bd;p=collectd.git In rrd synchronous file creation use lock_file to prevent the creation of the same file at the same time multiple times and obtain a corrupt rrd file. --- diff --git a/src/utils_rrdcreate.c b/src/utils_rrdcreate.c index 5368059e..da4a944a 100644 --- a/src/utils_rrdcreate.c +++ b/src/utils_rrdcreate.c @@ -704,18 +704,32 @@ int cu_rrd_create_file (const char *filename, /* {{{ */ } else /* synchronous */ { - status = srrd_create (filename, stepsize, last_up, - argc, (const char **) argv); - + status = lock_file (filename); if (status != 0) { - WARNING ("cu_rrd_create_file: srrd_create (%s) returned status %i.", - filename, status); + if (status == EEXIST) + NOTICE ("cu_rrd_create_file: File \"%s\" is already being created.", + filename); + else + ERROR ("cu_rrd_create_file: Unable to lock file \"%s\".", + filename); } else { - DEBUG ("cu_rrd_create_file: Successfully created RRD file \"%s\".", - filename); + status = srrd_create (filename, stepsize, last_up, + argc, (const char **) argv); + + if (status != 0) + { + WARNING ("cu_rrd_create_file: srrd_create (%s) returned status %i.", + filename, status); + } + else + { + DEBUG ("cu_rrd_create_file: Successfully created RRD file \"%s\".", + filename); + } + unlock_file (filename); } }