X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=src%2Fmain.c;h=c74d9646bd71f168ee29627019a76da272ca61ba;hb=HEAD;hp=929af5c951b3d28a7a09685ca6599b5bcfb2ac85;hpb=336d27baf938a957177e4c26c2b5c6c4172aa0a6;p=umurmur.git diff --git a/src/main.c b/src/main.c index 929af5c..c74d964 100644 --- a/src/main.c +++ b/src/main.c @@ -56,6 +56,7 @@ #include "version.h" #include "config.h" #include "sharedmemory.h" +#include "ban.h" char system_string[64], version_string[64]; int bindport; @@ -198,6 +199,10 @@ void daemonize() for (i = getdtablesize(); i >= 0; --i) close(i); /* close all descriptors */ +#ifdef USE_GNUTLS + gnutls_global_init(); +#endif + i = open("/dev/null",O_RDWR); (void)dup(i); (void)dup(i); @@ -317,16 +322,25 @@ int main(int argc, char **argv) Log_init(false); 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 - * it early. - */ - Log_reset(); } 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); @@ -350,16 +364,27 @@ int main(int argc, char **argv) Chan_init(); Client_init(); Ban_init(); - Sharedmemory_init(); - -#ifdef POSIX_PRIORITY_SCHEDULING - if (realtime) - setscheduler(); + +#ifdef USE_SHAREDMEMORY_API + Sharedmemory_init( bindport, bindport6 ); #endif + if(!nodaemon) { + /* SSL and scheduling is setup, we can drop privileges now */ + switch_user(); + + /* Reopen log file. If user switch results in access denied, we catch + * it early. + */ + Log_reset(); + } + Server_run(); +#ifdef USE_SHAREDMEMORY_API Sharedmemory_deinit(); +#endif + Ban_deinit(); SSLi_deinit(); Chan_free();