From 84f5f5923d8109366b2c3caf66ad7c2d89be38bd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Manuel=20Luis=20Sanmart=C3=ADn=20Rozada?= Date: Wed, 20 May 2015 17:10:41 +0200 Subject: [PATCH] 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. --- src/utils_rrdcreate.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) 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); } } -- 2.30.2