mirror of
https://github.com/systemd/systemd.git
synced 2026-08-03 22:50:29 +00:00
test: add explicit test for bind_remount_one_with_mountinfo()
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user