Skip to content

Commit 42e432f

Browse files
committed
Drop support for "/proc/self/oom_adj" OOM killer adjustment path.
Also make move variable declarations locally to help with understanding the code without jumping around in the file, as well as some minor readability improvements. "/proc/self/oom_adj" has been introduced in Linux kernel commit a63d83f427fbce97a6cea0db2e64b0eb8435cd10 and is available since kernel version 2.6.36, so no need to support both anymore.
1 parent df48ff8 commit 42e432f

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

judge/runguard.cc

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,6 @@ FILE *metafile;
117117
char cgroupname[255];
118118
const char *cpuset;
119119

120-
/* Linux Out-Of-Memory adjustment for current process. */
121-
#define OOM_PATH_NEW "/proc/self/oom_score_adj"
122-
#define OOM_PATH_OLD "/proc/self/oom_adj"
123-
#define OOM_RESET_VALUE 0
124-
125120
char *runuser;
126121
char *rungroup;
127122
int runuid;
@@ -1288,24 +1283,23 @@ int main(int argc, char **argv)
12881283
}
12891284

12901285
/* Check if any Linux Out-Of-Memory killer adjustments have to
1291-
* be made. The oom_adj or oom_score_adj is inherited by child
1286+
* be made. The oom_score_adj is inherited by child
12921287
* processes, and at least some configurations of sshd set
12931288
* it, leading to processes getting a timelimit instead of memory
12941289
* exceeded, when running via SSH. */
12951290
FILE *fp = nullptr;
1296-
char *oom_path;
1297-
if ( !fp && (fp = fopen(OOM_PATH_NEW,"r+")) ) oom_path = strdup(OOM_PATH_NEW);
1298-
if ( !fp && (fp = fopen(OOM_PATH_OLD,"r+")) ) oom_path = strdup(OOM_PATH_OLD);
1299-
if ( fp!=nullptr ) {
1300-
if ( fscanf(fp,"%d",&ret)!=1 ) error(errno,"cannot read from `%s'",oom_path);
1291+
const char *oom_score_path = "/proc/self/oom_score_adj";
1292+
if ( fp = fopen(oom_score_path, "r+") ) {
1293+
if ( fscanf(fp,"%d", &ret)!=1 ) error(errno,"cannot read from `%s'", oom_score_path);
13011294
if ( ret<0 ) {
1302-
verbose("resetting `%s' from %d to %d",oom_path,ret,OOM_RESET_VALUE);
1295+
int oom_reset_value = 0;
1296+
verbose("resetting `%s' from %d to %d", oom_score_path, ret, oom_reset_value);
13031297
rewind(fp);
1304-
if ( fprintf(fp,"%d\n",OOM_RESET_VALUE)<=0 ) {
1305-
error(errno,"cannot write to `%s'",oom_path);
1298+
if ( fprintf(fp,"%d\n", oom_reset_value) <= 0 ) {
1299+
error(errno, "cannot write to `%s'", oom_score_path);
13061300
}
13071301
}
1308-
if ( fclose(fp)!=0 ) error(errno,"closing file `%s'",oom_path);
1302+
if ( fclose(fp)!=0 ) error(errno, "closing file `%s'", oom_score_path);
13091303
}
13101304

13111305
switch ( child_pid = fork() ) {

0 commit comments

Comments
 (0)