From: Jean-Vincent Ficet Date: Mon, 9 Feb 2015 15:26:00 +0000 (+0100) Subject: rrd_utils: Fix broken recusive directory creation in multithreaded context X-Git-Tag: v1.7.0~38^2~1 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=0481ad4472f4d7c64e3eae2272243bf1db5892d7;p=thirdparty%2Frrdtool-1.x.git rrd_utils: Fix broken recusive directory creation in multithreaded context 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. --- diff --git a/src/rrd_utils.c b/src/rrd_utils.c index 27b6c3bb..430d92e7 100644 --- a/src/rrd_utils.c +++ b/src/rrd_utils.c @@ -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; }