Skip to content

Commit 89fe096

Browse files
committed
Always use cgroups in runguard.
There is no benefit in not using them, the library needs to be installed anyway to be able to compile runguard and it makes the flow in runguard more consistent.
1 parent c4daa9d commit 89fe096

File tree

1 file changed

+3
-29
lines changed

1 file changed

+3
-29
lines changed

judge/runguard.c

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,6 @@ Run COMMAND with restrictions.\n\
375375
Note that root privileges are needed for the `root' and `user' options.\n\
376376
If `user' is set, then `group' defaults to the same to prevent security\n\
377377
issues, since otherwise the process would retain group root permissions.\n\
378-
Additionally, Linux cgroup support is required for the `memsize', `cpuset'\n\
379-
and `cputime' options, and to report actual memory usage.\n\
380378
The COMMAND path is relative to the changed ROOT directory if specified.\n\
381379
TIME may be specified as a float; two floats separated by `:' are treated\n\
382380
as soft and hard limits. The runtime written to file is that of the last\n\
@@ -444,22 +442,10 @@ void output_exit_time(int exitcode, double cpudiff)
444442
write_meta("time-result","%s",output_timelimit_str[timelimit_reached]);
445443
}
446444

447-
/* Return whether we need to use cgroups. This is checked in the
448-
* cgroup_* functions below. If not used they return without
449-
* performing any action.
450-
*/
451-
int use_cgroup()
452-
{
453-
return use_cputime || memsize!=RLIM_INFINITY ||
454-
( cpuset!=NULL && strlen(cpuset)>0 );
455-
}
456-
457445
void check_remaining_procs()
458446
{
459447
char path[1024];
460448

461-
if ( !use_cgroup() ) return;
462-
463449
snprintf(path, 1023, "/sys/fs/cgroup/cpuacct%scgroup.procs", cgroupname);
464450
FILE *file = fopen(path, "r");
465451
if (file == NULL) {
@@ -480,8 +466,6 @@ void output_cgroup_stats(double *cputime)
480466
struct cgroup *cg;
481467
struct cgroup_controller *cg_controller;
482468

483-
if ( !use_cgroup() ) return;
484-
485469
if ( (cg = cgroup_new_cgroup(cgroupname))==NULL ) error(0,"cgroup_new_cgroup");
486470
if ((ret = cgroup_get_cgroup(cg)) != 0) error(ret,"get cgroup information");
487471

@@ -512,8 +496,6 @@ void cgroup_create()
512496
struct cgroup *cg;
513497
struct cgroup_controller *cg_controller;
514498

515-
if ( !use_cgroup() ) return;
516-
517499
cg = cgroup_new_cgroup(cgroupname);
518500
if (!cg) error(0,"cgroup_new_cgroup");
519501

@@ -560,8 +542,6 @@ void cgroup_attach()
560542
int ret;
561543
struct cgroup *cg;
562544

563-
if ( !use_cgroup() ) return;
564-
565545
cg = cgroup_new_cgroup(cgroupname);
566546
if (!cg) error(0,"cgroup_new_cgroup");
567547

@@ -579,8 +559,6 @@ void cgroup_kill()
579559
void *handle = NULL;
580560
pid_t pid;
581561

582-
if ( !use_cgroup() ) return;
583-
584562
/* kill any remaining tasks, and wait for them to be gone */
585563
while(1) {
586564
ret = cgroup_get_task_begin(cgroupname, "memory", &handle, &pid);
@@ -595,8 +573,6 @@ void cgroup_delete()
595573
int ret;
596574
struct cgroup *cg;
597575

598-
if ( !use_cgroup() ) return;
599-
600576
cg = cgroup_new_cgroup(cgroupname);
601577
if (!cg) error(0,"cgroup_new_cgroup");
602578

@@ -1198,11 +1174,9 @@ int main(int argc, char **argv)
11981174
}
11991175
}
12001176
/* Make libcgroup ready for use */
1201-
if ( use_cgroup() ) {
1202-
ret = cgroup_init();
1203-
if ( ret!=0 ) {
1204-
error(0,"libcgroup initialization failed: %s(%d)\n", cgroup_strerror(ret), ret);
1205-
}
1177+
ret = cgroup_init();
1178+
if ( ret!=0 ) {
1179+
error(0,"libcgroup initialization failed: %s(%d)\n", cgroup_strerror(ret), ret);
12061180
}
12071181
/* Define the cgroup name that we will use and make sure it will
12081182
* be unique. Note: group names must have slashes!

0 commit comments

Comments
 (0)