]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: add explicit test for bind_remount_one_with_mountinfo() 19101/head
authorLennart Poettering <lennart@poettering.net>
Wed, 24 Mar 2021 12:45:25 +0000 (13:45 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 26 Mar 2021 10:51:26 +0000 (11:51 +0100)
src/test/test-mount-util.c

index 29f462bfab9ba4838dfa7bdd1b2b625f81312ff8..2e9116d359dbeb9306f99a75a844541dd70d5753 100644 (file)
@@ -125,11 +125,43 @@ static void test_bind_remount_recursive(void) {
         }
 }
 
+static void test_bind_remount_one(void) {
+        pid_t pid;
+
+        if (geteuid() != 0) {
+                (void) log_tests_skipped("not running as root");
+                return;
+        }
+
+        pid = fork();
+        assert_se(pid >= 0);
+
+        if (pid == 0) {
+                /* child */
+
+                _cleanup_fclose_ FILE *proc_self_mountinfo = NULL;
+
+                assert_se(detach_mount_namespace() >= 0);
+
+                assert_se(fopen_unlocked("/proc/self/mountinfo", "re", &proc_self_mountinfo) >= 0);
+
+                assert_se(bind_remount_one_with_mountinfo("/run", MS_RDONLY, MS_RDONLY, proc_self_mountinfo) >= 0);
+                assert_se(bind_remount_one_with_mountinfo("/proc/idontexist", MS_RDONLY, MS_RDONLY, proc_self_mountinfo) == -ENOENT);
+                assert_se(bind_remount_one_with_mountinfo("/proc/self", MS_RDONLY, MS_RDONLY, proc_self_mountinfo) == -EINVAL);
+                assert_se(bind_remount_one_with_mountinfo("/", MS_RDONLY, MS_RDONLY, proc_self_mountinfo) >= 0);
+
+                _exit(EXIT_SUCCESS);
+        }
+
+        assert_se(wait_for_terminate_and_check("test-remount-one", pid, WAIT_LOG) == EXIT_SUCCESS);
+}
+
 int main(int argc, char *argv[]) {
         test_setup_logging(LOG_DEBUG);
 
         test_mount_option_mangle();
         test_bind_remount_recursive();
+        test_bind_remount_one();
 
         return 0;
 }