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-7.2/src/ircd.c (file contents), Revision 876 by michael, Wed Oct 24 21:51:21 2007 UTC vs.
ircd-hybrid/trunk/src/ircd.c (file contents), Revision 3215 by michael, Tue Mar 25 19:23:15 2014 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-2014 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 18 | Line 17
17   *  along with this program; if not, write to the Free Software
18   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
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"
29 < #include "tools.h"
29 > #include "list.h"
30   #include "ircd.h"
31   #include "channel.h"
32   #include "channel_mode.h"
33   #include "client.h"
32 #include "common.h"
34   #include "event.h"
35   #include "fdlist.h"
36   #include "hash.h"
37   #include "irc_string.h"
37 #include "sprintf_irc.h"
38   #include "ircd_signal.h"
39 #include "list.h"
39   #include "s_gline.h"
40   #include "motd.h"
41 < #include "ircd_handler.h"
43 < #include "msg.h"         /* msgtab */
41 > #include "conf.h"
42   #include "hostmask.h"
43   #include "numeric.h"
44   #include "packet.h"
45   #include "parse.h"
46   #include "irc_res.h"
47   #include "restart.h"
48 + #include "rng_mt.h"
49   #include "s_auth.h"
50   #include "s_bsd.h"
51 < #include "s_conf.h"
53 < #include "s_log.h"
51 > #include "log.h"
52   #include "s_misc.h"
53   #include "s_serv.h"      /* try_connections */
56 #include "s_stats.h"
54   #include "send.h"
55   #include "whowas.h"
56   #include "modules.h"
57   #include "memory.h"
58 + #include "mempool.h"
59   #include "hook.h"
60   #include "ircd_getopt.h"
63 #include "balloc.h"
64 #include "motd.h"
61   #include "supported.h"
62   #include "watch.h"
63 + #include "conf_db.h"
64 + #include "conf_class.h"
65  
66 < /* Try and find the correct name to use with getrlimit() for setting the max.
67 < * number of files allowed to be open by this process.
68 < */
66 >
67 > #ifdef HAVE_LIBGEOIP
68 > GeoIP *geoip_ctx;
69 > #endif
70  
71   /* /quote set variables */
72   struct SetOptions GlobalSetOptions;
73 <
74 < /* configuration set from ircd.conf */
75 < struct config_file_entry ConfigFileEntry;
77 < /* server info set from ircd.conf */
78 < struct server_info ServerInfo;
79 < /* admin info set from ircd.conf */
80 < struct admin_info AdminInfo = { NULL, NULL, NULL };
81 < struct Counter Count = { 0, 0, 0, 0, 0, 0, 0, 0 };
82 < struct ServerState_t server_state = { 0 };
83 < struct logging_entry ConfigLoggingEntry = { 1, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0} };
73 > struct Counter Count;
74 > struct ServerState_t server_state;
75 > struct ServerStatistics ServerStats;
76   struct timeval SystemTime;
77   struct Client me;             /* That's me */
78   struct LocalUser meLocalUser; /* That's also part of me */
87 unsigned long connect_id = 0; /* unique connect ID */
79  
89 static unsigned long initialVMTop = 0;   /* top of virtual memory at init */
80   const char *logFileName = LPATH;
81   const char *pidFileName = PPATH;
82  
83   char **myargv;
94 char ircd_platform[PLATFORMLEN];
84  
85   int dorehash = 0;
86   int doremotd = 0;
98 time_t nextconnect = 1;       /* time for next try_connections call */
87  
88   /* Set to zero because it should be initialized later using
89   * initialize_server_capabs
90   */
91   int default_server_capabs = 0;
92 <
93 < #ifdef HAVE_LIBCRYPTO
94 < int bio_spare_fd = -1;
107 < #endif
108 <
109 < int splitmode;
110 < int splitchecking;
111 < int split_users;
92 > unsigned int splitmode;
93 > unsigned int splitchecking;
94 > unsigned int split_users;
95   unsigned int split_servers;
96  
97   /* Do klines the same way hybrid-6 did them, i.e. at the
# Line 123 | Line 106 | unsigned int split_servers;
106  
107   int rehashed_klines = 0;
108  
126 /*
127 * get_vm_top - get the operating systems notion of the resident set size
128 */
129 #ifndef _WIN32
130 static unsigned long
131 get_vm_top(void)
132 {
133  /*
134   * NOTE: sbrk is not part of the ANSI C library or the POSIX.1 standard
135   * however it seems that everyone defines it. Calling sbrk with a 0
136   * argument will return a pointer to the top of the process virtual
137   * memory without changing the process size, so this call should be
138   * reasonably safe (sbrk returns the new value for the top of memory).
139   * This code relies on the notion that the address returned will be an
140   * offset from 0 (NULL), so the result of sbrk is cast to a size_t and
141   * returned. We really shouldn't be using it here but...
142   */
143
144  void *vptr = sbrk(0);
145  return((unsigned long)vptr);
146 }
109  
110   /*
111   * print_startup - print startup information
# Line 151 | Line 113 | get_vm_top(void)
113   static void
114   print_startup(int pid)
115   {
116 <  printf("ircd: version %s\n", ircd_version);
116 >  printf("ircd: version %s(%s)\n", ircd_version, serno);
117    printf("ircd: pid %d\n", pid);
118    printf("ircd: running in %s mode from %s\n", !server_state.foreground ? "background"
119           : "foreground", ConfigFileEntry.dpath);
# Line 175 | Line 137 | make_daemon(void)
137  
138    setsid();
139   }
178 #endif
179
180 /*
181 * get_maxrss - get the operating systems notion of the resident set size
182 */
183 unsigned long
184 get_maxrss(void)
185 {
186 #ifdef _WIN32
187  return (0);   /* FIXME */
188 #else
189  return (get_vm_top() - initialVMTop);
190 #endif
191 }
140  
141   static int printVersion = 0;
142  
143 < struct lgetopt myopts[] = {
144 <  {"dlinefile",  &ConfigFileEntry.dlinefile,
145 <   STRING, "File to use for dline.conf"},
198 <  {"configfile", &ConfigFileEntry.configfile,
143 > static struct lgetopt myopts[] =
144 > {
145 >  {"configfile", &ConfigFileEntry.configfile,
146     STRING, "File to use for ircd.conf"},
147 <  {"klinefile",  &ConfigFileEntry.klinefile,
148 <   STRING, "File to use for kline.conf"},
149 <  {"xlinefile",  &ConfigFileEntry.xlinefile,
150 <   STRING, "File to use for xline.conf"},
151 <  {"logfile",    &logFileName,
147 >  {"glinefile",  &ConfigFileEntry.glinefile,
148 >   STRING, "File to use for gline database"},
149 >  {"klinefile",  &ConfigFileEntry.klinefile,
150 >   STRING, "File to use for kline database"},
151 >  {"dlinefile",  &ConfigFileEntry.dlinefile,
152 >   STRING, "File to use for dline database"},
153 >  {"xlinefile",  &ConfigFileEntry.xlinefile,
154 >   STRING, "File to use for xline database"},
155 >  {"resvfile",  &ConfigFileEntry.resvfile,
156 >   STRING, "File to use for resv database"},
157 >  {"logfile",    &logFileName,
158     STRING, "File to use for ircd.log"},
159    {"pidfile",    &pidFileName,
160     STRING, "File to use for process ID"},
161 <  {"foreground", &server_state.foreground,
161 >  {"foreground", &server_state.foreground,
162     YESNO, "Run in foreground (don't detach)"},
163 <  {"version",    &printVersion,
163 >  {"version",    &printVersion,
164     YESNO, "Print version and exit"},
165    {"help", NULL, USAGE, "Print this text"},
166    {NULL, NULL, STRING, NULL},
# Line 216 | Line 169 | struct lgetopt myopts[] = {
169   void
170   set_time(void)
171   {
172 <  static char to_send[200];
220 <  struct timeval newtime;
221 < #ifdef _WIN32
222 <  FILETIME ft;
223 <
224 <  GetSystemTimeAsFileTime(&ft);
225 <  if (ft.dwLowDateTime < 0xd53e8000)
226 <    ft.dwHighDateTime--;
227 <  ft.dwLowDateTime -= 0xd53e8000;
228 <  ft.dwHighDateTime -= 0x19db1de;
229 <
230 <  newtime.tv_sec  = (*(uint64_t *) &ft) / 10000000;
231 <  newtime.tv_usec = (*(uint64_t *) &ft) / 10 % 1000000;
232 < #else
233 <  newtime.tv_sec  = 0;
234 <  newtime.tv_usec = 0;
172 >  struct timeval newtime = { .tv_sec = 0, .tv_usec = 0 };
173  
174    if (gettimeofday(&newtime, NULL) == -1)
175    {
176 <    ilog(L_ERROR, "Clock Failure (%s), TS can be corrupted",
176 >    ilog(LOG_TYPE_IRCD, "Clock Failure (%s), TS can be corrupted",
177           strerror(errno));
178 <    sendto_realops_flags(UMODE_ALL, L_ALL,
178 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
179                           "Clock Failure (%s), TS can be corrupted",
180                           strerror(errno));
181 <    restart("Clock Failure");
181 >    server_die("Clock Failure", 1);
182    }
245 #endif
183  
184    if (newtime.tv_sec < CurrentTime)
185    {
186 <    ircsprintf(to_send, "System clock is running backwards - (%lu < %lu)",
187 <               (unsigned long)newtime.tv_sec, (unsigned long)CurrentTime);
188 <    report_error(L_ALL, to_send, me.name, 0);
186 >    ilog(LOG_TYPE_IRCD, "System clock is running backwards - (%lu < %lu)",
187 >         (unsigned long)newtime.tv_sec, (unsigned long)CurrentTime);
188 >    sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE,
189 >                         "System clock is running backwards - (%lu < %lu)",
190 >                         (unsigned long)newtime.tv_sec,
191 >                         (unsigned long)CurrentTime);
192      set_back_events(CurrentTime - newtime.tv_sec);
193    }
194  
# Line 259 | Line 199 | set_time(void)
199   static void
200   io_loop(void)
201   {
202 <  while (1 == 1)
202 >  while (1)
203    {
204      /*
205       * Maybe we want a flags word?
206 <     * ie. if (REHASHED_KLINES(global_flags))
206 >     * ie. if (REHASHED_KLINES(global_flags))
207       * SET_REHASHED_KLINES(global_flags)
208       * CLEAR_REHASHED_KLINES(global_flags)
209       *
# Line 282 | Line 222 | io_loop(void)
222        {
223          struct Client *client_p = ptr->data;
224          assert(client_p->localClient->list_task);
225 <        safe_list_channels(client_p, client_p->localClient->list_task, 0, 0);
225 >        safe_list_channels(client_p, client_p->localClient->list_task, 0);
226        }
227      }
228  
# Line 295 | Line 235 | io_loop(void)
235      comm_select();
236      exit_aborted_clients();
237      free_exited_clients();
298    send_queued_all();
238  
239      /* Check to see whether we have to rehash the configuration .. */
240      if (dorehash)
# Line 303 | Line 242 | io_loop(void)
242        rehash(1);
243        dorehash = 0;
244      }
245 +
246      if (doremotd)
247      {
248 <      read_message_file(&ConfigFileEntry.motd);
249 <      sendto_realops_flags(UMODE_ALL, L_ALL,
250 <                           "Got signal SIGUSR1, reloading ircd motd file");
248 >      motd_recache();
249 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
250 >                           "Got signal SIGUSR1, reloading motd file(s)");
251        doremotd = 0;
252      }
253    }
# Line 317 | Line 257 | io_loop(void)
257   *
258   * inputs       - none
259   * output       - none
260 < * side effects - This sets all global set options needed
260 > * side effects - This sets all global set options needed
261   */
262   static void
263   initialize_global_set_options(void)
# Line 348 | Line 288 | initialize_global_set_options(void)
288    }
289  
290    GlobalSetOptions.ident_timeout = IDENT_TIMEOUT;
351  GlobalSetOptions.idletime = ConfigFileEntry.idletime;
291    /* End of global set options */
292   }
293  
355 /* initialize_message_files()
356 *
357 * inputs       - none
358 * output       - none
359 * side effects - Set up all message files needed, motd etc.
360 */
361 static void
362 initialize_message_files(void)
363 {
364  init_message_file(USER_MOTD, MPATH, &ConfigFileEntry.motd);
365  init_message_file(OPER_MOTD, OPATH, &ConfigFileEntry.opermotd);
366  init_message_file(USER_LINKS, LIPATH, &ConfigFileEntry.linksfile);
367
368  read_message_file(&ConfigFileEntry.motd);
369  read_message_file(&ConfigFileEntry.opermotd);
370  read_message_file(&ConfigFileEntry.linksfile);
371
372  init_isupport();
373 }
374
294   /* initialize_server_capabs()
295   *
296   * inputs       - none
# Line 381 | Line 300 | static void
300   initialize_server_capabs(void)
301   {
302    add_capability("QS", CAP_QS, 1);
384  add_capability("LL", CAP_LL, 1);
303    add_capability("EOB", CAP_EOB, 1);
304 <  if (ServerInfo.sid != NULL)   /* only enable TS6 if we have an SID */
387 <    add_capability("TS6", CAP_TS6, 0);
388 <  add_capability("ZIP", CAP_ZIP, 0);
304 >  add_capability("TS6", CAP_TS6, 0);
305    add_capability("CLUSTER", CAP_CLUSTER, 1);
306 +  add_capability("SVS", CAP_SVS, 1);
307   #ifdef HALFOPS
308    add_capability("HOPS", CAP_HOPS, 1);
309   #endif
# Line 401 | Line 318 | initialize_server_capabs(void)
318   static void
319   write_pidfile(const char *filename)
320   {
321 <  FBFILE *fb;
321 >  FILE *fb;
322  
323 <  if ((fb = fbopen(filename, "w")))
323 >  if ((fb = fopen(filename, "w")))
324    {
325 <    char buff[32];
325 >    char buff[IRCD_BUFSIZE];
326      unsigned int pid = (unsigned int)getpid();
410    size_t nbytes = ircsprintf(buff, "%u\n", pid);
327  
328 <    if ((fbputs(buff, fb, nbytes) == -1))
329 <      ilog(L_ERROR, "Error writing %u to pid file %s (%s)",
328 >    snprintf(buff, sizeof(buff), "%u\n", pid);
329 >
330 >    if ((fputs(buff, fb) == -1))
331 >      ilog(LOG_TYPE_IRCD, "Error writing %u to pid file %s (%s)",
332             pid, filename, strerror(errno));
333  
334 <    fbclose(fb);
417 <    return;
334 >    fclose(fb);
335    }
336    else
337    {
338 <    ilog(L_ERROR, "Error opening pid file %s", filename);
338 >    ilog(LOG_TYPE_IRCD, "Error opening pid file %s", filename);
339    }
340   }
341  
# Line 433 | Line 350 | write_pidfile(const char *filename)
350   static void
351   check_pidfile(const char *filename)
352   {
353 < #ifndef _WIN32
354 <  FBFILE *fb;
438 <  char buff[32];
353 >  FILE *fb;
354 >  char buff[IRCD_BUFSIZE];
355    pid_t pidfromfile;
356  
357    /* Don't do logging here, since we don't have log() initialised */
358 <  if ((fb = fbopen(filename, "r")))
358 >  if ((fb = fopen(filename, "r")))
359    {
360 <    if (fbgets(buff, 20, fb) == NULL)
360 >    if (fgets(buff, 20, fb) == NULL)
361      {
362        /* log(L_ERROR, "Error reading from pid file %s (%s)", filename,
363         * strerror(errno));
# Line 459 | Line 375 | check_pidfile(const char *filename)
375        }
376      }
377  
378 <    fbclose(fb);
378 >    fclose(fb);
379    }
380    else if (errno != ENOENT)
381    {
382      /* log(L_ERROR, "Error opening pid file %s", filename); */
383    }
468 #endif
384   }
385  
386   /* setup_corefile()
# Line 490 | Line 405 | setup_corefile(void)
405   #endif
406   }
407  
408 + #ifdef HAVE_LIBCRYPTO
409 + static int
410 + always_accept_verify_cb(int preverify_ok, X509_STORE_CTX *x509_ctx)
411 + {
412 +  return 1;
413 + }
414 + #endif
415 +
416   /* init_ssl()
417   *
418   * inputs       - nothing
# Line 497 | Line 420 | setup_corefile(void)
420   * side effects - setups SSL context.
421   */
422   static void
423 < init_ssl(void)
423 > ssl_init(void)
424   {
425   #ifdef HAVE_LIBCRYPTO
426 +  const unsigned char session_id[] = "ircd-hybrid";
427 +
428    SSL_load_error_strings();
429    SSLeay_add_ssl_algorithms();
430  
431 <  ServerInfo.ctx = SSL_CTX_new(SSLv23_server_method());
507 <  if (!ServerInfo.ctx)
431 >  if ((ServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL)
432    {
433      const char *s;
434  
435 <    fprintf(stderr, "ERROR: Could not initialize the SSL context -- %s\n",
435 >    fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n",
436              s = ERR_lib_error_string(ERR_get_error()));
437 <    ilog(L_CRIT, "ERROR: Could not initialize the SSL context -- %s\n", s);
437 >    ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s\n", s);
438    }
439  
440 <  SSL_CTX_set_options(ServerInfo.ctx, SSL_OP_NO_SSLv2);
441 <  SSL_CTX_set_options(ServerInfo.ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
442 <  SSL_CTX_set_verify(ServerInfo.ctx, SSL_VERIFY_NONE, NULL);
440 >  SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1);
441 >  SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
442 >  SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
443 >                     always_accept_verify_cb);
444 >  SSL_CTX_set_session_id_context(ServerInfo.server_ctx, session_id, sizeof(session_id) - 1);
445  
446 <  bio_spare_fd = save_spare_fd("SSL private key validation");
447 < #endif /* HAVE_LIBCRYPTO */
448 < }
446 >  if ((ServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL)
447 >  {
448 >    const char *s;
449  
450 < /* init_callbacks()
451 < *
452 < * inputs       - nothing
453 < * output       - nothing
454 < * side effects - setups standard hook points
455 < */
456 < static void
457 < init_callbacks(void)
458 < {
459 <  iorecv_cb = register_callback("iorecv", iorecv_default);
534 <  iosend_cb = register_callback("iosend", iosend_default);
535 <  iorecvctrl_cb = register_callback("iorecvctrl", NULL);
536 <  iosendctrl_cb = register_callback("iosendctrl", NULL);
450 >    fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n",
451 >            s = ERR_lib_error_string(ERR_get_error()));
452 >    ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s\n", s);
453 >  }
454 >
455 >  SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1);
456 >  SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
457 >  SSL_CTX_set_verify(ServerInfo.client_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
458 >                     always_accept_verify_cb);
459 > #endif /* HAVE_LIBCRYPTO */
460   }
461  
462   int
463   main(int argc, char *argv[])
464   {
465 <  /* Check to see if the user is running
543 <   * us as root, which is a nono
544 <   */
545 < #ifndef _WIN32
465 >  /* Check to see if the user is running us as root, which is a nono */
466    if (geteuid() == 0)
467    {
468      fprintf(stderr, "Don't run ircd as root!!!\n");
469 <    return(-1);
469 >    return -1;
470    }
471  
472    /* Setup corefile size immediately after boot -kre */
473    setup_corefile();
474  
555  /* set initialVMTop before we allocate any memory */
556  initialVMTop = get_vm_top();
557 #endif
558
475    /* save server boot time right away, so getrusage works correctly */
476    set_time();
477  
478 <    /* It ain't random, but it ought to be a little harder to guess */
479 <  srand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20)));
480 <  memset(&me, 0, sizeof(me));
565 <  memset(&meLocalUser, 0, sizeof(meLocalUser));
478 >  /* It ain't random, but it ought to be a little harder to guess */
479 >  init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20)));
480 >
481    me.localClient = &meLocalUser;
482 <  dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning
482 >  dlinkAdd(&me, &me.node, &global_client_list);  /* Pointer to beginning
483                                                     of Client list */
569
570  memset(&ServerInfo, 0, sizeof(ServerInfo));
571
572  /* Initialise the channel capability usage counts... */
573  init_chcap_usage_counts();
574
484    ConfigFileEntry.dpath      = DPATH;
485 <  ConfigFileEntry.configfile = CPATH;  /* Server configuration file */
486 <  ConfigFileEntry.klinefile  = KPATH;  /* Server kline file         */
487 <  ConfigFileEntry.xlinefile  = XPATH;  /* Server xline file         */
488 <  ConfigFileEntry.rxlinefile = RXPATH; /* Server regex xline file   */
489 <  ConfigFileEntry.rklinefile = RKPATH; /* Server regex kline file   */
490 <  ConfigFileEntry.dlinefile  = DLPATH; /* dline file                */
491 <  ConfigFileEntry.glinefile  = GPATH;  /* gline log file            */
583 <  ConfigFileEntry.cresvfile  = CRESVPATH; /* channel resv file      */
584 <  ConfigFileEntry.nresvfile  = NRESVPATH; /* nick resv file         */
485 >  ConfigFileEntry.configfile = CPATH;    /* Server configuration file */
486 >  ConfigFileEntry.klinefile  = KPATH;    /* Server kline file         */
487 >  ConfigFileEntry.glinefile  = GPATH;    /* Server gline file         */
488 >  ConfigFileEntry.xlinefile  = XPATH;    /* Server xline file         */
489 >  ConfigFileEntry.dlinefile  = DLPATH;   /* dline file                */
490 >  ConfigFileEntry.resvfile   = RESVPATH; /* resv file                 */
491 >
492    myargv = argv;
493    umask(077);                /* better safe than sorry --SRB */
494  
# Line 589 | Line 496 | main(int argc, char *argv[])
496  
497    if (printVersion)
498    {
499 <    printf("ircd: version %s\n", ircd_version);
499 >    printf("ircd: version %s(%s)\n", ircd_version, serno);
500      exit(EXIT_SUCCESS);
501    }
502  
# Line 599 | Line 506 | main(int argc, char *argv[])
506      exit(EXIT_FAILURE);
507    }
508  
509 <  init_ssl();
509 >  ssl_init();
510  
604 #ifndef _WIN32
511    if (!server_state.foreground)
512    {
513      make_daemon();
# Line 611 | Line 517 | main(int argc, char *argv[])
517      print_startup(getpid());
518  
519    setup_signals();
614 #endif
615
616  get_ircd_platform(ircd_platform);
520  
521    /* Init the event subsystem */
522    eventInit();
523 +
524    /* We need this to initialise the fd array before anything else */
525    fdlist_init();
526 <  init_log(logFileName);
526 >  log_set_file(LOG_TYPE_IRCD, 0, logFileName);
527    check_can_use_v6();
528 <  init_comm();         /* This needs to be setup early ! -- adrian */
528 >  init_netio();         /* This needs to be setup early ! -- adrian */
529 >
530    /* Check if there is pidfile and daemon already running */
531    check_pidfile(pidFileName);
532  
533 < #ifndef NOBALLOC
629 <  initBlockHeap();
630 < #endif
533 >  mp_pool_init();
534    init_dlink_nodes();
535 <  init_callbacks();
633 <  initialize_message_files();
535 >  init_isupport();
536    dbuf_init();
537 <  init_hash();
537 >  hash_init();
538    init_ip_hash_table();      /* client host ip hash table */
539    init_host_hash();          /* Host-hashtable. */
540 <  clear_tree_parse();
541 <  init_client();
542 <  init_class();
641 <  init_whowas();
540 >  client_init();
541 >  class_init();
542 >  whowas_init();
543    watch_init();
544 <  init_stats();
544 >  auth_init();          /* Initialise the auth code */
545 >  init_resolver();      /* Needs to be setup before the io loop */
546 >  modules_init();
547    read_conf_files(1);   /* cold start init conf files */
645  initServerMask();
646  me.id[0] = '\0';
548    init_uid();
648  init_auth();          /* Initialise the auth code */
649 #ifndef _WIN32
650  init_resolver();      /* Needs to be setup before the io loop */
651 #endif
549    initialize_server_capabs();   /* Set up default_server_capabs */
550    initialize_global_set_options();
551 <  init_channels();
551 >  channel_init();
552 >  read_links_file();
553 >  motd_init();
554 > #ifdef HAVE_LIBGEOIP
555 >  geoip_ctx = GeoIP_new(GEOIP_MEMORY_CACHE);
556 > #endif
557  
558 <  if (ServerInfo.name == NULL)
558 >  if (EmptyString(ServerInfo.sid))
559    {
560 <    ilog(L_CRIT, "No server name specified in serverinfo block.");
560 >    ilog(LOG_TYPE_IRCD, "ERROR: No server id specified in serverinfo block.");
561      exit(EXIT_FAILURE);
562    }
563 +
564 +  strlcpy(me.id, ServerInfo.sid, sizeof(me.id));
565 +
566 +  if (EmptyString(ServerInfo.name))
567 +  {
568 +    ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block.");
569 +    exit(EXIT_FAILURE);
570 +  }
571 +
572    strlcpy(me.name, ServerInfo.name, sizeof(me.name));
573  
574    /* serverinfo{} description must exist.  If not, error out.*/
575 <  if (ServerInfo.description == NULL)
575 >  if (EmptyString(ServerInfo.description))
576    {
577 <    ilog(L_CRIT,
667 <      "ERROR: No server description specified in serverinfo block.");
577 >    ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block.");
578      exit(EXIT_FAILURE);
579    }
580 +
581    strlcpy(me.info, ServerInfo.description, sizeof(me.info));
582  
583 <  me.from    = &me;
584 <  me.servptr = &me;
583 >  me.from                   = &me;
584 >  me.servptr                = &me;
585 >  me.localClient->lasttime  = CurrentTime;
586 >  me.localClient->since     = CurrentTime;
587 >  me.localClient->firsttime = CurrentTime;
588  
589    SetMe(&me);
590    make_server(&me);
591  
592 <  me.lasttime = me.since = me.firsttime = CurrentTime;
592 >  hash_add_id(&me);
593    hash_add_client(&me);
594 <  
594 >
595    /* add ourselves to global_serv_list */
596    dlinkAdd(&me, make_dlink_node(), &global_serv_list);
597  
598 <  check_class();
598 >  load_kline_database();
599 >  load_dline_database();
600 >  load_gline_database();
601 >  load_xline_database();
602 >  load_resv_database();
603  
686 #ifndef STATIC_MODULES
604    if (chdir(MODPATH))
605    {
606 <    ilog (L_CRIT, "Could not load core modules. Terminating!");
606 >    ilog(LOG_TYPE_IRCD, "Could not load core modules. Terminating!");
607      exit(EXIT_FAILURE);
608    }
609  
610    load_all_modules(1);
611    load_conf_modules();
612    load_core_modules(1);
613 +
614    /* Go back to DPATH after checking to see if we can chdir to MODPATH */
615 <  chdir(ConfigFileEntry.dpath);
616 < #else
617 <  load_all_modules(1);
618 < #endif
615 >  if (chdir(ConfigFileEntry.dpath))
616 >  {
617 >    perror("chdir");
618 >    exit(EXIT_FAILURE);
619 >  }
620 >
621    /*
622     * assemble_umode_buffer() has to be called after
623     * reading conf/loading modules.
# Line 706 | Line 626 | main(int argc, char *argv[])
626  
627    write_pidfile(pidFileName);
628  
629 <  ilog(L_NOTICE, "Server Ready");
629 >  ilog(LOG_TYPE_IRCD, "Server Ready");
630  
631    eventAddIsh("cleanup_glines", cleanup_glines, NULL, CLEANUP_GLINES_TIME);
632    eventAddIsh("cleanup_tklines", cleanup_tklines, NULL, CLEANUP_TKLINES_TIME);
# Line 715 | Line 635 | main(int argc, char *argv[])
635    /* No, 'cause after a restart it would cause all sorts of nick collides */
636    eventAddIsh("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME);
637  
718  eventAddIsh("collect_zipstats", collect_zipstats, NULL, ZIPSTATS_TIME);
719
638    /* Setup the timeout check. I'll shift it later :)  -- adrian */
639    eventAddIsh("comm_checktimeouts", comm_checktimeouts, NULL, 1);
640  
641 +  eventAddIsh("save_all_databases", save_all_databases, NULL, DATABASE_UPDATE_TIMEOUT);
642 +
643    if (ConfigServerHide.links_delay > 0)
644      eventAddIsh("write_links_file", write_links_file, NULL, ConfigServerHide.links_delay);
645    else
# Line 729 | Line 649 | main(int argc, char *argv[])
649      eventAddIsh("check_splitmode", check_splitmode, NULL, 60);
650  
651    io_loop();
652 <  return(0);
652 >  return 0;
653   }

Diff Legend

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