]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/ngircd.c
Update Copyright notices for 2012
[ngircd-alex.git] / src / ngircd / ngircd.c
index 4b49ec6cce56ba599616dce9049b1b15f99fad39..a1f1d8877da9ad9f5c4ef7165d6fdaae381bc6fd 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ngIRCd -- The Next Generation IRC Daemon
- * Copyright (c)2001-2011 Alexander Barton (alex@barton.de) and Contributors.
+ * Copyright (c)2001-2012 Alexander Barton (alex@barton.de) and Contributors.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -38,6 +38,7 @@
 
 #include "defines.h"
 #include "conn.h"
+#include "class.h"
 #include "conf-ssl.h"
 #include "channel.h"
 #include "conf.h"
@@ -60,6 +61,8 @@ static void Pidfile_Delete PARAMS(( void ));
 
 static void Fill_Version PARAMS(( void ));
 
+static void Random_Init PARAMS(( void ));
+
 static void Setup_FDStreams PARAMS(( int fd ));
 
 static bool NGIRCd_Init PARAMS(( bool ));
@@ -262,6 +265,8 @@ main( int argc, const char *argv[] )
                NGIRCd_SignalRestart = false;
                NGIRCd_SignalQuit = false;
 
+               Random_Init();
+
                /* Initialize modules, part I */
                Log_Init( ! NGIRCd_NoDaemon );
                Conf_Init( );
@@ -278,6 +283,7 @@ main( int argc, const char *argv[] )
                Channel_Init( );
                Client_Init( );
                Conn_Init( );
+               Class_Init( );
 
                if (!io_library_init(CONNECTION_POOL)) {
                        Log(LOG_ALERT, "Fatal: Cannot initialize IO routines: %s", strerror(errno));
@@ -323,6 +329,7 @@ main( int argc, const char *argv[] )
                Conn_Exit( );
                Client_Exit( );
                Channel_Exit( );
+               Class_Exit( );
                Log_Exit( );
        }
        Pidfile_Delete( );
@@ -417,7 +424,7 @@ static void
 Show_Version( void )
 {
        puts( NGIRCd_Version );
-       puts( "Copyright (c)2001-2011 Alexander Barton (<alex@barton.de>) and Contributors." );
+       puts( "Copyright (c)2001-2012 Alexander Barton (<alex@barton.de>) and Contributors." );
        puts( "Homepage: <http://ngircd.barton.de/>\n" );
        puts( "This is free software; see the source for copying conditions. There is NO" );
        puts( "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." );
@@ -562,6 +569,37 @@ NGIRCd_getNobodyID(uid_t *uid, gid_t *gid )
 } /* NGIRCd_getNobodyID */
 
 
+static bool
+Random_Init_Kern(const char *file)
+{
+       unsigned int seed;
+       bool ret = false;
+       int fd = open(file, O_RDONLY);
+       if (fd >= 0) {
+               if (read(fd, &seed, sizeof(seed)) == sizeof(seed))
+                       ret = true;
+               close(fd);
+               srand(seed);
+       }
+       return ret;
+}
+
+/**
+ * Initialize libc rand(3) number generator
+ */
+static void
+Random_Init(void)
+{
+       if (Random_Init_Kern("/dev/urandom"))
+               return;
+       if (Random_Init_Kern("/dev/random"))
+               return;
+       if (Random_Init_Kern("/dev/arandom"))
+               return;
+       srand(rand() ^ (unsigned)getpid() ^ (unsigned)time(NULL));
+}
+
+
 /**
  * Initialize ngIRCd daemon.
  *
@@ -671,10 +709,8 @@ NGIRCd_Init( bool NGIRCd_NoDaemon )
 
                /* Detach stdin, stdout and stderr */
                Setup_FDStreams(fd);
-               if (fd > 2) {
+               if (fd > 2)
                        close(fd);
-                       fd = -1;
-               }
        }
        pid = getpid();