--- slock.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/slock.c b/slock.c index 210d5c8..63f8d4a 100644 --- a/slock.c +++ b/slock.c _AT_@ -65,19 +65,27 @@ die(const char *errstr, ...) #ifdef __linux__ #include <fcntl.h> +#include <linux/oom.h> static void dontkillme(void) { - int fd; + FILE *f; + const char oomfile[] = "/proc/self/oom_score_adj"; - fd = open("/proc/self/oom_score_adj", O_WRONLY); - if (fd < 0 && errno == ENOENT) { - return; + if (!(f = fopen(oomfile, "w"))) { + if (errno == ENOENT) + return; + die("slock: fopen %s: %s\n", oomfile, strerror(errno)); } - if (fd < 0 || write(fd, "-1000\n", (sizeof("-1000\n") - 1)) != - (sizeof("-1000\n") - 1) || close(fd) != 0) { - die("can't tame the oom-killer. is suid or sgid set?\n"); + fprintf(f, "%d", OOM_SCORE_ADJ_MIN); + if (fclose(f)) { + if (errno == EACCES) + die("slock: unable to disable OOM killer. " + "suid or sgid set?\n"); + else + die("slock: fclose %s: %s\n", oomfile, + strerror(errno)); } } #endif -- 2.7.3 --Multipart=_Tue__30_Aug_2016_22_31_28_+0200_iUF.nQafE=6CdTP9 Content-Type: text/x-diff; name="0002-Convert-manpage-to-mandoc-and-fix-usage.patch" Content-Disposition: attachment; filename="0002-Convert-manpage-to-mandoc-and-fix-usage.patch" Content-Transfer-Encoding: 7bitReceived on Mon Sep 17 2001 - 00:00:00 CEST
This archive was generated by hypermail 2.3.0 : Tue Aug 30 2016 - 23:24:12 CEST