X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=udev_utils_file.c;h=9ab34705e2dd70c1d0becdc64c8db13439458273;hp=9bf60696d94ed74d9ddd79d5b854e918154dc1c2;hb=6056d9b3400fe0349d86636cbbf93f069bb5639a;hpb=27b77df44daebbd7597c572343105c16de099233 diff --git a/udev_utils_file.c b/udev_utils_file.c index 9bf60696d..9ab34705e 100644 --- a/udev_utils_file.c +++ b/udev_utils_file.c @@ -35,26 +35,35 @@ int create_path(const char *path) char p[PATH_SIZE]; char *pos; struct stat stats; + int ret; - strcpy (p, path); + strlcpy(p, path, sizeof(p)); pos = strrchr(p, '/'); if (pos == p || pos == NULL) return 0; while (pos[-1] == '/') pos--; - pos[0] = '\0'; - dbg("stat '%s'\n", p); + dbg("stat '%s'", p); if (stat(p, &stats) == 0 && (stats.st_mode & S_IFMT) == S_IFDIR) return 0; - if (create_path (p) != 0) + if (create_path(p) != 0) return -1; - dbg("mkdir '%s'\n", p); - return mkdir(p, 0755); + dbg("mkdir '%s'", p); + selinux_setfscreatecon(p, NULL, S_IFDIR|0755); + ret = mkdir(p, 0755); + selinux_resetfscreatecon(); + if (ret == 0) + return 0; + + if (errno == EEXIST) + if (stat(p, &stats) == 0 && (stats.st_mode & S_IFMT) == S_IFDIR) + return 0; + return -1; } int delete_path(const char *path) @@ -65,6 +74,9 @@ int delete_path(const char *path) strcpy (p, path); pos = strrchr(p, '/'); + if (pos == p || pos == NULL) + return 0; + while (1) { *pos = '\0'; pos = strrchr(p, '/');