Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

oom-score: restore oom score before running exit command #464

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/conmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ int main(int argc, char *argv[])
_cleanup_gerror_ GError *err = NULL;
char buf[BUF_SIZE];
int num_read;
int old_oom_score = 0;
_cleanup_close_ int dev_null_r_cleanup = -1;
_cleanup_close_ int dev_null_w_cleanup = -1;
_cleanup_close_ int dummyfd = -1;
Expand All @@ -55,7 +54,7 @@ int main(int argc, char *argv[])

process_cli();

attempt_oom_adjust(-1000, &old_oom_score);
attempt_oom_adjust(-1000);

/* ignoring SIGPIPE prevents conmon from being spuriously killed */
signal(SIGPIPE, SIG_IGN);
Expand Down Expand Up @@ -295,7 +294,7 @@ int main(int argc, char *argv[])
}

// We don't want runc to be unkillable so we reset the oom_score_adj back to 0
attempt_oom_adjust(old_oom_score, NULL);
reset_oom_adjust();
execv(g_ptr_array_index(runtime_argv, 0), (char **)runtime_argv->pdata);
exit(127);
}
Expand Down
3 changes: 3 additions & 0 deletions src/ctr_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "globals.h"
#include "ctr_logging.h"
#include "close_fds.h"
#include "oom.h"

#include <errno.h>
#include <glib.h>
Expand Down Expand Up @@ -201,6 +202,8 @@ void do_exit_command()
sleep(opt_exit_delay);
}

reset_oom_adjust();

execv(opt_exit_command, args);

/* Should not happen, but better be safe. */
Expand Down
14 changes: 13 additions & 1 deletion src/oom.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#include <string.h>
#include <unistd.h>

void attempt_oom_adjust(int oom_score, int *old_value)
int old_oom_score = 0;

static void write_oom_adjust(int oom_score, int *old_value)
{
#ifdef __linux__
char fmt_oom_score[16];
Expand All @@ -30,3 +32,13 @@ void attempt_oom_adjust(int oom_score, int *old_value)
(void)old_value;
#endif
}

void attempt_oom_adjust(int oom_score)
{
write_oom_adjust(oom_score, &old_oom_score);
}

void reset_oom_adjust()
{
write_oom_adjust(old_oom_score, NULL);
}
3 changes: 2 additions & 1 deletion src/oom.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#if !defined(OOM_H)
#define OOM_H

void attempt_oom_adjust(int oom_score, int *old_value);
void attempt_oom_adjust(int oom_score);
void reset_oom_adjust();

#endif // OOM_H
Loading