From 67d22a366567df874352099ff38083ffb3024d72 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 24 Mar 2021 13:45:25 +0100 Subject: [PATCH] test: add explicit test for bind_remount_one_with_mountinfo() --- src/test/test-mount-util.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/test/test-mount-util.c b/src/test/test-mount-util.c index 29f462bfab..2e9116d359 100644 --- a/src/test/test-mount-util.c +++ b/src/test/test-mount-util.c @@ -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; } -- 2.25.1