Skip to content

Commit

Permalink
2.0 code with 3.1 libcgroup
Browse files Browse the repository at this point in the history
  • Loading branch information
meisterT committed Jun 7, 2024
1 parent ea34b39 commit 44ef4e2
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions judge/runguard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ void cgroup_kill()
int size;
do {
pid_t* pids;
int ret = cgroup_get_procs(cgroupname, NULL, &pids, &size);
int ret = cgroup_get_procs(cgroupname, "memory", &pids, &size);
if (ret != 0) error(ret, "cgroup_get_procs");
for(int i = 0; i < size; i++) {
kill(pids[i], SIGKILL);
Expand Down Expand Up @@ -646,8 +646,9 @@ void cgroup_delete()
}
/* Clean up our cgroup */
nanosleep(&cg_delete_delay,nullptr);
int ret = cgroup_delete_cgroup_ext(cg, CGFLAG_DELETE_IGNORE_MIGRATION | CGFLAG_DELETE_RECURSIVE);
if ( ret!=0 ) error(ret,"deleting cgroup");
int ret = cgroup_delete_cgroup_ext(cg, CGFLAG_DELETE_IGNORE_MIGRATION | CGFLAG_DELETE_RECURSIVE);
// TODO: is this actually benign?
if ( ret!=0 && ret!=ECGOTHER ) error(ret,"deleting cgroup");

cgroup_free(&cg);

Expand Down Expand Up @@ -862,7 +863,8 @@ void setrestrictions()

/* Put the child process in the cgroup */
if (is_cgroup_v2) {
if (cgroup_change_cgroup_path(cgroupname, getpid(), NULL) != 0) {
const char *controllers[] = { "memory", NULL };
if (cgroup_change_cgroup_path(cgroupname, getpid(), controllers) != 0) {
error(0, "Failed to move the process to the cgroup");
}
} else {
Expand Down Expand Up @@ -1351,6 +1353,7 @@ int main(int argc, char **argv)
error(errno,"cannot start `%s'",cmdname);

default: /* become watchdog */
verbose("child pid = %d", child_pid);
/* Shed privileges, only if not using a separate child uid,
because in that case we may need root privileges to kill
the child process. Do not use Linux specific setresuid()
Expand Down

0 comments on commit 44ef4e2

Please sign in to comment.