From 0481ad4472f4d7c64e3eae2272243bf1db5892d7 Mon Sep 17 00:00:00 2001 From: Jean-Vincent Ficet Date: Mon, 9 Feb 2015 16:26:00 +0100 Subject: [PATCH] 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. --- src/rrd_utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; } -- 2.47.2