Skip to content

Commit

Permalink
Merge pull request #2245 from haircommander/oom_backport-1.14
Browse files Browse the repository at this point in the history
[1.14] various oom backports
  • Loading branch information
Mrunal Patel committed Apr 11, 2019
2 parents 38a624d + 9661047 commit c54f783
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions conmon/conmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,10 +486,12 @@ static gboolean oom_cb(int fd, GIOCondition condition, G_GNUC_UNUSED gpointer us
}

if (num_read > 0) {
_cleanup_close_ int oom_fd = -1;
if (num_read != sizeof(uint64_t))
nwarn("Failed to read full oom event from eventfd");
ninfo("OOM received");
if (open("oom", O_CREAT, 0666) < 0) {
oom_fd = open("oom", O_CREAT, 0666);
if (oom_fd < 0) {
nwarn("Failed to write oom file");
}
return G_SOURCE_CONTINUE;
Expand Down Expand Up @@ -955,19 +957,6 @@ int main(int argc, char *argv[])
int fds[2];
int oom_score_fd = -1;

oom_score_fd = open("/proc/self/oom_score_adj", O_WRONLY);
if (oom_score_fd < 0) {
g_print("failed to open /proc/self/oom_score_adj: %s\n", strerror(errno));
} else {
if (write(oom_score_fd, OOM_SCORE, strlen(OOM_SCORE)) < 0) {
g_print("failed to write to /proc/self/oom_score_adj: %s\n", strerror(errno));
}
close(oom_score_fd);
}


main_loop = g_main_loop_new(NULL, FALSE);

/* Command line parameters */
context = g_option_context_new("- conmon utility");
g_option_context_add_main_entries(context, opt_entries, "conmon");
Expand All @@ -986,6 +975,18 @@ int main(int argc, char *argv[])
}

set_conmon_logs(opt_log_level, opt_cid, opt_syslog);
oom_score_fd = open("/proc/self/oom_score_adj", O_WRONLY);
if (oom_score_fd < 0) {
ndebugf("failed to open /proc/self/oom_score_adj: %s\n", strerror(errno));
} else {
if (write(oom_score_fd, OOM_SCORE, strlen(OOM_SCORE)) < 0) {
ndebugf("failed to write to /proc/self/oom_score_adj: %s\n", strerror(errno));
}
close(oom_score_fd);
}


main_loop = g_main_loop_new(NULL, FALSE);

if (opt_restore_path && opt_exec)
nexit("Cannot use 'exec' and 'restore' at the same time.");
Expand Down

0 comments on commit c54f783

Please sign in to comment.