X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Fmkdir-label.c;h=221dd67eb2f139346370cc21bdd68af34f30261b;hb=30ab6a0fc1bb950c4dcd90dcd3dfe00a810c7fc1;hp=48941b3df44789912ff2a0f163deea1d5f57534c;hpb=c80d766c8072dd0be311dcd31c17f9719775be44;p=elogind.git diff --git a/src/shared/mkdir-label.c b/src/shared/mkdir-label.c index 48941b3df..221dd67eb 100644 --- a/src/shared/mkdir-label.c +++ b/src/shared/mkdir-label.c @@ -3,8 +3,7 @@ /*** This file is part of systemd. - Copyright 2010 Lennart Poettering - Copyright 2013 Kay Sievers + Copyright 2014 Zbigniew Jędrzejewski-Szmek systemd is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -20,56 +19,32 @@ along with systemd; If not, see . ***/ -#include -#include +#include #include -#include #include #include -#include "label.h" #include "util.h" -#include "path-util.h" -#include "mkdir.h" +#include "formats-util.h" -static int label_mkdir(const char *path, mode_t mode) { - int r; +int main(int argc, char** argv) { + const char *p = argv[1] ?: "/tmp"; + char *pattern = strjoina(p, "/systemd-test-XXXXXX"); + _cleanup_close_ int fd, fd2; + _cleanup_free_ char *cmd, *cmd2; - if (mac_selinux_use()) { - r = mac_selinux_mkdir(path, mode); - if (r < 0) - return r; - } + fd = open_tmpfile(p, O_RDWR|O_CLOEXEC); + assert_se(fd >= 0); - if (mac_smack_use()) { - r = mkdir(path, mode); - if (r < 0 && errno != EEXIST) - return -errno; + assert_se(asprintf(&cmd, "ls -l /proc/"PID_FMT"/fd/%d", getpid(), fd) > 0); + system(cmd); - r = mac_smack_fix(path); - if (r < 0) - return r; - } + fd2 = mkostemp_safe(pattern, O_RDWR|O_CLOEXEC); + assert_se(fd >= 0); + assert_se(unlink(pattern) == 0); - r = mkdir(path, mode); - if (r < 0 && errno != EEXIST) - return -errno; + assert_se(asprintf(&cmd2, "ls -l /proc/"PID_FMT"/fd/%d", getpid(), fd2) > 0); + system(cmd2); return 0; } - -int mkdir_label(const char *path, mode_t mode) { - return label_mkdir(path, mode); -} - -int mkdir_safe_label(const char *path, mode_t mode, uid_t uid, gid_t gid) { - return mkdir_safe_internal(path, mode, uid, gid, label_mkdir); -} - -int mkdir_parents_label(const char *path, mode_t mode) { - return mkdir_parents_internal(NULL, path, mode, label_mkdir); -} - -int mkdir_p_label(const char *path, mode_t mode) { - return mkdir_p_internal(NULL, path, mode, label_mkdir); -}