diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2023-03-23 20:28:57 +0100 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2023-03-23 20:28:57 +0100 |
| commit | dace7dca77e9539b5cb459f79c1154d11b3030fe (patch) | |
| tree | fbd3bc83e15c7b8d7e41dc351a7a50cfc0164c2f /oom.h | |
first version of wlock
Diffstat (limited to 'oom.h')
| -rw-r--r-- | oom.h | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -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 |