X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;ds=sidebyside;f=src%2Fshared%2Fmkdir.c;h=43c6ea6d4a1616bc85775fb48418be8c52fbc6e8;hb=fb15be839500c39f6c2f006f45306d439e1a7add;hp=e21a0f398949fd90d614c07a2f0e600a0ebb2cf3;hpb=4ad490007b70e6ac18d3cb04fa2ed92eba1451fa;p=elogind.git diff --git a/src/shared/mkdir.c b/src/shared/mkdir.c index e21a0f398..43c6ea6d4 100644 --- a/src/shared/mkdir.c +++ b/src/shared/mkdir.c @@ -31,14 +31,10 @@ #include "path-util.h" #include "mkdir.h" -int mkdir_label(const char *path, mode_t mode) { - return label_mkdir(path, mode, true); -} - -static int mkdir_safe_internal(const char *path, mode_t mode, uid_t uid, gid_t gid, bool apply) { +int mkdir_safe_internal(const char *path, mode_t mode, uid_t uid, gid_t gid, mkdir_func_t _mkdir) { struct stat st; - if (label_mkdir(path, mode, apply) >= 0) + if (_mkdir(path, mode) >= 0) if (chmod_and_chown(path, mode, uid, gid) < 0) return -errno; @@ -57,11 +53,7 @@ static int mkdir_safe_internal(const char *path, mode_t mode, uid_t uid, gid_t g } int mkdir_safe(const char *path, mode_t mode, uid_t uid, gid_t gid) { - return mkdir_safe_internal(path, mode, uid, gid, false); -} - -int mkdir_safe_label(const char *path, mode_t mode, uid_t uid, gid_t gid) { - return mkdir_safe_internal(path, mode, uid, gid, true); + return mkdir_safe_internal(path, mode, uid, gid, mkdir); } static int is_dir(const char* path) { @@ -73,7 +65,7 @@ static int is_dir(const char* path) { return S_ISDIR(st.st_mode); } -static int mkdir_parents_internal(const char *prefix, const char *path, mode_t mode, bool apply) { +int mkdir_parents_internal(const char *prefix, const char *path, mode_t mode, mkdir_func_t _mkdir) { const char *p, *e; int r; @@ -116,34 +108,26 @@ static int mkdir_parents_internal(const char *prefix, const char *path, mode_t m if (prefix && path_startswith(prefix, t)) continue; - r = label_mkdir(t, mode, apply); + r = _mkdir(t, mode); if (r < 0 && errno != EEXIST) return -errno; } } int mkdir_parents(const char *path, mode_t mode) { - return mkdir_parents_internal(NULL, path, mode, false); -} - -int mkdir_parents_label(const char *path, mode_t mode) { - return mkdir_parents_internal(NULL, path, mode, true); -} - -int mkdir_parents_prefix(const char *prefix, const char *path, mode_t mode) { - return mkdir_parents_internal(prefix, path, mode, true); + return mkdir_parents_internal(NULL, path, mode, mkdir); } -static int mkdir_p_internal(const char *prefix, const char *path, mode_t mode, bool apply) { +int mkdir_p_internal(const char *prefix, const char *path, mode_t mode, mkdir_func_t _mkdir) { int r; /* Like mkdir -p */ - r = mkdir_parents_internal(prefix, path, mode, apply); + r = mkdir_parents_internal(prefix, path, mode, _mkdir); if (r < 0) return r; - r = label_mkdir(path, mode, apply); + r = _mkdir(path, mode); if (r < 0 && (errno != EEXIST || is_dir(path) <= 0)) return -errno; @@ -151,13 +135,9 @@ static int mkdir_p_internal(const char *prefix, const char *path, mode_t mode, b } int mkdir_p(const char *path, mode_t mode) { - return mkdir_p_internal(NULL, path, mode, false); -} - -int mkdir_p_label(const char *path, mode_t mode) { - return mkdir_p_internal(NULL, path, mode, true); + return mkdir_p_internal(NULL, path, mode, mkdir); } int mkdir_p_prefix(const char *prefix, const char *path, mode_t mode) { - return mkdir_p_internal(prefix, path, mode, false); + return mkdir_p_internal(prefix, path, mode, mkdir); }