summaryrefslogtreecommitdiff
path: root/oom.h
diff options
context:
space:
mode:
Diffstat (limited to 'oom.h')
-rw-r--r--oom.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/oom.h b/oom.h
new file mode 100644
index 0000000..04d94a7
--- /dev/null
+++ b/oom.h
@@ -0,0 +1,27 @@
+#ifdef __linux__
+static void disable_oom_killer();
+
+#include <fcntl.h>
+#include <linux/oom.h>
+
+void
+disable_oom_killer()
+{
+ FILE *f;
+ const char oomfile[] = "/proc/self/oom_score_adj";
+
+ if (!(f = fopen(oomfile, "w"))) {
+ if (errno == ENOENT)
+ return;
+ die("slock: fopen %s: %s\n", oomfile, strerror(errno));
+ }
+ fprintf(f, "%d", OOM_SCORE_ADJ_MIN);
+ if (fclose(f)) {
+ if (errno == EACCES)
+ die("slock: unable to disable OOM killer. "
+ "Make sure to suid or sgid slock.\n");
+ else
+ die("slock: fclose %s: %s\n", oomfile, strerror(errno));
+ }
+}
+#endif