From 1aa006c5960c17ccb941fc850b29d49cd5c6d1c3 Mon Sep 17 00:00:00 2001 From: Sebastian Blunt Date: Tue, 6 Dec 2016 18:11:14 +0100 Subject: [PATCH] Set scheduling policy before dropping privileges Previously if set to daemonize, set to run with realtime priority, and set to drop privileges, umurmur would try to set the scheduling policy after dropping privileges, which would fail as unprivileged processes are not allowed to set a realtime scheduling policy as of Linux 2.6.12. Fixes #94. --- src/main.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/main.c b/src/main.c index a18363d..bc91339 100644 --- a/src/main.c +++ b/src/main.c @@ -323,6 +323,13 @@ int main(int argc, char **argv) if (pidfile != NULL) lockfile(pidfile); +#ifdef POSIX_PRIORITY_SCHEDULING + /* Set the scheduling policy, has to be called after daemonizing + * but before we drop privileges */ + if (realtime) + setscheduler(); +#endif + switch_user(); /* Reopen log file. If user switch results in access denied, we catch @@ -332,6 +339,15 @@ int main(int argc, char **argv) } else Log_init(true); +#ifdef POSIX_PRIORITY_SCHEDULING + /* We still want to set scheduling policy if nodaemon is specified, + * but if we are daemonizing setscheduler() will be called above */ + if (nodaemon) { + if (realtime) + setscheduler(); + } +#endif + signal(SIGCHLD, SIG_IGN); /* ignore child */ signal(SIGTSTP, SIG_IGN); /* ignore tty signals */ signal(SIGTTOU, SIG_IGN); @@ -360,11 +376,6 @@ int main(int argc, char **argv) Sharedmemory_init( bindport, bindport6 ); #endif -#ifdef POSIX_PRIORITY_SCHEDULING - if (realtime) - setscheduler(); -#endif - Server_run(); #ifdef USE_SHAREDMEMORY_API -- 2.30.2