X-Git-Url: https://jfr.im/git/irc/rqf/shadowircd.git/blobdiff_plain/a822ef295aa0cf3a2520def1c43fce15d85d3fe1..7f9801883f36c445e7326ed0b35284e23366a83e:/src/ircd.c diff --git a/src/ircd.c b/src/ircd.c index 6a80edd..907e697 100644 --- a/src/ircd.c +++ b/src/ircd.c @@ -34,9 +34,8 @@ #include "client.h" #include "common.h" #include "hash.h" -#include "irc_string.h" +#include "match.h" #include "ircd_signal.h" -#include "sprintf_irc.h" #include "msg.h" /* msgtab */ #include "hostmask.h" #include "numeric.h" @@ -141,6 +140,35 @@ rb_bh *linebuf_heap; rb_bh *dnode_heap; +void +ircd_shutdown(const char *reason) +{ + struct Client *target_p; + rb_dlink_node *ptr; + + RB_DLINK_FOREACH(ptr, lclient_list.head) + { + target_p = ptr->data; + + sendto_one(target_p, ":%s NOTICE %s :Server Terminating. %s", + me.name, target_p->name, reason); + } + + RB_DLINK_FOREACH(ptr, serv_list.head) + { + target_p = ptr->data; + + sendto_one(target_p, ":%s ERROR :Terminated by %s", + me.name, reason); + } + + ilog(L_MAIN, "Server Terminating. %s", reason); + close_logfiles(); + + unlink(pidFileName); + exit(0); +} + /* * print_startup - print startup information */ @@ -359,10 +387,10 @@ initialize_global_set_options(void) GlobalSetOptions.ident_timeout = IDENT_TIMEOUT; - strlcpy(GlobalSetOptions.operstring, + rb_strlcpy(GlobalSetOptions.operstring, ConfigFileEntry.default_operstring, sizeof(GlobalSetOptions.operstring)); - strlcpy(GlobalSetOptions.adminstring, + rb_strlcpy(GlobalSetOptions.adminstring, ConfigFileEntry.default_adminstring, sizeof(GlobalSetOptions.adminstring)); @@ -473,6 +501,47 @@ setup_corefile(void) 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); +} + /* * main * @@ -537,7 +606,7 @@ main(int argc, char *argv[]) if(printVersion) { - printf("ircd: version %s\n", ircd_version); + printf("ircd: version %s(%s)\n", ircd_version, serno); exit(EXIT_SUCCESS); } @@ -626,7 +695,7 @@ main(int argc, char *argv[]) ierror("no server name specified in serverinfo block."); return -1; } - strlcpy(me.name, ServerInfo.name, sizeof(me.name)); + rb_strlcpy(me.name, ServerInfo.name, sizeof(me.name)); if(ServerInfo.sid[0] == '\0') { @@ -642,7 +711,7 @@ main(int argc, char *argv[]) ierror("no server description specified in serverinfo block."); return -3; } - strlcpy(me.info, ServerInfo.description, sizeof(me.info)); + rb_strlcpy(me.info, ServerInfo.description, sizeof(me.info)); if(ServerInfo.ssl_cert != NULL && ServerInfo.ssl_private_key != NULL) { @@ -690,11 +759,8 @@ main(int argc, char *argv[]) */ rb_event_addish("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME); rb_event_addonce("try_connections_startup", try_connections, NULL, 0); - - /* Setup the timeout check. I'll shift it later :) -- adrian */ - rb_event_addish("rb_checktimeouts", rb_checktimeouts, NULL, 1); - rb_event_add("check_rehash", check_rehash, NULL, 1); + rb_event_addish("reseed_srand", seed_random, NULL, 300); /* reseed every 10 minutes */ if(splitmode) check_splitmode_ev = rb_event_add("check_splitmode", check_splitmode, NULL, 2);