]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic,shared: move make_mount_point_inode_*() to shared/
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 21 Jun 2021 17:44:35 +0000 (19:44 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 23 Jun 2021 08:34:58 +0000 (10:34 +0200)
Those pull in selinux for labelling, and we should avoid selinux in basic/.

src/basic/mountpoint-util.c
src/basic/mountpoint-util.h
src/shared/mount-util.c
src/shared/mount-util.h
src/test/test-mount-util.c
src/test/test-mountpoint-util.c

index 1d617e87b276a97946230feb350e157bf5163ea4..8c836a1b74e6f6e8582a146fa933476ee1c8d9b7 100644 (file)
@@ -8,7 +8,6 @@
 #include "fd-util.h"
 #include "fileio.h"
 #include "fs-util.h"
-#include "label.h"
 #include "missing_stat.h"
 #include "missing_syscall.h"
 #include "mkdir.h"
@@ -510,25 +509,3 @@ int mount_propagation_flags_from_string(const char *name, unsigned long *ret) {
                 return -EINVAL;
         return 0;
 }
-
-int make_mount_point_inode_from_stat(const struct stat *st, const char *dest, mode_t mode) {
-        assert(st);
-        assert(dest);
-
-        if (S_ISDIR(st->st_mode))
-                return mkdir_label(dest, mode);
-        else
-                return mknod(dest, S_IFREG|(mode & ~0111), 0);
-}
-
-int make_mount_point_inode_from_path(const char *source, const char *dest, mode_t mode) {
-        struct stat st;
-
-        assert(source);
-        assert(dest);
-
-        if (stat(source, &st) < 0)
-                return -errno;
-
-        return make_mount_point_inode_from_stat(&st, dest, mode);
-}
index cebcec5e78852ff15fc1cfd6cae90a70baa8b4db..aadb2123d91680003cf9dd687c1628c1ddc16083 100644 (file)
@@ -23,7 +23,3 @@ int dev_is_devtmpfs(void);
 
 const char *mount_propagation_flags_to_string(unsigned long flags);
 int mount_propagation_flags_from_string(const char *name, unsigned long *ret);
-
-/* Creates a mount point (not parents) based on the source path or stat - ie, a file or a directory */
-int make_mount_point_inode_from_stat(const struct stat *st, const char *dest, mode_t mode);
-int make_mount_point_inode_from_path(const char *source, const char *dest, mode_t mode);
index ef128dd5955b203d772808b6e539e2f55aa45f9d..ff95fbc569b7120e3ef6a19d015f698348687fee 100644 (file)
@@ -16,6 +16,7 @@
 #include "fileio.h"
 #include "fs-util.h"
 #include "hashmap.h"
+#include "label.h"
 #include "libmount-util.h"
 #include "missing_mount.h"
 #include "missing_syscall.h"
@@ -1071,3 +1072,25 @@ int remount_idmap(
 
         return 0;
 }
+
+int make_mount_point_inode_from_stat(const struct stat *st, const char *dest, mode_t mode) {
+        assert(st);
+        assert(dest);
+
+        if (S_ISDIR(st->st_mode))
+                return mkdir_label(dest, mode);
+        else
+                return mknod(dest, S_IFREG|(mode & ~0111), 0);
+}
+
+int make_mount_point_inode_from_path(const char *source, const char *dest, mode_t mode) {
+        struct stat st;
+
+        assert(source);
+        assert(dest);
+
+        if (stat(source, &st) < 0)
+                return -errno;
+
+        return make_mount_point_inode_from_stat(&st, dest, mode);
+}
index 0169083980d7d95e7d09917b1c77d60d68c8e469..36501c2c4a6757f6ebe1df202328b175edd24c07 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <mntent.h>
 #include <stdio.h>
+#include <sys/stat.h>
 #include <unistd.h>
 
 #include "alloc-util.h"
@@ -108,3 +109,7 @@ int mount_image_in_namespace(pid_t target, const char *propagate_path, const cha
 int make_mount_point(const char *path);
 
 int remount_idmap(const char *p, uid_t uid_shift, uid_t uid_range);
+
+/* Creates a mount point (not parents) based on the source path or stat - ie, a file or a directory */
+int make_mount_point_inode_from_stat(const struct stat *st, const char *dest, mode_t mode);
+int make_mount_point_inode_from_path(const char *source, const char *dest, mode_t mode);
index 0cbf68aa00b840f25cb29a3450754c4d1e79a761..d3d004071bb92b626fab54412cc4650812c7bece 100644 (file)
@@ -7,7 +7,9 @@
 #include "capability-util.h"
 #include "fd-util.h"
 #include "fileio.h"
+#include "fs-util.h"
 #include "missing_mount.h"
+#include "mkdir.h"
 #include "mount-util.h"
 #include "namespace-util.h"
 #include "path-util.h"
@@ -217,6 +219,52 @@ static void test_bind_remount_one(void) {
         assert_se(wait_for_terminate_and_check("test-remount-one", pid, WAIT_LOG) == EXIT_SUCCESS);
 }
 
+static void test_make_mount_point_inode(void) {
+        _cleanup_(rm_rf_physical_and_freep) char *d = NULL;
+        const char *src_file, *src_dir, *dst_file, *dst_dir;
+        struct stat st;
+
+        log_info("/* %s */", __func__);
+
+        assert_se(mkdtemp_malloc(NULL, &d) >= 0);
+
+        src_file = strjoina(d, "/src/file");
+        src_dir = strjoina(d, "/src/dir");
+        dst_file = strjoina(d, "/dst/file");
+        dst_dir = strjoina(d, "/dst/dir");
+
+        assert_se(mkdir_p(src_dir, 0755) >= 0);
+        assert_se(mkdir_parents(dst_file, 0755) >= 0);
+        assert_se(touch(src_file) >= 0);
+
+        assert_se(make_mount_point_inode_from_path(src_file, dst_file, 0755) >= 0);
+        assert_se(make_mount_point_inode_from_path(src_dir, dst_dir, 0755) >= 0);
+
+        assert_se(stat(dst_dir, &st) == 0);
+        assert_se(S_ISDIR(st.st_mode));
+        assert_se(stat(dst_file, &st) == 0);
+        assert_se(S_ISREG(st.st_mode));
+        assert_se(!(S_IXUSR & st.st_mode));
+        assert_se(!(S_IXGRP & st.st_mode));
+        assert_se(!(S_IXOTH & st.st_mode));
+
+        assert_se(unlink(dst_file) == 0);
+        assert_se(rmdir(dst_dir) == 0);
+
+        assert_se(stat(src_file, &st) == 0);
+        assert_se(make_mount_point_inode_from_stat(&st, dst_file, 0755) >= 0);
+        assert_se(stat(src_dir, &st) == 0);
+        assert_se(make_mount_point_inode_from_stat(&st, dst_dir, 0755) >= 0);
+
+        assert_se(stat(dst_dir, &st) == 0);
+        assert_se(S_ISDIR(st.st_mode));
+        assert_se(stat(dst_file, &st) == 0);
+        assert_se(S_ISREG(st.st_mode));
+        assert_se(!(S_IXUSR & st.st_mode));
+        assert_se(!(S_IXGRP & st.st_mode));
+        assert_se(!(S_IXOTH & st.st_mode));
+}
+
 int main(int argc, char *argv[]) {
         test_setup_logging(LOG_DEBUG);
 
@@ -224,6 +272,7 @@ int main(int argc, char *argv[]) {
         test_mount_flags_to_string();
         test_bind_remount_recursive();
         test_bind_remount_one();
+        test_make_mount_point_inode();
 
         return 0;
 }
index 128daa6de89e7b6b0e4a67bdd480a11481f486c3..983e1842d6c8c0ac0302d2ecb0f6355da92b57dc 100644 (file)
@@ -8,10 +8,8 @@
 #include "def.h"
 #include "fd-util.h"
 #include "fileio.h"
-#include "fs-util.h"
 #include "hashmap.h"
 #include "log.h"
-#include "mkdir.h"
 #include "mountpoint-util.h"
 #include "path-util.h"
 #include "rm-rf.h"
@@ -290,52 +288,6 @@ static void test_fd_is_mount_point(void) {
         assert_se(IN_SET(fd_is_mount_point(fd, "root/", 0), -ENOENT, 0));
 }
 
-static void test_make_mount_point_inode(void) {
-        _cleanup_(rm_rf_physical_and_freep) char *d = NULL;
-        const char *src_file, *src_dir, *dst_file, *dst_dir;
-        struct stat st;
-
-        log_info("/* %s */", __func__);
-
-        assert_se(mkdtemp_malloc(NULL, &d) >= 0);
-
-        src_file = strjoina(d, "/src/file");
-        src_dir = strjoina(d, "/src/dir");
-        dst_file = strjoina(d, "/dst/file");
-        dst_dir = strjoina(d, "/dst/dir");
-
-        assert_se(mkdir_p(src_dir, 0755) >= 0);
-        assert_se(mkdir_parents(dst_file, 0755) >= 0);
-        assert_se(touch(src_file) >= 0);
-
-        assert_se(make_mount_point_inode_from_path(src_file, dst_file, 0755) >= 0);
-        assert_se(make_mount_point_inode_from_path(src_dir, dst_dir, 0755) >= 0);
-
-        assert_se(stat(dst_dir, &st) == 0);
-        assert_se(S_ISDIR(st.st_mode));
-        assert_se(stat(dst_file, &st) == 0);
-        assert_se(S_ISREG(st.st_mode));
-        assert_se(!(S_IXUSR & st.st_mode));
-        assert_se(!(S_IXGRP & st.st_mode));
-        assert_se(!(S_IXOTH & st.st_mode));
-
-        assert_se(unlink(dst_file) == 0);
-        assert_se(rmdir(dst_dir) == 0);
-
-        assert_se(stat(src_file, &st) == 0);
-        assert_se(make_mount_point_inode_from_stat(&st, dst_file, 0755) >= 0);
-        assert_se(stat(src_dir, &st) == 0);
-        assert_se(make_mount_point_inode_from_stat(&st, dst_dir, 0755) >= 0);
-
-        assert_se(stat(dst_dir, &st) == 0);
-        assert_se(S_ISDIR(st.st_mode));
-        assert_se(stat(dst_file, &st) == 0);
-        assert_se(S_ISREG(st.st_mode));
-        assert_se(!(S_IXUSR & st.st_mode));
-        assert_se(!(S_IXGRP & st.st_mode));
-        assert_se(!(S_IXOTH & st.st_mode));
-}
-
 int main(int argc, char *argv[]) {
         test_setup_logging(LOG_DEBUG);
 
@@ -360,7 +312,6 @@ int main(int argc, char *argv[]) {
         test_mnt_id();
         test_path_is_mount_point();
         test_fd_is_mount_point();
-        test_make_mount_point_inode();
 
         return 0;
 }