chiark / gitweb /
shared: add formats-util.h
[elogind.git] / src / shared / mkdir-label.c
index c41045e5b54da96058936b3a75fb6418bba38513..221dd67eb2f139346370cc21bdd68af34f30261b 100644 (file)
@@ -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
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <assert.h>
-#include <string.h>
+#include <fcntl.h>
 #include <unistd.h>
-#include <errno.h>
 #include <stdlib.h>
 #include <stdio.h>
 
-#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 (use_selinux()) {
-                r = label_mkdir_selinux(path, mode);
-                if (r < 0)
-                        return r;
-        }
+        fd = open_tmpfile(p, O_RDWR|O_CLOEXEC);
+        assert_se(fd >= 0);
 
-        if (use_smack()) {
-                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 = smack_relabel_in_dev(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);
-}