diff --git a/src/conmon.c b/src/conmon.c index 9365c154..98d1fbad 100644 --- a/src/conmon.c +++ b/src/conmon.c @@ -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; @@ -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); @@ -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); } diff --git a/src/ctr_exit.c b/src/ctr_exit.c index f69ce93b..55e71a70 100644 --- a/src/ctr_exit.c +++ b/src/ctr_exit.c @@ -7,6 +7,7 @@ #include "globals.h" #include "ctr_logging.h" #include "close_fds.h" +#include "oom.h" #include #include @@ -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. */ diff --git a/src/ctr_logging.c b/src/ctr_logging.c index e5f03f38..bbae8b84 100644 --- a/src/ctr_logging.c +++ b/src/ctr_logging.c @@ -600,6 +600,8 @@ static void reopen_k8s_file(void) return; _cleanup_free_ char *k8s_log_path_tmp = g_strdup_printf("%s.tmp", k8s_log_path); + _cleanup_free_ char *k8s_log_path_tmp_old = g_strdup_printf("%s.tmp.old", k8s_log_path); + _cleanup_free_ char *k8s_log_path_old = g_strdup_printf("%s.1", k8s_log_path); /* Sync the logs to disk */ if (!opt_no_sync_log && fsync(k8s_log_fd) < 0) { @@ -614,6 +616,10 @@ static void reopen_k8s_file(void) if (k8s_log_fd < 0) pexitf("Failed to open log file %s", k8s_log_path); + unlink(k8s_log_path_tmp_old); + link(k8s_log_path, k8s_log_path_tmp_old); + rename(k8s_log_path_tmp_old, k8s_log_path_old); + /* Replace the previous file */ if (rename(k8s_log_path_tmp, k8s_log_path) < 0) { pexit("Failed to rename log file"); diff --git a/src/oom.c b/src/oom.c index 25c8dcf4..2517eef7 100644 --- a/src/oom.c +++ b/src/oom.c @@ -5,7 +5,9 @@ #include #include -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]; @@ -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); +} diff --git a/src/oom.h b/src/oom.h index cc27340a..5509f953 100644 --- a/src/oom.h +++ b/src/oom.h @@ -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