Skip to content

Commit

Permalink
Merge branch 'pascua28:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
zelodev authored Sep 10, 2024
2 parents 8b4d3a0 + d3e3082 commit c8257b4
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 50 deletions.
18 changes: 0 additions & 18 deletions manager/src/main/jni/cgroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
1 change: 0 additions & 1 deletion manager/src/main/jni/cgroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define CGROUP_H

namespace cgroup {
int get_cgroup(int pid, int* cuid, int *cpid);
int switch_cgroup(int pid);
}

Expand Down
31 changes: 0 additions & 31 deletions manager/src/main/jni/starter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit c8257b4

Please sign in to comment.