daandemeyer / rpms / systemd

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