]> jfr.im git - irc/rqf/shadowircd.git/blobdiff - src/ircd.c
Fixing time_t warnings
[irc/rqf/shadowircd.git] / src / ircd.c
index 7c57228d435daefeaa7fd6cf111d6c69365c5b92..bf13e0d3f5f617b6e896afa92481ae8b452377e0 100644 (file)
  *  $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"
 #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"
-
-#include "ratbox_lib.h"
-
-/*
- * Try and find the correct name to use with getrlimit() for setting the max.
- * number of files allowed to be open by this process.
- */
-int _charybdis_data_version = CHARYBDIS_DV;
-
-extern int ServerRunning;
-extern struct LocalUser meLocalUser;
-extern char **myargv;
+#include "sslproc.h"
+
+/* /quote set variables */\r
+struct SetOptions GlobalSetOptions;
+\r
+/* configuration set from ircd.conf */\r
+struct config_file_entry ConfigFileEntry;\r
+/* server info set from ircd.conf */\r
+struct server_info ServerInfo;\r
+/* admin info set from ircd.conf */\r
+struct admin_info AdminInfo;
+
+struct Counter Count;\r
+struct ServerStatistics ServerStats;
+
+int maxconnections;
+struct timeval SystemTime;
+struct Client me;              /* That's me */\r
+struct LocalUser meLocalUser;  /* That's also part of me */
+
+rb_dlink_list lclient_list = { NULL, NULL, 0 };\r
+rb_dlink_list global_client_list = { NULL, NULL, 0 };\r
+rb_dlink_list global_channel_list = { NULL, NULL, 0 };\r
+\r
+rb_dlink_list unknown_list;        /* unknown clients ON this server only */\r
+rb_dlink_list serv_list;           /* local servers to this server ONLY */\r
+rb_dlink_list global_serv_list;    /* global servers on the network */\r
+rb_dlink_list local_oper_list;     /* our opers, duplicated in lclient_list */\r
+rb_dlink_list oper_list;           /* network opers */
+
+time_t startup_time;\r
+\r
+int default_server_capabs = CAP_MASK;\r
+\r
+int splitmode;\r
+int splitchecking;\r
+int split_users;\r
+int split_servers;\r
+int eob_count;\r
+\r
+unsigned long initialVMTop = 0;  /* top of virtual memory at init */\r
+const char *logFileName = LPATH;\r
+const char *pidFileName = PPATH;
+
+char **myargv;
+int dorehash = 0;\r
+int dorehashbans = 0;\r
+int doremotd = 0;\r
+int kline_queued = 0;\r
+int server_state_foreground = 0;\r
+int opers_see_all_users = 0;\r
+int ssl_ok = 0;\r
+int zlib_ok = 1;\r
+\r
+int testing_conf = 0;\r
+\r
+struct config_channel_entry ConfigChannel;\r
+rb_bh *channel_heap;\r
+rb_bh *ban_heap;\r
+rb_bh *topic_heap;\r
+rb_bh *member_heap;\r
+\r
+rb_bh *client_heap = NULL;\r
+rb_bh *lclient_heap = NULL;\r
+rb_bh *pclient_heap = NULL;\r
+\r
+char current_uid[IDLEN];\r
+\r
+/* patricia */\r
+rb_bh *prefix_heap;\r
+rb_bh *node_heap;\r
+rb_bh *patricia_heap;\r
+\r
+rb_bh *linebuf_heap;\r
+\r
+rb_bh *dnode_heap;
 
 /*
  * print_startup - print startup information
@@ -116,7 +173,7 @@ ircd_log_cb(const char *str)
 static void
 ircd_restart_cb(const char *str)
 {
-       ilog(L_MAIN, "%s", str);
+       restart(str);
 }
 
 /*
@@ -129,9 +186,12 @@ ircd_restart_cb(const char *str)
 static void
 ircd_die_cb(const char *str)
 {
-       /* Try to get the message out to currently logged in operators. */
-       sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "Server panic! %s", str);
-       inotice("server panic: %s", str);
+       if(str != NULL)\r
+       {
+               /* Try to get the message out to currently logged in operators. */
+               sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "Server panic! %s", str);
+               inotice("server panic: %s", str);
+       }
 
        unlink(pidFileName);
        exit(EXIT_FAILURE);
@@ -147,19 +207,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)\r
+       struct rlimit limit;\r
+\r
+       if(!getrlimit(RLIMIT_NOFILE, &limit))\r
+       {\r
+               maxconnections = limit.rlim_cur;\r
+               if(maxconnections <= MAX_BUFFER)\r
+               {\r
+                       fprintf(stderr, "ERROR: Shell FD limits are too low.\n");\r
+                       fprintf(stderr, "ERROR: ircd-ratbox reserves %d FDs, shell limits must be above this\n", MAX_BUFFER);\r
+                       exit(EXIT_FAILURE);\r
+               }\r
+               return;\r
+       }\r
+#endif /* RLIMIT_FD_MAX */\r
+       maxconnections = MAXCONNECTIONS;
 }
 
 static int
@@ -230,32 +293,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)
 {
@@ -284,26 +321,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();
-
-
-               rb_select(250);
-       }
-}
-
 /*
  * initalialize_global_set_options
  *
@@ -317,7 +334,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;\r
+\r
+       if(GlobalSetOptions.maxclients > (maxconnections - MAX_BUFFER) || (GlobalSetOptions.maxclients <= 0))\r
+               GlobalSetOptions.maxclients = maxconnections - MAX_BUFFER;
+
        GlobalSetOptions.autoconn = 1;
 
        GlobalSetOptions.spam_time = MIN_JOIN_LEAVE_TIME;
@@ -452,6 +473,8 @@ setup_corefile(void)
 #endif
 }
 
+struct ev_entry *check_splitmode_ev = NULL;
+
 /*
  * main
  *
@@ -473,16 +496,11 @@ 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
         */
        setup_corefile();
 
-       ServerRunning = 0;
        /* It ain't random, but it ought to be a little harder to guess */
        srand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20)));
        memset(&me, 0, sizeof(me));
@@ -499,9 +517,10 @@ main(int argc, char *argv[])
 
        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();
@@ -561,17 +580,10 @@ main(int argc, char *argv[])
 
        /* Init the event subsystem */
        init_sys();
-       libcharybdis_init(ircd_log_cb, restart, ircd_die_cb);
-       rb_lib_init(ircd_log_cb, restart, ircd_die_cb);
-
-       fdlist_init();
-       if(!server_state_foreground)
-       {
-               rb_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();
@@ -585,7 +597,6 @@ main(int argc, char *argv[])
        init_channels();
        initclass();
        initwhowas();
-       init_stats();
        init_reject();
        init_cache();
        init_monitor();
@@ -607,6 +618,8 @@ main(int argc, char *argv[])
        mod_add_path(MODULE_DIR "/autoload"); 
 #endif
 
+       init_ssld();
+
        initialize_server_capabs();     /* Set up default_server_capabs */
        initialize_global_set_options();
 
@@ -633,6 +646,18 @@ main(int argc, char *argv[])
        }
        strlcpy(me.info, ServerInfo.description, sizeof(me.info));
 
+       if(ServerInfo.ssl_cert != NULL && ServerInfo.ssl_private_key != NULL)\r
+       {\r
+               /* just do the rb_setup_ssl_server to validate the config */\r
+               if(!rb_setup_ssl_server(ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params))\r
+               {\r
+                       ilog(L_MAIN, "WARNING: Unable to setup SSL.");\r
+                       ssl_ok = 0;\r
+               }\r
+               else\r
+                       ssl_ok = 1;\r
+       }
+
        if (testing_conf)
        {
                fprintf(stderr, "\nConfig testing complete.\n");
@@ -644,7 +669,7 @@ main(int argc, char *argv[])
        me.servptr = &me;
        SetMe(&me);
        make_server(&me);
-       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);
@@ -660,31 +685,27 @@ 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);
-
-       eventAddIsh("collect_zipstats", collect_zipstats, NULL, ZIPSTATS_TIME);
+       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 */
-       eventAddIsh("rb_checktimeouts", rb_checktimeouts, NULL, 1);
+       rb_event_addish("rb_checktimeouts", rb_checktimeouts, NULL, 1);
 
-       eventAdd("check_rehash", check_rehash, NULL, 1);
+       rb_event_add("check_rehash", check_rehash, NULL, 1);
 
        if(splitmode)
-               eventAdd("check_splitmode", check_splitmode, NULL, 2);
-
-       ServerRunning = 1;
+               check_splitmode_ev = rb_event_add("check_splitmode", check_splitmode, NULL, 2);
 
        print_startup(getpid());
 
-       charybdis_io_loop();
+       rb_lib_loop(0);
 
        return 0;
 }