From d3e308240ec0f292a3cee8278f1c883f84a52a3f Mon Sep 17 00:00:00 2001 From: Samuel Pascua Date: Thu, 5 Sep 2024 22:42:49 +0800 Subject: [PATCH] Remove unnecessary cgroup switch for root Signed-off-by: Samuel Pascua --- manager/src/main/jni/cgroup.cpp | 18 ------------------ manager/src/main/jni/cgroup.h | 1 - manager/src/main/jni/starter.cpp | 31 ------------------------------- 3 files changed, 50 deletions(-) diff --git a/manager/src/main/jni/cgroup.cpp b/manager/src/main/jni/cgroup.cpp index f15c632a2..8ce5482d9 100644 --- a/manager/src/main/jni/cgroup.cpp +++ b/manager/src/main/jni/cgroup.cpp @@ -23,24 +23,6 @@ namespace cgroup { return len; } - int get_cgroup(int pid, int* cuid, int *cpid) { - char buf[PATH_MAX]; - snprintf(buf, PATH_MAX, "/proc/%d/cgroup", pid); - - int fd = open(buf, O_RDONLY); - if (fd == -1) - return -1; - - while (fdgets(buf, PATH_MAX, fd) > 0) { - if (sscanf(buf, "%*d:cpuacct:/uid_%d/pid_%d", cuid, cpid) == 2) { - close(fd); - return 0; - } - } - close(fd); - return -1; - } - int switch_cgroup(int pid) { char buf[PATH_MAX]; diff --git a/manager/src/main/jni/cgroup.h b/manager/src/main/jni/cgroup.h index 24503e7e5..71d5137fc 100644 --- a/manager/src/main/jni/cgroup.h +++ b/manager/src/main/jni/cgroup.h @@ -2,7 +2,6 @@ #define CGROUP_H namespace cgroup { - int get_cgroup(int pid, int* cuid, int *cpid); int switch_cgroup(int pid); } diff --git a/manager/src/main/jni/starter.cpp b/manager/src/main/jni/starter.cpp index 4e56fc4eb..7f8b0e2a4 100644 --- a/manager/src/main/jni/starter.cpp +++ b/manager/src/main/jni/starter.cpp @@ -145,36 +145,6 @@ static int check_selinux(const char *s, const char *t, const char *c, const char return res; } -static int switch_cgroup() { - int s_cuid, s_cpid; - int spid = getpid(); - - if (cgroup::get_cgroup(spid, &s_cuid, &s_cpid) != 0) { - printf("warn: can't read cgroup\n"); - fflush(stdout); - return -1; - } - - printf("info: cgroup is /uid_%d/pid_%d\n", s_cuid, s_cpid); - fflush(stdout); - - if (cgroup::switch_cgroup(spid) != 0) { - printf("warn: can't switch cgroup\n"); - fflush(stdout); - return -1; - } - - if (cgroup::get_cgroup(spid, &s_cuid, &s_cpid) != 0) { - printf("info: switch cgroup succeeded\n"); - fflush(stdout); - return 0; - } - - printf("warn: can't switch self, current cgroup is /uid_%d/pid_%d\n", s_cuid, s_cpid); - fflush(stdout); - return -1; -} - void redirectStd(int old_fd) { dup2(old_fd, STDIN_FILENO); dup2(old_fd, STDOUT_FILENO); @@ -275,7 +245,6 @@ int starter_main(int argc, char *argv[]) { if (uid == 0) { chown("/data/local/tmp/shizuku_starter", 2000, 2000); se::setfilecon("/data/local/tmp/shizuku_starter", "u:object_r:shell_data_file:s0"); - switch_cgroup(); int sdkLevel = 0; char buf[PROP_VALUE_MAX + 1];