ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/ircd.c
(Generate patch)

Comparing ircd-hybrid/trunk/src/ircd.c (file contents):
Revision 1625 by michael, Thu Nov 1 13:49:25 2012 UTC vs.
Revision 5460 by michael, Tue Feb 3 22:24:57 2015 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 < *  ircd.c: Starts up and runs the ircd.
2 > *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (C) 2002 by the past and present ircd coders, and others.
4 > *  Copyright (c) 1997-2015 ircd-hybrid development team
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 16 | Line 15
15   *
16   *  You should have received a copy of the GNU General Public License
17   *  along with this program; if not, write to the Free Software
18 < *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
18 > *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19   *  USA
20 < *
21 < *  $Id$
20 > */
21 >
22 > /*! \file ircd.c
23 > * \brief Starts up and runs the ircd.
24 > * \version $Id$
25   */
26  
27   #include "stdinc.h"
28 < #include "s_user.h"
28 > #include "user.h"
29   #include "list.h"
30   #include "ircd.h"
31   #include "channel.h"
30 #include "channel_mode.h"
32   #include "client.h"
33   #include "event.h"
34   #include "fdlist.h"
35   #include "hash.h"
36   #include "irc_string.h"
37   #include "ircd_signal.h"
38 < #include "s_gline.h"
38 > #include "gline.h"
39   #include "motd.h"
40 + #include "conf.h"
41   #include "hostmask.h"
40 #include "numeric.h"
41 #include "packet.h"
42   #include "parse.h"
43 < #include "irc_res.h"
43 > #include "res.h"
44   #include "restart.h"
45   #include "rng_mt.h"
46 < #include "s_auth.h"
46 > #include "auth.h"
47   #include "s_bsd.h"
48 #include "conf.h"
48   #include "log.h"
49 < #include "s_misc.h"
51 < #include "s_serv.h"      /* try_connections */
49 > #include "server.h"      /* try_connections */
50   #include "send.h"
51   #include "whowas.h"
52   #include "modules.h"
53   #include "memory.h"
54 < #include "hook.h"
54 > #include "mempool.h"
55   #include "ircd_getopt.h"
58 #include "balloc.h"
59 #include "motd.h"
60 #include "supported.h"
56   #include "watch.h"
57   #include "conf_db.h"
58 + #include "conf_class.h"
59 + #include "ipcache.h"
60  
64 /* /quote set variables */
65 struct SetOptions GlobalSetOptions;
61  
62 < /* configuration set from ircd.conf */
63 < struct config_file_entry ConfigFileEntry;
64 < /* server info set from ircd.conf */
65 < struct server_info ServerInfo;
71 < /* admin info set from ircd.conf */
72 < struct admin_info AdminInfo = { NULL, NULL, NULL };
73 < struct Counter Count = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
74 < struct ServerState_t server_state = { 0 };
75 < struct logging_entry ConfigLoggingEntry = { .use_logging = 1 };
76 < struct ServerStatistics ServerStats;
62 > #ifdef HAVE_LIBGEOIP
63 > GeoIP *geoip_ctx;
64 > #endif
65 >
66   struct timeval SystemTime;
67 < struct Client me;             /* That's me */
79 < struct LocalUser meLocalUser; /* That's also part of me */
67 > struct Client me = { .connection = &(struct Connection) {} };  /* That's me */
68  
69 + char **myargv;
70   const char *logFileName = LPATH;
71   const char *pidFileName = PPATH;
72  
73 < char **myargv;
74 <
75 < int dorehash = 0;
87 < int doremotd = 0;
88 <
89 < /* Set to zero because it should be initialized later using
90 < * initialize_server_capabs
91 < */
92 < int default_server_capabs = 0;
73 > unsigned int dorehash;
74 > unsigned int doremotd;
75 > unsigned int default_server_capabs;
76   unsigned int splitmode;
77   unsigned int splitchecking;
78   unsigned int split_users;
79   unsigned int split_servers;
80  
81 < /* Do klines the same way hybrid-6 did them, i.e. at the
82 < * top of the next io_loop instead of in the same loop as
83 < * the klines are being applied.
84 < *
85 < * This should fix strange CPU starvation as very indirectly reported.
86 < * (Why do you people not email bug reports? WHY? WHY?)
87 < *
88 < * - Dianora
89 < */
81 > static struct event event_cleanup_glines =
82 > {
83 >  .name = "cleanup_glines",
84 >  .handler = cleanup_glines,
85 >  .when = CLEANUP_GLINES_TIME
86 > };
87 >
88 > static struct event event_cleanup_tklines =
89 > {
90 >  .name = "cleanup_tklines",
91 >  .handler = cleanup_tklines,
92 >  .when = CLEANUP_TKLINES_TIME
93 > };
94 >
95 > static struct event event_try_connections =
96 > {
97 >  .name = "try_connections",
98 >  .handler = try_connections,
99 >  .when = STARTUP_CONNECTIONS_TIME
100 > };
101 >
102 > static struct event event_comm_checktimeouts =
103 > {
104 >  .name = "comm_checktimeouts",
105 >  .handler = comm_checktimeouts,
106 >  .when = 1
107 > };
108 >
109 > static struct event event_save_all_databases =
110 > {
111 >  .name = "save_all_databases",
112 >  .handler = save_all_databases,
113 >  .when = DATABASE_UPDATE_TIMEOUT
114 > };
115  
116 < int rehashed_klines = 0;
116 > struct event event_write_links_file =
117 > {
118 >  .name = "write_links_file",
119 >  .handler = write_links_file,
120 > };
121  
122  
123   /*
# Line 114 | Line 126 | int rehashed_klines = 0;
126   static void
127   print_startup(int pid)
128   {
129 <  printf("ircd: version %s\n", ircd_version);
129 >  printf("ircd: version %s(%s)\n", ircd_version, serno);
130    printf("ircd: pid %d\n", pid);
131    printf("ircd: running in %s mode from %s\n", !server_state.foreground ? "background"
132 <         : "foreground", ConfigFileEntry.dpath);
132 >         : "foreground", ConfigGeneral.dpath);
133   }
134  
135   static void
# Line 141 | Line 153 | make_daemon(void)
153  
154   static int printVersion = 0;
155  
156 < static struct lgetopt myopts[] = {
157 <  {"dlinefile",  &ConfigFileEntry.dlinefile,
158 <   STRING, "File to use for dline.conf"},
147 <  {"configfile", &ConfigFileEntry.configfile,
156 > static struct lgetopt myopts[] =
157 > {
158 >  {"configfile", &ConfigGeneral.configfile,
159     STRING, "File to use for ircd.conf"},
160 <  {"klinefile",  &ConfigFileEntry.klinefile,
161 <   STRING, "File to use for kline.conf"},
162 <  {"xlinefile",  &ConfigFileEntry.xlinefile,
163 <   STRING, "File to use for xline.conf"},
164 <  {"logfile",    &logFileName,
160 >  {"glinefile",  &ConfigGeneral.glinefile,
161 >   STRING, "File to use for gline database"},
162 >  {"klinefile",  &ConfigGeneral.klinefile,
163 >   STRING, "File to use for kline database"},
164 >  {"dlinefile",  &ConfigGeneral.dlinefile,
165 >   STRING, "File to use for dline database"},
166 >  {"xlinefile",  &ConfigGeneral.xlinefile,
167 >   STRING, "File to use for xline database"},
168 >  {"resvfile",  &ConfigGeneral.resvfile,
169 >   STRING, "File to use for resv database"},
170 >  {"logfile",    &logFileName,
171     STRING, "File to use for ircd.log"},
172    {"pidfile",    &pidFileName,
173     STRING, "File to use for process ID"},
174 <  {"foreground", &server_state.foreground,
174 >  {"foreground", &server_state.foreground,
175     YESNO, "Run in foreground (don't detach)"},
176 <  {"version",    &printVersion,
176 >  {"version",    &printVersion,
177     YESNO, "Print version and exit"},
178    {"help", NULL, USAGE, "Print this text"},
179    {NULL, NULL, STRING, NULL},
# Line 165 | Line 182 | static struct lgetopt myopts[] = {
182   void
183   set_time(void)
184   {
185 <  static char to_send[200];
169 <  struct timeval newtime;
170 <  newtime.tv_sec  = 0;
171 <  newtime.tv_usec = 0;
185 >  struct timeval newtime = { .tv_sec = 0, .tv_usec = 0 };
186  
187    if (gettimeofday(&newtime, NULL) == -1)
188    {
# Line 177 | Line 191 | set_time(void)
191      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
192                           "Clock Failure (%s), TS can be corrupted",
193                           strerror(errno));
194 <    restart("Clock Failure");
194 >    server_die("Clock Failure", 1);
195    }
196  
197    if (newtime.tv_sec < CurrentTime)
198    {
199 <    snprintf(to_send, sizeof(to_send),
200 <             "System clock is running backwards - (%lu < %lu)",
201 <             (unsigned long)newtime.tv_sec, (unsigned long)CurrentTime);
202 <    report_error(L_ALL, to_send, me.name, 0);
199 >    ilog(LOG_TYPE_IRCD, "System clock is running backwards - (%lu < %lu)",
200 >         (unsigned long)newtime.tv_sec, (unsigned long)CurrentTime);
201 >    sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE,
202 >                         "System clock is running backwards - (%lu < %lu)",
203 >                         (unsigned long)newtime.tv_sec,
204 >                         (unsigned long)CurrentTime);
205      set_back_events(CurrentTime - newtime.tv_sec);
206    }
207  
# Line 196 | Line 212 | set_time(void)
212   static void
213   io_loop(void)
214   {
215 <  while (1 == 1)
215 >  while (1)
216    {
201    /*
202     * Maybe we want a flags word?
203     * ie. if (REHASHED_KLINES(global_flags))
204     * SET_REHASHED_KLINES(global_flags)
205     * CLEAR_REHASHED_KLINES(global_flags)
206     *
207     * - Dianora
208     */
209    if (rehashed_klines)
210    {
211      check_conf_klines();
212      rehashed_klines = 0;
213    }
214
217      if (listing_client_list.head)
218      {
219 <      dlink_node *ptr = NULL, *ptr_next = NULL;
220 <      DLINK_FOREACH_SAFE(ptr, ptr_next, listing_client_list.head)
221 <      {
220 <        struct Client *client_p = ptr->data;
221 <        assert(client_p->localClient->list_task);
222 <        safe_list_channels(client_p, client_p->localClient->list_task, 0);
223 <      }
219 >      dlink_node *node = NULL, *node_next = NULL;
220 >      DLINK_FOREACH_SAFE(node, node_next, listing_client_list.head)
221 >        safe_list_channels(node->data, 0);
222      }
223  
224 <    /* Run pending events, then get the number of seconds to the next
225 <     * event
228 <     */
229 <    while (eventNextTime() <= CurrentTime)
230 <      eventRun();
224 >    /* Run pending events */
225 >    event_run();
226  
227      comm_select();
228      exit_aborted_clients();
229      free_exited_clients();
235    send_queued_all();
230  
231      /* Check to see whether we have to rehash the configuration .. */
232      if (dorehash)
233      {
234 <      rehash(1);
234 >      conf_rehash(1);
235        dorehash = 0;
236      }
237 +
238      if (doremotd)
239      {
240 <      read_message_file(&ConfigFileEntry.motd);
240 >      motd_recache();
241        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
242 <                           "Got signal SIGUSR1, reloading ircd motd file");
242 >                           "Got signal SIGUSR1, reloading motd file(s)");
243        doremotd = 0;
244      }
245    }
# Line 254 | Line 249 | io_loop(void)
249   *
250   * inputs       - none
251   * output       - none
252 < * side effects - This sets all global set options needed
252 > * side effects - This sets all global set options needed
253   */
254   static void
255   initialize_global_set_options(void)
256   {
262  memset(&GlobalSetOptions, 0, sizeof(GlobalSetOptions));
263
257    GlobalSetOptions.autoconn  = 1;
258    GlobalSetOptions.spam_time = MIN_JOIN_LEAVE_TIME;
259    GlobalSetOptions.spam_num  = MAX_JOIN_LEAVE_COUNT;
260  
261 <  if (ConfigFileEntry.default_floodcount)
262 <    GlobalSetOptions.floodcount = ConfigFileEntry.default_floodcount;
261 >  if (ConfigGeneral.default_floodcount)
262 >    GlobalSetOptions.floodcount = ConfigGeneral.default_floodcount;
263    else
264      GlobalSetOptions.floodcount = 10;
265  
# Line 285 | Line 278 | initialize_global_set_options(void)
278    }
279  
280    GlobalSetOptions.ident_timeout = IDENT_TIMEOUT;
288  /* End of global set options */
289 }
290
291 /* initialize_message_files()
292 *
293 * inputs       - none
294 * output       - none
295 * side effects - Set up all message files needed, motd etc.
296 */
297 static void
298 initialize_message_files(void)
299 {
300  init_message_file(USER_MOTD, MPATH, &ConfigFileEntry.motd);
301  init_message_file(USER_LINKS, LIPATH, &ConfigFileEntry.linksfile);
302
303  read_message_file(&ConfigFileEntry.motd);
304  read_message_file(&ConfigFileEntry.linksfile);
305
306  init_isupport();
281   }
282  
283   /* initialize_server_capabs()
# Line 319 | Line 293 | initialize_server_capabs(void)
293    add_capability("TS6", CAP_TS6, 0);
294    add_capability("CLUSTER", CAP_CLUSTER, 1);
295    add_capability("SVS", CAP_SVS, 1);
296 < #ifdef HALFOPS
296 >  add_capability("CHW", CAP_CHW, 1);
297    add_capability("HOPS", CAP_HOPS, 1);
324 #endif
298   }
299  
300   /* write_pidfile()
# Line 337 | Line 310 | write_pidfile(const char *filename)
310  
311    if ((fb = fopen(filename, "w")))
312    {
313 <    char buff[32];
313 >    char buff[IRCD_BUFSIZE];
314      unsigned int pid = (unsigned int)getpid();
315  
316      snprintf(buff, sizeof(buff), "%u\n", pid);
317  
318 <    if ((fputs(buff, fb) == -1))
318 >    if (fputs(buff, fb) == -1)
319        ilog(LOG_TYPE_IRCD, "Error writing %u to pid file %s (%s)",
320             pid, filename, strerror(errno));
321  
# Line 350 | Line 323 | write_pidfile(const char *filename)
323    }
324    else
325    {
326 <    ilog(LOG_TYPE_IRCD, "Error opening pid file %s", filename);
326 >    ilog(LOG_TYPE_IRCD, "Error opening pid file %s (%s)",
327 >         filename, strerror(errno));
328    }
329   }
330  
# Line 366 | Line 340 | static void
340   check_pidfile(const char *filename)
341   {
342    FILE *fb;
343 <  char buff[32];
343 >  char buff[IRCD_BUFSIZE];
344    pid_t pidfromfile;
345  
346    /* Don't do logging here, since we don't have log() initialised */
347    if ((fb = fopen(filename, "r")))
348    {
349 <    if (fgets(buff, 20, fb) == NULL)
349 >    if (!fgets(buff, 20, fb))
350      {
351        /* log(L_ERROR, "Error reading from pid file %s (%s)", filename,
352         * strerror(errno));
# Line 420 | Line 394 | setup_corefile(void)
394   #endif
395   }
396  
397 + #ifdef HAVE_LIBCRYPTO
398 + static int
399 + always_accept_verify_cb(int preverify_ok, X509_STORE_CTX *x509_ctx)
400 + {
401 +  return 1;
402 + }
403 + #endif
404 +
405   /* init_ssl()
406   *
407   * inputs       - nothing
# Line 427 | Line 409 | setup_corefile(void)
409   * side effects - setups SSL context.
410   */
411   static void
412 < init_ssl(void)
412 > ssl_init(void)
413   {
414   #ifdef HAVE_LIBCRYPTO
415    SSL_load_error_strings();
416    SSLeay_add_ssl_algorithms();
417  
418 <  if ((ServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL)
418 >  if (!(ConfigServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method())))
419    {
420 <    const char *s;
420 >    const char *s = ERR_lib_error_string(ERR_get_error());
421  
422 <    fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n",
423 <            s = ERR_lib_error_string(ERR_get_error()));
424 <    ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s\n", s);
422 >    fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n", s);
423 >    ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s", s);
424 >    exit(EXIT_FAILURE);
425 >    return;  /* Not reached */
426    }
427  
428 <  SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1);
429 <  SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
430 <  SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_NONE, NULL);
428 >  SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TICKET);
429 >  SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_DH_USE|SSL_OP_CIPHER_SERVER_PREFERENCE);
430 >  SSL_CTX_set_verify(ConfigServerInfo.server_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
431 >                     always_accept_verify_cb);
432 >  SSL_CTX_set_session_cache_mode(ConfigServerInfo.server_ctx, SSL_SESS_CACHE_OFF);
433 >  SSL_CTX_set_cipher_list(ConfigServerInfo.server_ctx, "EECDH+HIGH:EDH+HIGH:HIGH:!aNULL");
434  
435 <  if ((ServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL)
435 > #if OPENSSL_VERSION_NUMBER >= 0x009080FFL && !defined(OPENSSL_NO_ECDH)
436    {
437 <    const char *s;
437 >    EC_KEY *key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
438  
439 <    fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n",
440 <            s = ERR_lib_error_string(ERR_get_error()));
441 <    ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s\n", s);
439 >    if (key)
440 >    {
441 >      SSL_CTX_set_tmp_ecdh(ConfigServerInfo.server_ctx, key);
442 >      EC_KEY_free(key);
443 >    }
444    }
445  
446 <  SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1);
447 <  SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
460 <  SSL_CTX_set_verify(ServerInfo.client_ctx, SSL_VERIFY_NONE, NULL);
461 < #endif /* HAVE_LIBCRYPTO */
462 < }
446 >  SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_ECDH_USE);
447 > #endif
448  
449 < /* init_callbacks()
450 < *
451 < * inputs       - nothing
452 < * output       - nothing
453 < * side effects - setups standard hook points
454 < */
455 < static void
456 < init_callbacks(void)
457 < {
458 <  iorecv_cb = register_callback("iorecv", iorecv_default);
459 <  iosend_cb = register_callback("iosend", iosend_default);
449 >  if (!(ConfigServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())))
450 >  {
451 >    const char *s = ERR_lib_error_string(ERR_get_error());
452 >
453 >    fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n", s);
454 >    ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s", s);
455 >    exit(EXIT_FAILURE);
456 >    return;  /* Not reached */
457 >  }
458 >
459 >  SSL_CTX_set_options(ConfigServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TICKET);
460 >  SSL_CTX_set_options(ConfigServerInfo.client_ctx, SSL_OP_SINGLE_DH_USE);
461 >  SSL_CTX_set_verify(ConfigServerInfo.client_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
462 >                     always_accept_verify_cb);
463 >  SSL_CTX_set_session_cache_mode(ConfigServerInfo.client_ctx, SSL_SESS_CACHE_OFF);
464 > #endif /* HAVE_LIBCRYPTO */
465   }
466  
467   int
468   main(int argc, char *argv[])
469   {
470 <  /* Check to see if the user is running
471 <   * us as root, which is a nono
482 <   */
483 <  if (geteuid() == 0)
470 >  /* Check to see if the user is running us as root, which is a nono */
471 >  if (!geteuid())
472    {
473 <    fprintf(stderr, "Don't run ircd as root!!!\n");
473 >    fprintf(stderr, "ERROR: This server won't run as root/superuser\n");
474      return -1;
475    }
476  
# Line 495 | Line 483 | main(int argc, char *argv[])
483    /* It ain't random, but it ought to be a little harder to guess */
484    init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20)));
485  
486 <  me.localClient = &meLocalUser;
499 <  dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning
486 >  dlinkAdd(&me, &me.node, &global_client_list);  /* Pointer to beginning
487                                                     of Client list */
488 <  /* Initialise the channel capability usage counts... */
489 <  init_chcap_usage_counts();
488 >  ConfigLog.use_logging = 1;
489 >  ConfigGeneral.dpath      = DPATH;
490 >  ConfigGeneral.spath      = SPATH;
491 >  ConfigGeneral.mpath      = MPATH;
492 >  ConfigGeneral.configfile = CPATH;    /* Server configuration file */
493 >  ConfigGeneral.klinefile  = KPATH;    /* Server kline file         */
494 >  ConfigGeneral.glinefile  = GPATH;    /* Server gline file         */
495 >  ConfigGeneral.xlinefile  = XPATH;    /* Server xline file         */
496 >  ConfigGeneral.dlinefile  = DLPATH;   /* dline file                */
497 >  ConfigGeneral.resvfile   = RESVPATH; /* resv file                 */
498  
504  ConfigFileEntry.dpath      = DPATH;
505  ConfigFileEntry.configfile = CPATH;  /* Server configuration file */
506  ConfigFileEntry.klinefile  = KPATH;  /* Server kline file         */
507  ConfigFileEntry.xlinefile  = XPATH;  /* Server xline file         */
508  ConfigFileEntry.dlinefile  = DLPATH; /* dline file                */
509 //  ConfigFileEntry.cresvfile  = CRESVPATH; /* channel resv file      */
510 //  ConfigFileEntry.nresvfile  = NRESVPATH; /* nick resv file         */
499    myargv = argv;
500    umask(077);                /* better safe than sorry --SRB */
501  
# Line 515 | Line 503 | main(int argc, char *argv[])
503  
504    if (printVersion)
505    {
506 <    printf("ircd: version %s\n", ircd_version);
506 >    printf("ircd: version %s(%s)\n", ircd_version, serno);
507      exit(EXIT_SUCCESS);
508    }
509  
510 <  if (chdir(ConfigFileEntry.dpath))
510 >  if (chdir(ConfigGeneral.dpath))
511    {
512      perror("chdir");
513      exit(EXIT_FAILURE);
514    }
515  
516 <  init_ssl();
516 >  ssl_init();
517  
518    if (!server_state.foreground)
519    {
# Line 537 | Line 525 | main(int argc, char *argv[])
525  
526    setup_signals();
527  
540  /* Init the event subsystem */
541  eventInit();
528    /* We need this to initialise the fd array before anything else */
529    fdlist_init();
530 <  log_add_file(LOG_TYPE_IRCD, 0, logFileName);
531 <  check_can_use_v6();
532 <  init_comm();         /* This needs to be setup early ! -- adrian */
530 >  log_set_file(LOG_TYPE_IRCD, 0, logFileName);
531 >
532 >  init_netio();         /* This needs to be setup early ! -- adrian */
533 >
534    /* Check if there is pidfile and daemon already running */
535    check_pidfile(pidFileName);
536  
537 <  initBlockHeap();
537 >  mp_pool_init();
538    init_dlink_nodes();
539 <  init_callbacks();
553 <  initialize_message_files();
539 >  init_isupport();
540    dbuf_init();
541 <  init_hash();
542 <  init_ip_hash_table();      /* client host ip hash table */
543 <  init_host_hash();          /* Host-hashtable. */
544 <  init_client();
559 <  init_class();
541 >  hash_init();
542 >  ipcache_init();
543 >  client_init();
544 >  class_init();
545    whowas_init();
546    watch_init();
547 <  init_auth();          /* Initialise the auth code */
547 >  auth_init();          /* Initialise the auth code */
548    init_resolver();      /* Needs to be setup before the io loop */
549    modules_init();
550    read_conf_files(1);   /* cold start init conf files */
551    init_uid();
552    initialize_server_capabs();   /* Set up default_server_capabs */
553    initialize_global_set_options();
554 <  init_channels();
554 >  channel_init();
555 >  read_links_file();
556 >  motd_init();
557 >  user_usermodes_init();
558 > #ifdef HAVE_LIBGEOIP
559 >  geoip_ctx = GeoIP_new(GEOIP_MEMORY_CACHE);
560 > #endif
561  
562 <  if (EmptyString(ServerInfo.sid))
562 >  if (EmptyString(ConfigServerInfo.sid))
563    {
564      ilog(LOG_TYPE_IRCD, "ERROR: No server id specified in serverinfo block.");
565      exit(EXIT_FAILURE);
566    }
567  
568 <  strlcpy(me.id, ServerInfo.sid, sizeof(me.id));
568 >  strlcpy(me.id, ConfigServerInfo.sid, sizeof(me.id));
569  
570 <  if (EmptyString(ServerInfo.name))
570 >  if (EmptyString(ConfigServerInfo.name))
571    {
572      ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block.");
573      exit(EXIT_FAILURE);
574    }
575  
576 <  strlcpy(me.name, ServerInfo.name, sizeof(me.name));
576 >  strlcpy(me.name, ConfigServerInfo.name, sizeof(me.name));
577  
578    /* serverinfo{} description must exist.  If not, error out.*/
579 <  if (EmptyString(ServerInfo.description))
579 >  if (EmptyString(ConfigServerInfo.description))
580    {
581      ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block.");
582      exit(EXIT_FAILURE);
583    }
584  
585 <  strlcpy(me.info, ServerInfo.description, sizeof(me.info));
585 >  strlcpy(me.info, ConfigServerInfo.description, sizeof(me.info));
586  
587    me.from                   = &me;
588    me.servptr                = &me;
589 <  me.localClient->lasttime  = CurrentTime;
590 <  me.localClient->since     = CurrentTime;
591 <  me.localClient->firsttime = CurrentTime;
589 >  me.connection->lasttime  = CurrentTime;
590 >  me.connection->since     = CurrentTime;
591 >  me.connection->firsttime = CurrentTime;
592  
593    SetMe(&me);
594    make_server(&me);
595  
596    hash_add_id(&me);
597    hash_add_client(&me);
598 <  
599 <  /* add ourselves to global_serv_list */
609 <  dlinkAdd(&me, make_dlink_node(), &global_serv_list);
598 >
599 >  dlinkAdd(&me, make_dlink_node(), &global_server_list);
600  
601    load_kline_database();
602    load_dline_database();
# Line 614 | Line 604 | main(int argc, char *argv[])
604    load_xline_database();
605    load_resv_database();
606  
617  if (chdir(MODPATH))
618  {
619    ilog(LOG_TYPE_IRCD, "Could not load core modules. Terminating!");
620    exit(EXIT_FAILURE);
621  }
622
607    load_all_modules(1);
608    load_conf_modules();
609    load_core_modules(1);
610  
627  /* Go back to DPATH after checking to see if we can chdir to MODPATH */
628  if (chdir(ConfigFileEntry.dpath))
629  {
630    perror("chdir");
631    exit(EXIT_FAILURE);
632  }
633
634  /*
635   * assemble_umode_buffer() has to be called after
636   * reading conf/loading modules.
637   */
638  assemble_umode_buffer();
639
611    write_pidfile(pidFileName);
612  
613    ilog(LOG_TYPE_IRCD, "Server Ready");
614  
615 <  eventAddIsh("cleanup_glines", cleanup_glines, NULL, CLEANUP_GLINES_TIME);
616 <  eventAddIsh("cleanup_tklines", cleanup_tklines, NULL, CLEANUP_TKLINES_TIME);
615 >  event_addish(&event_cleanup_glines, NULL);
616 >  event_addish(&event_cleanup_tklines, NULL);
617  
618    /* We want try_connections to be called as soon as possible now! -- adrian */
619    /* No, 'cause after a restart it would cause all sorts of nick collides */
620 <  eventAddIsh("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME);
620 >  event_addish(&event_try_connections, NULL);
621  
622    /* Setup the timeout check. I'll shift it later :)  -- adrian */
623 <  eventAddIsh("comm_checktimeouts", comm_checktimeouts, NULL, 1);
623 >  event_add(&event_comm_checktimeouts, NULL);
624  
625 <  eventAddIsh("save_all_databases", save_all_databases, NULL, DATABASE_UPDATE_TIMEOUT);
625 >  event_addish(&event_save_all_databases, NULL);
626  
627    if (ConfigServerHide.links_delay > 0)
628 <    eventAddIsh("write_links_file", write_links_file, NULL, ConfigServerHide.links_delay);
628 >  {
629 >    event_write_links_file.when = ConfigServerHide.links_delay;
630 >    event_addish(&event_write_links_file, NULL);
631 >  }
632    else
633      ConfigServerHide.links_disabled = 1;
634  
635    if (splitmode)
636 <    eventAddIsh("check_splitmode", check_splitmode, NULL, 60);
636 >    event_addish(&splitmode_event, NULL);
637  
638    io_loop();
639    return 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)