summaryrefslogtreecommitdiffstats
path: root/src/daemon.c
diff options
context:
space:
mode:
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>2017-03-30 00:32:34 +0300
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>2017-03-30 00:32:34 +0300
commit58863a7f5aab111df0b63adb48518ddf55317dd8 (patch)
tree3382466abd703396ea68b0069ca8b94352bab10d /src/daemon.c
parent89c7b84058d36bedca07cb8ddd4a89336460a539 (diff)
allow user to set out of memory score via environment and disable it in configuration file; fixes #2036
Diffstat (limited to 'src/daemon.c')
-rw-r--r--src/daemon.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/src/daemon.c b/src/daemon.c
index 42b04c4019..d839c859c6 100644
--- a/src/daemon.c
+++ b/src/daemon.c
@@ -155,22 +155,42 @@ int become_user(const char *username, int pid_fd)
return(0);
}
+#ifndef OOM_SCORE_ADJ_MAX
+#define OOM_SCORE_ADJ_MAX 1000
+#endif
+#ifndef OOM_SCORE_ADJ_MIN
+#define OOM_SCORE_ADJ_MIN -1000
+#endif
+
static void oom_score_adj(void) {
- int score = (int)config_get_number(CONFIG_SECTION_GLOBAL, "OOM score", 1000);
+ char buf[10 + 1];
+ snprintfz(buf, 10, "%d", OOM_SCORE_ADJ_MAX);
+
+ // check the environment
+ char *s = getenv("OOMScoreAdjust");
+ if(!s || !*s) s = buf;
+
+ // check netdata.conf configuration
+ s = config_get(CONFIG_SECTION_GLOBAL, "OOM score", s);
+ if(!s || !*s) s = buf;
+
+ if(!isdigit(*s) && *s != '-' && *s != '+') {
+ info("Out-Of-Memory score not changed due to setting: '%s'", s);
+ return;
+ }
int done = 0;
int fd = open("/proc/self/oom_score_adj", O_WRONLY);
if(fd != -1) {
- char buf[10 + 1];
- ssize_t len = snprintfz(buf, 10, "%d", score);
+ ssize_t len = strlen(s);
if(len > 0 && write(fd, buf, (size_t)len) == len) done = 1;
close(fd);
}
if(!done)
- error("Cannot adjust my Out-Of-Memory score to %d.", score);
+ error("Cannot adjust my Out-Of-Memory score to '%s'.", s);
else
- debug(D_SYSTEM, "Adjusted my Out-Of-Memory score to %d.", score);
+ info("Adjusted my Out-Of-Memory score to '%s'.", s);
}
static void process_nice_level(void) {