Skip to content

Commit

Permalink
Set oom_score_adj to 0 for all enroot processes
Browse files Browse the repository at this point in the history
Fixes #120

Signed-off-by: Felix Abecassis <[email protected]>
  • Loading branch information
flx42 committed Aug 18, 2023
1 parent 6c21574 commit a54c99c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions enroot.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pid_t enroot_exec(uid_t uid, gid_t gid, int log_fd,
int ret;
int null_fd = -1;
int target_fd = -1;
int oom_score_fd = -1;
pid_t pid;
char *argv_str;

Expand Down Expand Up @@ -59,6 +60,16 @@ pid_t enroot_exec(uid_t uid, gid_t gid, int log_fd,
if (ret < 0)
_exit(EXIT_FAILURE);

/*
* Attempt to set oom_score_adj to 0, as it's often set to -1000 (OOM killing
* disabled), inherited from slurmstepd or slurmd.
*/
oom_score_fd = open("/proc/self/oom_score_adj", O_CLOEXEC | O_WRONLY | O_APPEND);
if (oom_score_fd >= 0) {
dprintf(oom_score_fd, "%d", 0);
close(oom_score_fd);
}

ret = setregid(gid, gid);
if (ret < 0)
_exit(EXIT_FAILURE);
Expand Down

0 comments on commit a54c99c

Please sign in to comment.