]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
rrd_utils: Fix broken recusive directory creation in multithreaded context
authorJean-Vincent Ficet <jean-vincent.ficet@bull.net>
Mon, 9 Feb 2015 15:26:00 +0000 (16:26 +0100)
committerMarek Schimara <Marek.Schimara@bull.net>
Wed, 24 Aug 2016 08:03:29 +0000 (10:03 +0200)
Multithreaded applications can issue CREATE commands simultaneously
from several threads. Such commands may require to create directories
from the same root path.

Example:

Thread #1 creates /var/cache/rrd/data/switch/isw61/board0/chip1/port1
Thread #2 creates /var/cache/rrd/data/switch/isw61/board0/chip1/port3

If 2 threads attempt to create the above directories, one thread may
fail when creating a directory already created by the other thread.

The mkdir syscall fails with an error (errno = EEXIST), which causes
the whole CREATE transaction to fail.

Fixed by checking errno after invoking mkdir when creating
directories recursively.

src/rrd_utils.c

index 27b6c3bbde8ead138f39a7f214cd9c10a77fecff..430d92e7d7c9f3d68dfbfb867ae2291b8d2d6aab 100644 (file)
@@ -222,7 +222,7 @@ int rrd_mkdir_p(const char *pathname_unsafe, mode_t mode)
         return -1;
     }
 #else
-    if (0 != mkdir(pathname, mode)) {
+    if ((mkdir(pathname, mode) != 0) && (errno != EEXIST)) {
         free(pathname);
         return -1;
     }