@@ -117,11 +117,6 @@ FILE *metafile;
117117char cgroupname[255 ];
118118const 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-
125120char *runuser;
126121char *rungroup;
127122int 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
1292- * processes, and at least older versions of sshd seemed to set
1286+ * be made. The oom_score_adj is inherited by child
1287+ * 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