[CRIU] [PATCH 1/3] util: Make mkdirpat more generic

Cyrill Gorcunov gorcunov at openvz.org
Fri Nov 18 06:51:22 PST 2016


 - take @mode into account
 - return system error codes on error

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 criu/cgroup.c       | 2 +-
 criu/include/util.h | 2 +-
 criu/util.c         | 9 +++++----
 3 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/criu/cgroup.c b/criu/cgroup.c
index 5f8e84e13f93..48850573f947 100644
--- a/criu/cgroup.c
+++ b/criu/cgroup.c
@@ -1510,7 +1510,7 @@ static int prepare_cgroup_dirs(char **controllers, int n_controllers, char *paux
 				return -1;
 			}
 
-			if (mkdirpat(cg, paux)) {
+			if (mkdirpat(cg, paux, 0755)) {
 				pr_perror("Can't make cgroup dir %s", paux);
 				return -1;
 			}
diff --git a/criu/include/util.h b/criu/include/util.h
index 8eaee33391c5..62f9733cc30e 100644
--- a/criu/include/util.h
+++ b/criu/include/util.h
@@ -247,7 +247,7 @@ static inline bool issubpath(const char *path, const char *sub_path)
 /*
  * mkdir -p
  */
-int mkdirpat(int fd, const char *path);
+int mkdirpat(int fd, const char *path, int mode);
 
 /*
  * Tests whether a path is a prefix of another path. This is different than
diff --git a/criu/util.c b/criu/util.c
index 2cf03556441e..6ba787edd299 100644
--- a/criu/util.c
+++ b/criu/util.c
@@ -801,14 +801,14 @@ struct vma_area *alloc_vma_area(void)
 	return p;
 }
 
-int mkdirpat(int fd, const char *path)
+int mkdirpat(int fd, const char *path, int mode)
 {
 	size_t i;
 	char made_path[PATH_MAX], *pos;
 
 	if (strlen(path) >= PATH_MAX) {
 		pr_err("path %s is longer than PATH_MAX\n", path);
-		return -1;
+		return -ENOSPC;
 	}
 
 	strcpy(made_path, path);
@@ -821,9 +821,10 @@ int mkdirpat(int fd, const char *path)
 		pos = strchr(made_path + i, '/');
 		if (pos)
 			*pos = '\0';
-		if (mkdirat(fd, made_path, 0755) < 0 && errno != EEXIST) {
+		if (mkdirat(fd, made_path, mode) < 0 && errno != EEXIST) {
+			int ret = -errno;
 			pr_perror("couldn't mkdirpat directory %s", made_path);
-			return -1;
+			return ret;
 		}
 		if (pos) {
 			*pos = '/';
-- 
2.7.4



More information about the CRIU mailing list