X-Git-Url: https://jfr.im/git/irc/rqf/shadowircd.git/blobdiff_plain/1aa8ffcbfd855ffe11cd16a81af6147ec39e2016..1d39b466d4ddd974674c9397589d45935c746ed0:/src/ircd.c diff --git a/src/ircd.c b/src/ircd.c index dd1264f..5e108e0 100644 --- a/src/ircd.c +++ b/src/ircd.c @@ -24,17 +24,15 @@ * $Id: ircd.c 3380 2007-04-03 22:25:11Z jilles $ */ +#include "ratbox_lib.h" #include "stdinc.h" #include "setup.h" #include "config.h" - -#include "tools.h" #include "ircd.h" #include "channel.h" #include "class.h" #include "client.h" #include "common.h" -#include "event.h" #include "hash.h" #include "irc_string.h" #include "ircd_signal.h" @@ -47,9 +45,8 @@ #include "res.h" #include "restart.h" #include "s_auth.h" -#include "commio.h" #include "s_conf.h" -#include "s_log.h" +#include "logger.h" #include "s_serv.h" /* try_connections */ #include "s_user.h" #include "s_stats.h" @@ -58,18 +55,14 @@ #include "supported.h" #include "whowas.h" #include "modules.h" -#include "memory.h" #include "hook.h" #include "ircd_getopt.h" -#include "balloc.h" #include "newconf.h" -#include "patricia.h" #include "reject.h" #include "s_conf.h" #include "s_newconf.h" #include "cache.h" #include "monitor.h" -#include "libcharybdis.h" #include "patchlevel.h" #include "serno.h" @@ -83,6 +76,21 @@ extern int ServerRunning; extern struct LocalUser meLocalUser; extern char **myargv; +int maxconnections; + +/* /quote set variables */ +struct SetOptions GlobalSetOptions; + +/* configuration set from ircd.conf */ +struct config_file_entry ConfigFileEntry; +/* server info set from ircd.conf */ +struct server_info ServerInfo; +/* admin info set from ircd.conf */ +struct admin_info AdminInfo; + +struct Counter Count; +struct ServerStatistics ServerStats; + /* * print_startup - print startup information */ @@ -111,6 +119,12 @@ ircd_log_cb(const char *str) ilog(L_MAIN, "%s", str); } +static void +ircd_restart_cb(const char *str) +{ + restart(str); +} + /* * Why EXIT_FAILURE here? * Because if ircd_die_cb() is called it's because of a fatal @@ -139,19 +153,22 @@ ircd_die_cb(const char *str) static void init_sys(void) { -#if defined(RLIMIT_NOFILE) && defined(HAVE_SYS_RESOURCE_H) - struct rlimit limit; - - if(!getrlimit(RLIMIT_NOFILE, &limit)) - { - limit.rlim_cur = limit.rlim_max; /* make soft limit the max */ - if(setrlimit(RLIMIT_NOFILE, &limit) == -1) - { - fprintf(stderr, "error setting max fd's to %ld\n", (long) limit.rlim_cur); - exit(EXIT_FAILURE); - } - } -#endif /* RLIMIT_NOFILE */ +#if defined(RLIMIT_NOFILE) && defined(HAVE_SYS_RESOURCE_H) + struct rlimit limit; + + if(!getrlimit(RLIMIT_NOFILE, &limit)) + { + maxconnections = limit.rlim_cur; + if(maxconnections <= MAX_BUFFER) + { + fprintf(stderr, "ERROR: Shell FD limits are too low.\n"); + fprintf(stderr, "ERROR: ircd-ratbox reserves %d FDs, shell limits must be above this\n", MAX_BUFFER); + exit(EXIT_FAILURE); + } + return; + } +#endif /* RLIMIT_FD_MAX */ + maxconnections = MAXCONNECTIONS; } static int @@ -222,32 +239,6 @@ struct lgetopt myopts[] = { {NULL, NULL, STRING, NULL}, }; -void -set_time(void) -{ - struct timeval newtime; - newtime.tv_sec = 0; - newtime.tv_usec = 0; -#ifdef HAVE_GETTIMEOFDAY - if(gettimeofday(&newtime, NULL) == -1) - { - ilog(L_MAIN, "Clock Failure (%d)", errno); - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Clock Failure (%d), TS can be corrupted", errno); - - restart("Clock Failure"); - } -#else - newtime.tv_sec = time(NULL); - -#endif - if(newtime.tv_sec < CurrentTime) - set_back_events(CurrentTime - newtime.tv_sec); - - SystemTime.tv_sec = newtime.tv_sec; - SystemTime.tv_usec = newtime.tv_usec; -} - static void check_rehash(void *unused) { @@ -276,26 +267,6 @@ check_rehash(void *unused) } } -void -charybdis_io_loop(void) -{ - time_t delay; - - while (ServerRunning) - { - /* Run pending events, then get the number of seconds to the next - * event - */ - - delay = eventNextTime(); - if(delay <= CurrentTime) - eventRun(); - - - comm_select(250); - } -} - /* * initalialize_global_set_options * @@ -309,7 +280,11 @@ initialize_global_set_options(void) memset(&GlobalSetOptions, 0, sizeof(GlobalSetOptions)); /* memset( &ConfigFileEntry, 0, sizeof(ConfigFileEntry)); */ - GlobalSetOptions.maxclients = ServerInfo.max_clients; + GlobalSetOptions.maxclients = ServerInfo.default_max_clients; + + if(GlobalSetOptions.maxclients > (maxconnections - MAX_BUFFER)) + GlobalSetOptions.maxclients = maxconnections - MAX_BUFFER; + GlobalSetOptions.autoconn = 1; GlobalSetOptions.spam_time = MIN_JOIN_LEAVE_TIME; @@ -374,7 +349,7 @@ write_pidfile(const char *filename) { unsigned int pid = (unsigned int) getpid(); - ircsnprintf(buff, sizeof(buff), "%u\n", pid); + rb_snprintf(buff, sizeof(buff), "%u\n", pid); if((fputs(buff, fb) == -1)) { ilog(L_MAIN, "Error writing %u to pid file %s (%s)", @@ -444,6 +419,8 @@ setup_corefile(void) #endif } +struct ev_entry *check_splitmode_ev = NULL; + /* * main * @@ -465,10 +442,6 @@ main(int argc, char *argv[]) return -1; } - /* - * save server boot time right away, so getrusage works correctly - */ - set_time(); /* * Setup corefile size immediately after boot -kre */ @@ -489,11 +462,12 @@ main(int argc, char *argv[]) memset(&local_oper_list, 0, sizeof(local_oper_list)); memset(&oper_list, 0, sizeof(oper_list)); - dlinkAddTail(&me, &me.node, &global_client_list); + rb_dlinkAddTail(&me, &me.node, &global_client_list); - memset((void *) &Count, 0, sizeof(Count)); - memset((void *) &ServerInfo, 0, sizeof(ServerInfo)); - memset((void *) &AdminInfo, 0, sizeof(AdminInfo)); + memset(&Count, 0, sizeof(Count)); + memset(&ServerInfo, 0, sizeof(ServerInfo)); + memset(&AdminInfo, 0, sizeof(AdminInfo)); + memset(&ServerStats, 0, sizeof(struct ServerStatistics)); /* Initialise the channel capability usage counts... */ init_chcap_usage_counts(); @@ -553,16 +527,10 @@ main(int argc, char *argv[]) /* Init the event subsystem */ init_sys(); - libcharybdis_init(ircd_log_cb, restart, ircd_die_cb); - - fdlist_init(); - if(!server_state_foreground) - { - comm_close_all(); - } + rb_lib_init(ircd_log_cb, ircd_restart_cb, ircd_die_cb, !server_state_foreground, maxconnections, DNODE_HEAP_SIZE, FD_HEAP_SIZE); + rb_linebuf_init(LINEBUF_HEAP_SIZE); init_main_logfile(); - init_patricia(); newconf_init(); init_s_conf(); init_s_newconf(); @@ -576,7 +544,6 @@ main(int argc, char *argv[]) init_channels(); initclass(); initwhowas(); - init_stats(); init_reject(); init_cache(); init_monitor(); @@ -635,12 +602,12 @@ main(int argc, char *argv[]) me.servptr = &me; SetMe(&me); make_server(&me); - me.serv->up = me.name; - startup_time = CurrentTime; + startup_time = rb_current_time(); add_to_client_hash(me.name, &me); add_to_id_hash(me.id, &me); + me.serv->nameinfo = scache_connect(me.name, me.info, 0); - dlinkAddAlloc(&me, &global_serv_list); + rb_dlinkAddAlloc(&me, &global_serv_list); construct_umodebuf(); @@ -651,37 +618,31 @@ main(int argc, char *argv[]) ilog(L_MAIN, "Server Ready"); - eventAddIsh("cleanup_glines", cleanup_glines, NULL, CLEANUP_GLINES_TIME); + rb_event_addish("cleanup_glines", cleanup_glines, NULL, CLEANUP_GLINES_TIME); /* We want try_connections to be called as soon as possible now! -- adrian */ /* No, 'cause after a restart it would cause all sorts of nick collides */ /* um. by waiting even longer, that just means we have even *more* * nick collisions. what a stupid idea. set an event for the IO loop --fl */ - eventAddIsh("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME); - eventAddOnce("try_connections_startup", try_connections, NULL, 0); + rb_event_addish("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME); + rb_event_addonce("try_connections_startup", try_connections, NULL, 0); - eventAddIsh("collect_zipstats", collect_zipstats, NULL, ZIPSTATS_TIME); + rb_event_addish("collect_zipstats", collect_zipstats, NULL, ZIPSTATS_TIME); /* Setup the timeout check. I'll shift it later :) -- adrian */ - eventAddIsh("comm_checktimeouts", comm_checktimeouts, NULL, 1); + rb_event_addish("rb_checktimeouts", rb_checktimeouts, NULL, 1); - eventAdd("check_rehash", check_rehash, NULL, 1); - - if(ConfigServerHide.links_delay > 0) - eventAdd("cache_links", cache_links, NULL, - ConfigServerHide.links_delay); - else - ConfigServerHide.links_disabled = 1; + rb_event_add("check_rehash", check_rehash, NULL, 1); if(splitmode) - eventAdd("check_splitmode", check_splitmode, NULL, 2); + check_splitmode_ev = rb_event_add("check_splitmode", check_splitmode, NULL, 2); ServerRunning = 1; print_startup(getpid()); - charybdis_io_loop(); + rb_lib_loop(250); return 0; }