Add an old cgroup v2 path

https://android-review.googlesource.com/c/platform/system/core/+/1324649
This commit is contained in:
vvb2060 2021-09-20 13:15:16 +08:00 committed by John Wu
parent 43d11d877d
commit 2e299b3814

View File

@ -257,19 +257,20 @@ done:
close(client); close(client);
} }
static int switch_cgroup(const char *cgroup, int pid) { static void switch_cgroup(const char *cgroup, int pid) {
char buf[32]; char buf[32];
snprintf(buf, sizeof(buf), "%s/cgroup.procs", cgroup); snprintf(buf, sizeof(buf), "%s/cgroup.procs", cgroup);
int fd = open(buf, O_WRONLY | O_APPEND | O_CLOEXEC); if (access(buf, F_OK) != 0)
return;
int fd = xopen(buf, O_WRONLY | O_APPEND | O_CLOEXEC);
if (fd == -1) if (fd == -1)
return -1; return;
snprintf(buf, sizeof(buf), "%d\n", pid); snprintf(buf, sizeof(buf), "%d\n", pid);
if (xwrite(fd, buf, strlen(buf)) == -1) { if (xwrite(fd, buf, strlen(buf)) == -1) {
close(fd); close(fd);
return -1; return;
} }
close(fd); close(fd);
return 0;
} }
static void daemon_entry() { static void daemon_entry() {
@ -302,8 +303,9 @@ static void daemon_entry() {
// Escape from cgroup // Escape from cgroup
int pid = getpid(); int pid = getpid();
if (switch_cgroup("/acct", pid) && switch_cgroup("/sys/fs/cgroup", pid)) switch_cgroup("/acct", pid);
LOGW("Can't switch cgroup\n"); switch_cgroup("/dev/cg2_bpf", pid);
switch_cgroup("/sys/fs/cgroup", pid);
// Get self stat // Get self stat
char buf[64]; char buf[64];