+static void
+ircd_log_cb(const char *str)
+{
+ ilog(L_MAIN, "libratbox reports: %s", str);
+}
+
+static void
+ircd_restart_cb(const char *str)
+{
+ inotice("libratbox has called the restart callback: %s", str);
+ restart(str);
+}
+
+/*
+ * Why EXIT_FAILURE here?
+ * Because if ircd_die_cb() is called it's because of a fatal
+ * error inside libcharybdis, and we don't know how to handle the
+ * exception, so it is logical to return a FAILURE exit code here.
+ * --nenolod
+ */
+static void
+ircd_die_cb(const char *str)
+{
+ if(str != NULL)
+ {
+ /* Try to get the message out to currently logged in operators. */
+ sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "libratbox has called the die callback..aborting: %s", str);
+ inotice("libratbox has called the die callback..aborting: %s", str);
+ }
+ else
+ inotice("libratbox has called the die callback..aborting");
+
+ unlink(pidFileName);
+ exit(EXIT_FAILURE);
+}
+
+struct ev_entry *check_splitmode_ev = NULL;
+
+static int
+seed_with_urandom(void)
+{
+ unsigned int seed;
+ int fd;
+
+ fd = open("/dev/urandom", O_RDONLY);
+ if(fd >= 0)
+ {
+ if(read(fd, &seed, sizeof(seed)) == sizeof(seed))
+ {
+ close(fd);
+ srand(seed);
+ return 1;
+ }
+ }
+ return 0;
+}
+
+static void
+seed_with_clock(void)
+{
+ const struct timeval *tv;
+ rb_set_time();
+ tv = rb_current_time_tv();
+ srand(tv->tv_sec ^ (tv->tv_usec | (getpid() << 20)));
+}
+
+static void
+seed_random(void *unused)
+{
+ unsigned int seed;
+ if(rb_get_random(&seed, sizeof(seed)) == -1)
+ {
+ if(!seed_with_urandom())
+ seed_with_clock();
+ return;
+ }
+ srand(seed);
+}
+