From baadbadba5927717dbf08293bc266c74658d1de6 Mon Sep 17 00:00:00 2001 From: Shaun Ruffell Date: Sun, 17 Jun 2012 11:45:55 -0500 Subject: [PATCH] Lock all pages when running with elevated priorities. Internal-Issue-ID: DAHLIN-241 Signed-off-by: Shaun Ruffell --- main/asterisk.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/main/asterisk.c b/main/asterisk.c index d7c5e00..4e9480e 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -105,6 +105,7 @@ int daemon(int, int); /* defined in libresolv of all places */ #endif #ifdef linux +#include #include #ifdef HAVE_CAP #include @@ -1622,9 +1623,14 @@ int ast_set_priority(int pri) if (sched_setscheduler(0, SCHED_RR, &sched)) { ast_log(LOG_WARNING, "Unable to set high priority\n"); return -1; - } else - if (option_verbose) + } else { + if (mlockall(MCL_CURRENT | MCL_FUTURE)) { + ast_log(LOG_WARNING, "Unable to lock address space.\n"); + } + if (option_verbose) { ast_verbose("Set to realtime thread\n"); + } + } } else { sched.sched_priority = 0; /* According to the manpage, these parameters can never fail. */ @@ -3740,6 +3746,9 @@ int main(int argc, char *argv[]) if (daemon(1, 0) < 0) { ast_log(LOG_ERROR, "daemon() failed: %s\n", strerror(errno)); } + if (isroot) { + ast_set_priority(ast_opt_high_priority); + } ast_mainpid = getpid(); /* Blindly re-write pid file since we are forking */ unlink(ast_config_AST_PID); -- 1.7.10.2