summaryrefslogtreecommitdiff
path: root/oom.h
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2023-03-23 20:28:57 +0100
committerNathan Reiner <nathan@nathanreiner.xyz>2023-03-23 20:28:57 +0100
commitdace7dca77e9539b5cb459f79c1154d11b3030fe (patch)
treefbd3bc83e15c7b8d7e41dc351a7a50cfc0164c2f /oom.h
first version of wlock
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