From 53c49998d5a26c58d1f21fb79e7df9511e023998 Mon Sep 17 00:00:00 2001 From: Mikolaj Golub Date: Sun, 19 Feb 2012 10:38:55 +0000 Subject: [PATCH] If permitted protect the supervisor against pageout kill. Suggested by: Andrey Zonov MFC after: 2 weeks --- usr.sbin/daemon/daemon.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/usr.sbin/daemon/daemon.c b/usr.sbin/daemon/daemon.c index b1773bfdd2af..54d312358617 100644 --- a/usr.sbin/daemon/daemon.c +++ b/usr.sbin/daemon/daemon.c @@ -32,6 +32,7 @@ __FBSDID("$FreeBSD$"); #include +#include #include #include @@ -138,6 +139,12 @@ main(int argc, char *argv[]) sigaddset(&mask, SIGCHLD); if (sigprocmask(SIG_SETMASK, &mask, &oldmask) == -1) err(1, "sigprocmask"); + /* + * Try to protect against pageout kill. Ignore the + * error, madvise(2) will fail only if a process does + * not have superuser privileges. + */ + (void)madvise(NULL, 0, MADV_PROTECT); restart: /* * Spawn a child to exec the command, so in the parent