#include "defines.h"
#include "conn.h"
+#include "class.h"
#include "conf-ssl.h"
#include "channel.h"
#include "conf.h"
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 ));
NGIRCd_SignalRestart = false;
NGIRCd_SignalQuit = false;
+ Random_Init();
+
/* Initialize modules, part I */
Log_Init( ! NGIRCd_NoDaemon );
Conf_Init( );
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));
exit(1);
}
- srandom(getpid());
-
/* Create protocol and server identification. The syntax
* used by ngIRCd in PASS commands and the known "extended
* flags" are described in doc/Protocol.txt. */
Conn_Exit( );
Client_Exit( );
Channel_Exit( );
+ Class_Exit( );
Log_Exit( );
}
Pidfile_Delete( );
} /* 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.
*
/* Detach stdin, stdout and stderr */
Setup_FDStreams(fd);
- if (fd > 2) {
+ if (fd > 2)
close(fd);
- fd = -1;
- }
}
pid = getpid();