mkdir(2) function returns EROFS error even when the path already exists on
the read only file system, so it is impossible to determine whether the path
already exists on this kind of fs only be return code from the mkdir(2). To make
cg_mkdir_p() compatible with the ro fs, the function checks whether the
path exists with stat(2) before trying to create it.
Signed-off-by: Peter Schiffer <pschiffe@redhat.com>
Acked-By: Jan Safranek <jsafrane@redhat.com>
char *real_path = NULL;
int i = 0;
char pos;
- int ret = 0;
+ int ret = 0, stat_ret;
+ struct stat st;
real_path = strdup(path);
if (!real_path) {
ret = ECGROUPNOTOWNER;
goto done;
default:
+ /* Check if path exists */
+ real_path[i] = '\0';
+ stat_ret = stat(real_path, &st);
+ real_path[i] = pos;
+ if (stat_ret == 0) {
+ ret = 0; /* Path exists */
+ break;
+ }
ret = ECGROUPNOTALLOWED;
goto done;
}