From: Felix Morgner Date: Thu, 26 Jan 2017 11:30:42 +0000 (+0100) Subject: Merge pull request #100 from C4K3/scheduler-timing X-Git-Url: http://git.code-monkey.de/?p=umurmur.git;a=commitdiff_plain;h=a80a3363723e4f8c35acf63274332e20c35616ce;hp=ea29a328d04bdffd8397fa3ff515f09f48c617f1 Merge pull request #100 from C4K3/scheduler-timing Set scheduling policy before dropping privileges --- 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