Skip to content

Commit 44ef4e2

Browse files
committed
2.0 code with 3.1 libcgroup
1 parent ea34b39 commit 44ef4e2

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

judge/runguard.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ void cgroup_kill()
610610
int size;
611611
do {
612612
pid_t* pids;
613-
int ret = cgroup_get_procs(cgroupname, NULL, &pids, &size);
613+
int ret = cgroup_get_procs(cgroupname, "memory", &pids, &size);
614614
if (ret != 0) error(ret, "cgroup_get_procs");
615615
for(int i = 0; i < size; i++) {
616616
kill(pids[i], SIGKILL);
@@ -646,8 +646,9 @@ void cgroup_delete()
646646
}
647647
/* Clean up our cgroup */
648648
nanosleep(&cg_delete_delay,nullptr);
649-
int ret = cgroup_delete_cgroup_ext(cg, CGFLAG_DELETE_IGNORE_MIGRATION | CGFLAG_DELETE_RECURSIVE);
650-
if ( ret!=0 ) error(ret,"deleting cgroup");
649+
int ret = cgroup_delete_cgroup_ext(cg, CGFLAG_DELETE_IGNORE_MIGRATION | CGFLAG_DELETE_RECURSIVE);
650+
// TODO: is this actually benign?
651+
if ( ret!=0 && ret!=ECGOTHER ) error(ret,"deleting cgroup");
651652

652653
cgroup_free(&cg);
653654

@@ -862,7 +863,8 @@ void setrestrictions()
862863

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

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

0 commit comments

Comments
 (0)