diff options
-rw-r--r-- | slock.c | 22 |
1 files changed, 15 insertions, 7 deletions
@@ -65,19 +65,27 @@ die(const char *errstr, ...) | |||
65 | 65 | ||
66 | #ifdef __linux__ | 66 | #ifdef __linux__ |
67 | #include <fcntl.h> | 67 | #include <fcntl.h> |
68 | #include <linux/oom.h> | ||
68 | 69 | ||
69 | static void | 70 | static void |
70 | dontkillme(void) | 71 | dontkillme(void) |
71 | { | 72 | { |
72 | int fd; | 73 | FILE *f; |
74 | const char oomfile[] = "/proc/self/oom_score_adj"; | ||
73 | 75 | ||
74 | fd = open("/proc/self/oom_score_adj", O_WRONLY); | 76 | if (!(f = fopen(oomfile, "w"))) { |
75 | if (fd < 0 && errno == ENOENT) { | 77 | if (errno == ENOENT) |
76 | return; | 78 | return; |
79 | die("slock: fopen %s: %s\n", oomfile, strerror(errno)); | ||
77 | } | 80 | } |
78 | if (fd < 0 || write(fd, "-1000\n", (sizeof("-1000\n") - 1)) != | 81 | fprintf(f, "%d", OOM_SCORE_ADJ_MIN); |
79 | (sizeof("-1000\n") - 1) || close(fd) != 0) { | 82 | if (fclose(f)) { |
80 | die("can't tame the oom-killer. is suid or sgid set?\n"); | 83 | if (errno == EACCES) |
84 | die("slock: unable to disable OOM killer. " | ||
85 | "suid or sgid set?\n"); | ||
86 | else | ||
87 | die("slock: fclose %s: %s\n", oomfile, | ||
88 | strerror(errno)); | ||
81 | } | 89 | } |
82 | } | 90 | } |
83 | #endif | 91 | #endif |