]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-process-util: port to detach_mount_namespace()
authorLennart Poettering <lennart@poettering.net>
Mon, 13 Mar 2023 14:22:38 +0000 (15:22 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 14 Mar 2023 08:39:28 +0000 (17:39 +0900)
src/test/test-process-util.c

index 9a0c15dffe4475307b799f43acb522537102e032..fc0d25ea2b7002e9b71f5078d89e1d7ae0adebf7 100644 (file)
@@ -25,6 +25,7 @@
 #include "macro.h"
 #include "missing_sched.h"
 #include "missing_syscall.h"
+#include "namespace-util.h"
 #include "parse-util.h"
 #include "process-util.h"
 #include "procfs-util.h"
@@ -244,6 +245,7 @@ TEST(get_process_cmdline_harder) {
         _cleanup_close_ int fd = -EBADF;
         _cleanup_free_ char *line = NULL;
         pid_t pid;
+        int r;
 
         if (geteuid() != 0) {
                 log_info("Skipping %s: not root", __func__);
@@ -278,11 +280,11 @@ TEST(get_process_cmdline_harder) {
         }
 
         assert_se(pid == 0);
-        assert_se(unshare(CLONE_NEWNS) >= 0);
 
-        if (mount(NULL, "/", NULL, MS_SLAVE|MS_REC, NULL) < 0) {
-                log_warning_errno(errno, "mount(..., \"/\", MS_SLAVE|MS_REC, ...) failed: %m");
-                assert_se(IN_SET(errno, EPERM, EACCES));
+        r = detach_mount_namespace();
+        if (r < 0) {
+                log_warning_errno(r, "detach mount namespace failed: %m");
+                assert_se(ERRNO_IS_PRIVILEGE(r));
                 return;
         }