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

Diff Legend

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