From: Lennart Poettering Date: Wed, 24 Mar 2021 12:45:25 +0000 (+0100) Subject: test: add explicit test for bind_remount_one_with_mountinfo() X-Git-Tag: v249-rc1~502^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F19101%2Fhead;p=thirdparty%2Fsystemd.git test: add explicit test for bind_remount_one_with_mountinfo() --- diff --git a/src/test/test-mount-util.c b/src/test/test-mount-util.c index 29f462bfab9..2e9116d359d 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; }