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.
return -1;
}
#else
- if (0 != mkdir(pathname, mode)) {
+ if ((mkdir(pathname, mode) != 0) && (errno != EEXIST)) {
free(pathname);
return -1;
}