From ae69a754244c4e475c8d2591772ca8e005071d83 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 18 Feb 2019 11:55:41 +0100 Subject: Update to 5.42 --- driver/passwd.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) (limited to 'driver/passwd.c') diff --git a/driver/passwd.c b/driver/passwd.c index ac5a3f0..f443726 100644 --- a/driver/passwd.c +++ b/driver/passwd.c @@ -1,5 +1,5 @@ /* passwd.c --- verifying typed passwords with the OS. - * xscreensaver, Copyright (c) 1993-2014 Jamie Zawinski + * xscreensaver, Copyright (c) 1993-2018 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -24,6 +24,7 @@ #endif #include #include +#include #ifndef VMS # include /* for getpwuid() */ @@ -111,6 +112,44 @@ struct auth_methods methods[] = { }; +# ifdef HAVE_PROC_OOM +/* On some recent Linux systems you can tell the kernel's OOM-killer to + consider the possibility of maybe sometimes not killing you in low-memory + situations. Because that would unlock the screen. And that would be bad. + + Linux >= 2.6.11: echo -17 > /proc/$$/oom_adj <-- ignoring this. + Linux >= 2.6.37: echo -1000 > /proc/$$/oom_score_adj <-- trying this. + */ +static void +oom_assassin_immunity (Bool verbose_p) +{ + char fn[1024]; + struct stat st; + FILE *out; + sprintf (fn, "/proc/%d/oom_score_adj", getpid()); + if (stat(fn, &st) != 0) + { + if (verbose_p) + fprintf (stderr, "%s: OOM: %s does not exist\n", blurb(), fn); + return; + } + out = fopen (fn, "w"); + if (!out) + { + if (verbose_p) + { + char b[2048]; + sprintf (b, "%s: OOM: unable to write %s\n", blurb(), fn); + perror(b); + } + return; + } + fputs ("-1000\n", out); + fclose (out); +} +# endif /* HAVE_PROC_OOM */ + + Bool lock_priv_init (int argc, char **argv, Bool verbose_p) { @@ -130,6 +169,11 @@ lock_priv_init (int argc, char **argv, Bool verbose_p) fprintf (stderr, "%s: initialization of %s passwords failed.\n", blurb(), methods[i].name); } + +# ifdef HAVE_PROC_OOM + oom_assassin_immunity (verbose_p); +# endif + return any_ok; } -- cgit v1.2.3-55-g7522