From 9837be14200fecb32db0337652e60532f1adb7be Mon Sep 17 00:00:00 2001
From: WangFengTu <wangfengtu@huawei.com>
Date: Mon, 23 May 2022 17:06:19 +0800
Subject: [PATCH 01/30] do not mkdir of isulad if no controller found

If selinux disable the capibility DAC_OVERRIDE,
mkdir isulad may fail when run container.

Signed-off-by: WangFengTu <wangfengtu@huawei.com>
---
 src/daemon/common/sysinfo.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/src/daemon/common/sysinfo.c b/src/daemon/common/sysinfo.c
index e60377dd..6fb4ec38 100644
--- a/src/daemon/common/sysinfo.c
+++ b/src/daemon/common/sysinfo.c
@@ -1303,6 +1303,21 @@ out:
     return ret;
 }
 
+#ifdef __ANDROID__
+static bool cgroup2_no_controller() {
+    char *controllers_str = NULL;
+
+    controllers_str = util_read_content_from_file(CGROUP2_CONTROLLERS_PATH);
+    if (controllers_str == NULL || strlen(controllers_str) == 0 || strcmp(controllers_str, "\n") == 0) {
+        free(controllers_str);
+        return true;
+    }
+
+    free(controllers_str);
+    return false;
+}
+#endif
+
 static int make_sure_cgroup2_isulad_path_exist()
 {
     int ret = 0;
@@ -1315,6 +1330,13 @@ static int make_sure_cgroup2_isulad_path_exist()
         return -1;
     }
 
+#ifdef __ANDROID__
+    if (cgroup2_no_controller()) {
+        DEBUG("no cgroup controller found");
+        return 0;
+    }
+#endif
+
     ret = mkdir(CGROUP_ISULAD_PATH, DEFAULT_CGROUP_DIR_MODE);
     if (ret != 0 && (errno != EEXIST || !util_dir_exists(CGROUP_ISULAD_PATH))) {
         return -1;
-- 
2.32.1 (Apple Git-133)

