diff options
author | attilio <attilio@FreeBSD.org> | 2009-11-25 15:12:24 +0000 |
---|---|---|
committer | attilio <attilio@FreeBSD.org> | 2009-11-25 15:12:24 +0000 |
commit | 99524169bf3f72fffa8e41ace1a952854e3f97d3 (patch) | |
tree | f308da7e1d86252ddb2bfef1aafa5f589034f693 | |
parent | c984dc56360945b3348330530b2cec41b26e99e5 (diff) | |
download | FreeBSD-src-99524169bf3f72fffa8e41ace1a952854e3f97d3.zip FreeBSD-src-99524169bf3f72fffa8e41ace1a952854e3f97d3.tar.gz |
Avoid sshd, cron, syslogd and inetd to be killed under high-pressure swap
environments.
Please note that this can't be done while such processes run in jails.
Note: in future it would be interesting to find a way to do that
selectively for any desired proccess (choosen by user himself), probabilly
via a ptrace interface or whatever.
Obtained from: Sandvine Incorporated
Reviewed by: emaste, arch@
Sponsored by: Sandvine Incorporated
MFC: 1 month
-rw-r--r-- | crypto/openssh/sshd.c | 5 | ||||
-rw-r--r-- | usr.sbin/cron/cron/cron.c | 4 | ||||
-rw-r--r-- | usr.sbin/inetd/inetd.c | 4 | ||||
-rw-r--r-- | usr.sbin/syslogd/syslogd.c | 4 |
4 files changed, 17 insertions, 0 deletions
diff --git a/crypto/openssh/sshd.c b/crypto/openssh/sshd.c index 249e20f..422f0cb 100644 --- a/crypto/openssh/sshd.c +++ b/crypto/openssh/sshd.c @@ -47,6 +47,7 @@ __RCSID("$FreeBSD$"); #include <sys/types.h> #include <sys/ioctl.h> +#include <sys/mman.h> #include <sys/socket.h> #ifdef HAVE_SYS_STAT_H # include <sys/stat.h> @@ -1293,6 +1294,10 @@ main(int ac, char **av) /* Initialize configuration options to their default values. */ initialize_server_options(&options); + /* Avoid killing the process in high-pressure swapping environments. */ + if (madvise(NULL, 0, MADV_PROTECT) != 0) + debug("madvise(): %.200s", strerror(errno)); + /* Parse command-line arguments. */ while ((opt = getopt(ac, av, "f:p:b:k:h:g:u:o:C:dDeiqrtQRT46")) != -1) { switch (opt) { diff --git a/usr.sbin/cron/cron/cron.c b/usr.sbin/cron/cron/cron.c index 101989c..52cdcc8 100644 --- a/usr.sbin/cron/cron/cron.c +++ b/usr.sbin/cron/cron/cron.c @@ -24,6 +24,7 @@ static const char rcsid[] = #include "cron.h" +#include <sys/mman.h> #include <sys/signal.h> #if SYS_TIME_H # include <sys/time.h> @@ -134,6 +135,9 @@ main(argc, argv) } } + if (madvise(NULL, 0, MADV_PROTECT) != 0) + log_it("CRON", getpid(), "WARNING", "madvise() failed"); + pidfile_write(pfh); database.head = NULL; database.tail = NULL; diff --git a/usr.sbin/inetd/inetd.c b/usr.sbin/inetd/inetd.c index 6bcbac6..e8d34f4 100644 --- a/usr.sbin/inetd/inetd.c +++ b/usr.sbin/inetd/inetd.c @@ -110,6 +110,7 @@ __FBSDID("$FreeBSD$"); */ #include <sys/param.h> #include <sys/ioctl.h> +#include <sys/mman.h> #include <sys/wait.h> #include <sys/time.h> #include <sys/resource.h> @@ -497,6 +498,9 @@ main(int argc, char **argv) } } + if (madvise(NULL, 0, MADV_PROTECT) != 0) + syslog(LOG_WARNING, "madvise() failed: %s", strerror(errno)); + for (i = 0; i < PERIPSIZE; ++i) LIST_INIT(&proctable[i]); diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c index 3e628a2..5cb0af9 100644 --- a/usr.sbin/syslogd/syslogd.c +++ b/usr.sbin/syslogd/syslogd.c @@ -77,6 +77,7 @@ __FBSDID("$FreeBSD$"); #include <sys/param.h> #include <sys/ioctl.h> +#include <sys/mman.h> #include <sys/stat.h> #include <sys/wait.h> #include <sys/socket.h> @@ -352,6 +353,9 @@ main(int argc, char *argv[]) pid_t ppid = 1, spid; socklen_t len; + if (madvise(NULL, 0, MADV_PROTECT) != 0) + dprintf("madvise() failed: %s\n", strerror(errno)); + bindhostname = NULL; while ((ch = getopt(argc, argv, "468Aa:b:cCdf:kl:m:nop:P:sS:Tuv")) != -1) |