52b84b
From 15ab55eca3d1f7feb86e55bdc147069f36d198eb Mon Sep 17 00:00:00 2001
be3800
From: Yu Watanabe <watanabe.yu+github@gmail.com>
be3800
Date: Fri, 14 Sep 2018 15:51:04 +0900
be3800
Subject: [PATCH] test-fs-util: skip some tests when running in unprivileged
be3800
 container
be3800
be3800
(cherry picked from commit 9590065f37be040996f1c2b9a246b9952fdc0c0b)
be3800
52b84b
Resolves: #1823767
be3800
---
be3800
 src/test/test-fs-util.c | 9 ++++++++-
be3800
 1 file changed, 8 insertions(+), 1 deletion(-)
be3800
be3800
diff --git a/src/test/test-fs-util.c b/src/test/test-fs-util.c
be3800
index 7b7990bb70..e3338ea440 100644
be3800
--- a/src/test/test-fs-util.c
be3800
+++ b/src/test/test-fs-util.c
be3800
@@ -17,6 +17,7 @@
be3800
 #include "strv.h"
be3800
 #include "user-util.h"
be3800
 #include "util.h"
be3800
+#include "virt.h"
be3800
 
be3800
 static void test_chase_symlinks(void) {
be3800
         _cleanup_free_ char *result = NULL;
be3800
@@ -468,6 +469,7 @@ static void test_touch_file(void) {
be3800
         struct stat st;
be3800
         const char *a;
be3800
         usec_t test_mtime;
be3800
+        int r;
be3800
 
be3800
         test_uid = geteuid() == 0 ? 65534 : getuid();
be3800
         test_gid = geteuid() == 0 ? 65534 : getgid();
be3800
@@ -517,7 +519,12 @@ static void test_touch_file(void) {
be3800
 
be3800
         if (geteuid() == 0) {
be3800
                 a = strjoina(p, "/cdev");
be3800
-                assert_se(mknod(a, 0775 | S_IFCHR, makedev(0, 0)) >= 0);
be3800
+                r = mknod(a, 0775 | S_IFCHR, makedev(0, 0));
be3800
+                if (r < 0 && errno == EPERM && detect_container() > 0) {
be3800
+                        log_notice("Running in unprivileged container? Skipping remaining tests in %s", __func__);
be3800
+                        return;
be3800
+                }
be3800
+                assert_se(r >= 0);
be3800
                 assert_se(touch_file(a, false, test_mtime, test_uid, test_gid, 0640) >= 0);
be3800
                 assert_se(lstat(a, &st) >= 0);
be3800
                 assert_se(st.st_uid == test_uid);