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 967 by michael, Sun Aug 2 18:05:28 2009 UTC vs.
ircd-hybrid/trunk/src/ircd.c (file contents), Revision 7569 by michael, Tue May 24 16:26:05 2016 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-2016 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"
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 "id.h"
37   #include "irc_string.h"
37 #include "sprintf_irc.h"
38   #include "ircd_signal.h"
39 #include "list.h"
40 #include "s_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 */
48 > #include "log.h"
49 > #include "server.h"
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"
62 #include "balloc.h"
63 #include "motd.h"
64 #include "supported.h"
56   #include "watch.h"
57 + #include "conf_db.h"
58 + #include "conf_class.h"
59 + #include "ipcache.h"
60 + #include "isupport.h"
61 + #include "userhost.h"
62  
67 /* Try and find the correct name to use with getrlimit() for setting the max.
68 * number of files allowed to be open by this process.
69 */
63  
64 < /* /quote set variables */
65 < struct SetOptions GlobalSetOptions;
64 > #ifdef HAVE_LIBGEOIP
65 > GeoIP *GeoIPv4_ctx;
66 > GeoIP *GeoIPv6_ctx;
67 > #endif
68  
69 < /* configuration set from ircd.conf */
70 < struct config_file_entry ConfigFileEntry;
71 < /* 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} };
69 > struct SetOptions GlobalSetOptions;  /* /quote set variables */
70 > struct Counter Count;
71 > struct ServerState_t server_state;
72   struct ServerStatistics ServerStats;
73 < struct timeval SystemTime;
74 < struct Client me;             /* That's me */
75 < struct LocalUser meLocalUser; /* That's also part of me */
73 > struct ServerTime SystemTime;
74 > struct Connection meConnection;  /* That's also part of me */
75 > struct Client me = { .connection = &meConnection };  /* That's me */
76  
77 < static unsigned long initialVMTop = 0;   /* top of virtual memory at init */
77 > char **myargv;
78   const char *logFileName = LPATH;
79   const char *pidFileName = PPATH;
80  
81 < char **myargv;
82 < char ircd_platform[PLATFORMLEN];
94 <
95 < int dorehash = 0;
96 < int doremotd = 0;
97 < time_t nextconnect = 1;       /* time for next try_connections call */
98 <
99 < /* Set to zero because it should be initialized later using
100 < * initialize_server_capabs
101 < */
102 < int default_server_capabs = 0;
103 <
104 < #ifdef HAVE_LIBCRYPTO
105 < int bio_spare_fd = -1;
106 < #endif
107 <
108 < int splitmode;
109 < int splitchecking;
110 < int split_users;
111 < unsigned int split_servers;
112 <
113 < /* Do klines the same way hybrid-6 did them, i.e. at the
114 < * top of the next io_loop instead of in the same loop as
115 < * the klines are being applied.
116 < *
117 < * This should fix strange CPU starvation as very indirectly reported.
118 < * (Why do you people not email bug reports? WHY? WHY?)
119 < *
120 < * - Dianora
121 < */
122 <
123 < int rehashed_klines = 0;
81 > unsigned int dorehash;
82 > unsigned int doremotd;
83  
84 + static int printVersion;
85  
86 < #ifndef _WIN32
127 < /*
128 < * print_startup - print startup information
129 < */
130 < static void
131 < print_startup(int pid)
86 > static struct lgetopt myopts[] =
87   {
88 <  printf("ircd: version %s\n", ircd_version);
89 <  printf("ircd: pid %d\n", pid);
90 <  printf("ircd: running in %s mode from %s\n", !server_state.foreground ? "background"
91 <         : "foreground", ConfigFileEntry.dpath);
92 < }
88 >  { "configfile", &ConfigGeneral.configfile,
89 >   STRING, "File to use for ircd.conf" },
90 >  { "klinefile",  &ConfigGeneral.klinefile,
91 >   STRING, "File to use for kline database" },
92 >  { "dlinefile",  &ConfigGeneral.dlinefile,
93 >   STRING, "File to use for dline database" },
94 >  { "xlinefile",  &ConfigGeneral.xlinefile,
95 >   STRING, "File to use for xline database" },
96 >  { "resvfile",   &ConfigGeneral.resvfile,
97 >   STRING, "File to use for resv database" },
98 >  { "logfile",    &logFileName,
99 >   STRING, "File to use for ircd.log" },
100 >  { "pidfile",    &pidFileName,
101 >   STRING, "File to use for process ID" },
102 >  { "foreground", &server_state.foreground,
103 >   YESNO, "Run in foreground (don't detach)" },
104 >  { "version",    &printVersion,
105 >   YESNO, "Print version and exit" },
106 >  { "help", NULL, USAGE, "Print this text" },
107 >  { NULL, NULL, STRING, NULL },
108 > };
109  
110 < static void
140 < make_daemon(void)
110 > static struct event event_cleanup_tklines =
111   {
112 <  int pid;
112 >  .name = "cleanup_tklines",
113 >  .handler = cleanup_tklines,
114 >  .when = CLEANUP_TKLINES_TIME
115 > };
116  
117 <  if ((pid = fork()) < 0)
118 <  {
119 <    perror("fork");
120 <    exit(EXIT_FAILURE);
121 <  }
122 <  else if (pid > 0)
150 <  {
151 <    print_startup(pid);
152 <    exit(EXIT_SUCCESS);
153 <  }
117 > static struct event event_try_connections =
118 > {
119 >  .name = "try_connections",
120 >  .handler = try_connections,
121 >  .when = STARTUP_CONNECTIONS_TIME
122 > };
123  
124 <  setsid();
125 < }
126 < #endif
124 > static struct event event_comm_checktimeouts =
125 > {
126 >  .name = "comm_checktimeouts",
127 >  .handler = comm_checktimeouts,
128 >  .when = 1
129 > };
130  
131 < static int printVersion = 0;
131 > static struct event event_save_all_databases =
132 > {
133 >  .name = "save_all_databases",
134 >  .handler = save_all_databases,
135 >  .when = DATABASE_UPDATE_TIMEOUT
136 > };
137  
138 < struct lgetopt myopts[] = {
139 <  {"dlinefile",  &ConfigFileEntry.dlinefile,
140 <   STRING, "File to use for dline.conf"},
141 <  {"configfile", &ConfigFileEntry.configfile,
165 <   STRING, "File to use for ircd.conf"},
166 <  {"klinefile",  &ConfigFileEntry.klinefile,
167 <   STRING, "File to use for kline.conf"},
168 <  {"xlinefile",  &ConfigFileEntry.xlinefile,
169 <   STRING, "File to use for xline.conf"},
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,
175 <   YESNO, "Run in foreground (don't detach)"},
176 <  {"version",    &printVersion,
177 <   YESNO, "Print version and exit"},
178 <  {"help", NULL, USAGE, "Print this text"},
179 <  {NULL, NULL, STRING, NULL},
138 > struct event event_write_links_file =
139 > {
140 >  .name = "write_links_file",
141 >  .handler = write_links_file,
142   };
143  
144 +
145   void
146   set_time(void)
147   {
148 <  static char to_send[200];
186 <  struct timeval newtime;
187 < #ifdef _WIN32
188 <  FILETIME ft;
189 <
190 <  GetSystemTimeAsFileTime(&ft);
191 <  if (ft.dwLowDateTime < 0xd53e8000)
192 <    ft.dwHighDateTime--;
193 <  ft.dwLowDateTime -= 0xd53e8000;
194 <  ft.dwHighDateTime -= 0x19db1de;
195 <
196 <  newtime.tv_sec  = (*(uint64_t *) &ft) / 10000000;
197 <  newtime.tv_usec = (*(uint64_t *) &ft) / 10 % 1000000;
198 < #else
199 <  newtime.tv_sec  = 0;
200 <  newtime.tv_usec = 0;
148 >  struct timeval newtime = { .tv_sec = 0, .tv_usec = 0 };
149  
150    if (gettimeofday(&newtime, NULL) == -1)
151    {
152 <    ilog(L_ERROR, "Clock Failure (%s), TS can be corrupted",
153 <         strerror(errno));
154 <    sendto_realops_flags(UMODE_ALL, L_ALL,
155 <                         "Clock Failure (%s), TS can be corrupted",
156 <                         strerror(errno));
209 <    restart("Clock Failure");
152 >    char buf[IRCD_BUFSIZE];
153 >
154 >    snprintf(buf, sizeof(buf), "Clock failure, TS can be corrupted: %s",
155 >             strerror(errno));
156 >    server_die(buf, SERVER_SHUTDOWN);
157    }
211 #endif
158  
159 <  if (newtime.tv_sec < CurrentTime)
159 >  if ((uintmax_t)newtime.tv_sec < CurrentTime)
160    {
161 <    ircsprintf(to_send, "System clock is running backwards - (%lu < %lu)",
162 <               (unsigned long)newtime.tv_sec, (unsigned long)CurrentTime);
163 <    report_error(L_ALL, to_send, me.name, 0);
164 <    set_back_events(CurrentTime - newtime.tv_sec);
161 >    ilog(LOG_TYPE_IRCD, "System clock is running backwards - (%ju < %ju)",
162 >         (uintmax_t)newtime.tv_sec, CurrentTime);
163 >    sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE,
164 >                         "System clock is running backwards - (%ju < %ju)",
165 >                         (uintmax_t)newtime.tv_sec, CurrentTime);
166 >    event_set_back_events(CurrentTime - (uintmax_t)newtime.tv_sec);
167    }
168  
169 <  SystemTime.tv_sec  = newtime.tv_sec;
169 >  SystemTime.tv_sec = newtime.tv_sec;
170    SystemTime.tv_usec = newtime.tv_usec;
171   }
172  
173   static void
174   io_loop(void)
175   {
176 <  while (1 == 1)
176 >  while (1)
177    {
230    /*
231     * Maybe we want a flags word?
232     * ie. if (REHASHED_KLINES(global_flags))
233     * SET_REHASHED_KLINES(global_flags)
234     * CLEAR_REHASHED_KLINES(global_flags)
235     *
236     * - Dianora
237     */
238    if (rehashed_klines)
239    {
240      check_conf_klines();
241      rehashed_klines = 0;
242    }
243
178      if (listing_client_list.head)
179      {
180 <      dlink_node *ptr = NULL, *ptr_next = NULL;
181 <      DLINK_FOREACH_SAFE(ptr, ptr_next, listing_client_list.head)
182 <      {
249 <        struct Client *client_p = ptr->data;
250 <        assert(client_p->localClient->list_task);
251 <        safe_list_channels(client_p, client_p->localClient->list_task, 0);
252 <      }
180 >      dlink_node *node = NULL, *node_next = NULL;
181 >      DLINK_FOREACH_SAFE(node, node_next, listing_client_list.head)
182 >        safe_list_channels(node->data, 0);
183      }
184  
185 <    /* Run pending events, then get the number of seconds to the next
186 <     * event
257 <     */
258 <    while (eventNextTime() <= CurrentTime)
259 <      eventRun();
185 >    /* Run pending events */
186 >    event_run();
187  
188      comm_select();
189      exit_aborted_clients();
190      free_exited_clients();
264    send_queued_all();
191  
192 <    /* Check to see whether we have to rehash the configuration .. */
192 >    /* Check to see whether we have to rehash the configuration. */
193      if (dorehash)
194      {
195 <      rehash(1);
195 >      conf_rehash(1);
196        dorehash = 0;
197      }
198 +
199      if (doremotd)
200      {
201 <      read_message_file(&ConfigFileEntry.motd);
202 <      sendto_realops_flags(UMODE_ALL, L_ALL,
203 <                           "Got signal SIGUSR1, reloading ircd motd file");
201 >      motd_recache();
202 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
203 >                           "Got signal SIGUSR1, reloading motd file(s)");
204        doremotd = 0;
205      }
206    }
# Line 283 | Line 210 | io_loop(void)
210   *
211   * inputs       - none
212   * output       - none
213 < * side effects - This sets all global set options needed
213 > * side effects - This sets all global set options needed
214   */
215   static void
216   initialize_global_set_options(void)
217   {
218 <  memset(&GlobalSetOptions, 0, sizeof(GlobalSetOptions));
219 <
293 <  GlobalSetOptions.autoconn  = 1;
218 >  GlobalSetOptions.maxclients = ConfigServerInfo.default_max_clients;
219 >  GlobalSetOptions.autoconn = 1;
220    GlobalSetOptions.spam_time = MIN_JOIN_LEAVE_TIME;
221 <  GlobalSetOptions.spam_num  = MAX_JOIN_LEAVE_COUNT;
222 <
223 <  if (ConfigFileEntry.default_floodcount)
224 <    GlobalSetOptions.floodcount = ConfigFileEntry.default_floodcount;
299 <  else
300 <    GlobalSetOptions.floodcount = 10;
301 <
302 <  /* XXX I have no idea what to try here - Dianora */
303 <  GlobalSetOptions.joinfloodcount = 16;
304 <  GlobalSetOptions.joinfloodtime = 8;
305 <
306 <  split_servers = ConfigChannel.default_split_server_count;
307 <  split_users   = ConfigChannel.default_split_user_count;
308 <
309 <  if (split_users && split_servers && (ConfigChannel.no_create_on_split ||
310 <                                       ConfigChannel.no_join_on_split))
311 <  {
312 <    splitmode     = 1;
313 <    splitchecking = 1;
314 <  }
315 <
221 >  GlobalSetOptions.spam_num = MAX_JOIN_LEAVE_COUNT;
222 >  GlobalSetOptions.floodcount = ConfigGeneral.default_floodcount;
223 >  GlobalSetOptions.joinfloodcount = ConfigChannel.default_join_flood_count;
224 >  GlobalSetOptions.joinfloodtime = ConfigChannel.default_join_flood_time;
225    GlobalSetOptions.ident_timeout = IDENT_TIMEOUT;
317  GlobalSetOptions.idletime = ConfigFileEntry.idletime;
318  /* End of global set options */
319 }
320
321 /* initialize_message_files()
322 *
323 * inputs       - none
324 * output       - none
325 * side effects - Set up all message files needed, motd etc.
326 */
327 static void
328 initialize_message_files(void)
329 {
330  init_message_file(USER_MOTD, MPATH, &ConfigFileEntry.motd);
331  init_message_file(OPER_MOTD, OPATH, &ConfigFileEntry.opermotd);
332  init_message_file(USER_LINKS, LIPATH, &ConfigFileEntry.linksfile);
333
334  read_message_file(&ConfigFileEntry.motd);
335  read_message_file(&ConfigFileEntry.opermotd);
336  read_message_file(&ConfigFileEntry.linksfile);
337
338  init_isupport();
226   }
227  
228   /* initialize_server_capabs()
# Line 346 | Line 233 | initialize_message_files(void)
233   static void
234   initialize_server_capabs(void)
235   {
236 <  add_capability("QS", CAP_QS, 1);
237 <  add_capability("EOB", CAP_EOB, 1);
238 <
239 <  if (ServerInfo.sid != NULL)   /* only enable TS6 if we have an SID */
240 <    add_capability("TS6", CAP_TS6, 0);
241 <
355 <  add_capability("ZIP", CAP_ZIP, 0);
356 <  add_capability("CLUSTER", CAP_CLUSTER, 1);
357 < #ifdef HALFOPS
358 <  add_capability("HOPS", CAP_HOPS, 1);
359 < #endif
236 >  add_capability("QS", CAPAB_QS);
237 >  add_capability("EOB", CAPAB_EOB);
238 >  add_capability("CLUSTER", CAPAB_CLUSTER);
239 >  add_capability("SVS", CAPAB_SVS);
240 >  add_capability("CHW", CAPAB_CHW);
241 >  add_capability("HOPS", CAPAB_HOPS);
242   }
243  
244   /* write_pidfile()
# Line 368 | Line 250 | initialize_server_capabs(void)
250   static void
251   write_pidfile(const char *filename)
252   {
253 <  FBFILE *fb;
253 >  FILE *fb;
254  
255 <  if ((fb = fbopen(filename, "w")))
255 >  if ((fb = fopen(filename, "w")))
256    {
257 <    char buff[32];
257 >    char buf[IRCD_BUFSIZE];
258      unsigned int pid = (unsigned int)getpid();
377    size_t nbytes = ircsprintf(buff, "%u\n", pid);
259  
260 <    if ((fbputs(buff, fb, nbytes) == -1))
261 <      ilog(L_ERROR, "Error writing %u to pid file %s (%s)",
262 <           pid, filename, strerror(errno));
260 >    snprintf(buf, sizeof(buf), "%u\n", pid);
261 >
262 >    if (fputs(buf, fb) == -1)
263 >      ilog(LOG_TYPE_IRCD, "Error writing to pid file %s: %s",
264 >           filename, strerror(errno));
265  
266 <    fbclose(fb);
384 <    return;
266 >    fclose(fb);
267    }
268    else
269 <  {
270 <    ilog(L_ERROR, "Error opening pid file %s", filename);
389 <  }
269 >    ilog(LOG_TYPE_IRCD, "Error opening pid file %s: %s",
270 >         filename, strerror(errno));
271   }
272  
273   /* check_pidfile()
# Line 400 | Line 281 | write_pidfile(const char *filename)
281   static void
282   check_pidfile(const char *filename)
283   {
284 < #ifndef _WIN32
285 <  FBFILE *fb;
405 <  char buff[32];
406 <  pid_t pidfromfile;
284 >  FILE *fb;
285 >  char buf[IRCD_BUFSIZE];
286  
287 <  /* Don't do logging here, since we don't have log() initialised */
409 <  if ((fb = fbopen(filename, "r")))
287 >  if ((fb = fopen(filename, "r")))
288    {
289 <    if (fbgets(buff, 20, fb) == NULL)
290 <    {
291 <      /* log(L_ERROR, "Error reading from pid file %s (%s)", filename,
414 <       * strerror(errno));
415 <       */
416 <    }
289 >    if (!fgets(buf, 20, fb))
290 >      ilog(LOG_TYPE_IRCD, "Error reading from pid file %s: %s",
291 >           filename, strerror(errno));
292      else
293      {
294 <      pidfromfile = atoi(buff);
294 >      pid_t pid = atoi(buf);
295  
296 <      if (!kill(pidfromfile, 0))
296 >      if (!kill(pid, 0))
297        {
298          /* log(L_ERROR, "Server is already running"); */
299          printf("ircd: daemon is already running\n");
300 <        exit(-1);
300 >        exit(EXIT_FAILURE);
301        }
302      }
303  
304 <    fbclose(fb);
304 >    fclose(fb);
305    }
306    else if (errno != ENOENT)
307 <  {
308 <    /* log(L_ERROR, "Error opening pid file %s", filename); */
434 <  }
435 < #endif
307 >    ilog(LOG_TYPE_IRCD, "Error opening pid file %s: %s",
308 >         filename, strerror(errno));
309   }
310  
311   /* setup_corefile()
# Line 457 | Line 330 | setup_corefile(void)
330   #endif
331   }
332  
333 < /* init_ssl()
334 < *
462 < * inputs       - nothing
463 < * output       - nothing
464 < * side effects - setups SSL context.
333 > /*
334 > * print_startup - print startup information
335   */
336   static void
337 < init_ssl(void)
337 > print_startup(int pid)
338   {
339 < #ifdef HAVE_LIBCRYPTO
340 <  SSL_load_error_strings();
341 <  SSLeay_add_ssl_algorithms();
342 <
473 <  if ((ServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL)
474 <  {
475 <    const char *s;
476 <
477 <    fprintf(stderr, "ERROR: Could not initialize the SSL context -- %s\n",
478 <            s = ERR_lib_error_string(ERR_get_error()));
479 <    ilog(L_CRIT, "ERROR: Could not initialize the SSL context -- %s\n", s);
480 <  }
481 <
482 <  SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2);
483 <  SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
484 <  SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_NONE, NULL);
485 <
486 <  bio_spare_fd = save_spare_fd("SSL private key validation");
487 < #endif /* HAVE_LIBCRYPTO */
339 >  printf("ircd: version %s(%s)\n", ircd_version, serno);
340 >  printf("ircd: pid %d\n", pid);
341 >  printf("ircd: running in %s mode from %s\n", !server_state.foreground ? "background"
342 >         : "foreground", ConfigGeneral.dpath);
343   }
344  
490 /* init_callbacks()
491 *
492 * inputs       - nothing
493 * output       - nothing
494 * side effects - setups standard hook points
495 */
345   static void
346 < init_callbacks(void)
346 > make_daemon(void)
347   {
348 <  iorecv_cb = register_callback("iorecv", iorecv_default);
349 <  iosend_cb = register_callback("iosend", iosend_default);
350 <  iorecvctrl_cb = register_callback("iorecvctrl", NULL);
351 <  iosendctrl_cb = register_callback("iosendctrl", NULL);
348 >  int pid;
349 >
350 >  if ((pid = fork()) < 0)
351 >  {
352 >    perror("fork");
353 >    exit(EXIT_FAILURE);
354 >  }
355 >  else if (pid > 0)
356 >  {
357 >    print_startup(pid);
358 >    exit(EXIT_SUCCESS);
359 >  }
360 >
361 >  setsid();
362   }
363  
364   int
365   main(int argc, char *argv[])
366   {
367 <  /* Check to see if the user is running
368 <   * us as root, which is a nono
510 <   */
511 < #ifndef _WIN32
512 <  if (geteuid() == 0)
367 >  /* Check to see if the user is running us as root, which is a nono */
368 >  if (!geteuid())
369    {
370 <    fprintf(stderr, "Don't run ircd as root!!!\n");
371 <    return(-1);
370 >    fprintf(stderr, "ERROR: This server won't run as root/superuser\n");
371 >    return -1;
372    }
373  
374    /* Setup corefile size immediately after boot -kre */
375    setup_corefile();
520 #endif
376  
377 <  /* save server boot time right away, so getrusage works correctly */
377 >  /* Save server boot time right away, so getrusage works correctly */
378    set_time();
379  
380 <    /* It ain't random, but it ought to be a little harder to guess */
381 <  srand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20)));
382 <  memset(&me, 0, sizeof(me));
383 <  memset(&meLocalUser, 0, sizeof(meLocalUser));
384 <  me.localClient = &meLocalUser;
385 <  dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning
386 <                                                   of Client list */
387 <
388 <  memset(&ServerInfo, 0, sizeof(ServerInfo));
389 <  memset(&ServerStats, 0, sizeof(ServerStats));
390 <
391 <  /* Initialise the channel capability usage counts... */
537 <  init_chcap_usage_counts();
538 <
539 <  ConfigFileEntry.dpath      = DPATH;
540 <  ConfigFileEntry.configfile = CPATH;  /* Server configuration file */
541 <  ConfigFileEntry.klinefile  = KPATH;  /* Server kline file         */
542 <  ConfigFileEntry.xlinefile  = XPATH;  /* Server xline file         */
543 <  ConfigFileEntry.rxlinefile = RXPATH; /* Server regex xline file   */
544 <  ConfigFileEntry.rklinefile = RKPATH; /* Server regex kline file   */
545 <  ConfigFileEntry.dlinefile  = DLPATH; /* dline file                */
546 <  ConfigFileEntry.glinefile  = GPATH;  /* gline log file            */
547 <  ConfigFileEntry.cresvfile  = CRESVPATH; /* channel resv file      */
548 <  ConfigFileEntry.nresvfile  = NRESVPATH; /* nick resv file         */
380 >  /* It's not random, but it ought to be a little harder to guess */
381 >  init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20)));
382 >
383 >  ConfigGeneral.dpath      = DPATH;
384 >  ConfigGeneral.spath      = SPATH;
385 >  ConfigGeneral.mpath      = MPATH;
386 >  ConfigGeneral.configfile = CPATH;    /* Server configuration file */
387 >  ConfigGeneral.klinefile  = KPATH;    /* Server kline file         */
388 >  ConfigGeneral.xlinefile  = XPATH;    /* Server xline file         */
389 >  ConfigGeneral.dlinefile  = DLPATH;   /* dline file                */
390 >  ConfigGeneral.resvfile   = RESVPATH; /* resv file                 */
391 >
392    myargv = argv;
393 <  umask(077);                /* better safe than sorry --SRB */
393 >  umask(077);  /* umask 077: u=rwx,g=,o= */
394  
395    parseargs(&argc, &argv, myopts);
396  
397    if (printVersion)
398    {
399 <    printf("ircd: version %s\n", ircd_version);
399 >    printf("ircd: version %s(%s)\n", ircd_version, serno);
400      exit(EXIT_SUCCESS);
401    }
402  
403 <  if (chdir(ConfigFileEntry.dpath))
403 >  if (chdir(ConfigGeneral.dpath))
404    {
405      perror("chdir");
406      exit(EXIT_FAILURE);
407    }
408  
566  init_ssl();
567
568 #ifndef _WIN32
409    if (!server_state.foreground)
410    {
411      make_daemon();
412 <    close_standard_fds(); /* this needs to be before init_netio()! */
412 >    close_standard_fds(); /* this needs to be before netio_init()! */
413    }
414    else
415      print_startup(getpid());
416  
417    setup_signals();
578 #endif
418  
580  get_ircd_platform(ircd_platform);
581
582  /* Init the event subsystem */
583  eventInit();
419    /* We need this to initialise the fd array before anything else */
420    fdlist_init();
421 <  init_log(logFileName);
422 <  check_can_use_v6();
423 <  init_comm();         /* This needs to be setup early ! -- adrian */
421 >  log_set_file(LOG_TYPE_IRCD, 0, logFileName);
422 >
423 >  netio_init();         /* This needs to be setup early ! -- adrian */
424 >  tls_init();
425 >
426    /* Check if there is pidfile and daemon already running */
427    check_pidfile(pidFileName);
428  
429 < #ifndef NOBALLOC
593 <  initBlockHeap();
594 < #endif
429 >  mp_pool_init();
430    init_dlink_nodes();
431 <  init_callbacks();
597 <  initialize_message_files();
431 >  isupport_init();
432    dbuf_init();
433 <  init_hash();
434 <  init_ip_hash_table();      /* client host ip hash table */
435 <  init_host_hash();          /* Host-hashtable. */
436 <  clear_tree_parse();
437 <  init_client();
438 <  init_class();
605 <  init_whowas();
433 >  hash_init();
434 >  userhost_init();
435 >  ipcache_init();
436 >  client_init();
437 >  class_init();
438 >  whowas_init();
439    watch_init();
440 +  auth_init();          /* Initialise the auth code */
441 +  resolver_init();      /* Needs to be setup before the io loop */
442 +  modules_init();
443    read_conf_files(1);   /* cold start init conf files */
608  me.id[0] = '\0';
609  init_uid();
610  init_auth();          /* Initialise the auth code */
611 #ifndef _WIN32
612  init_resolver();      /* Needs to be setup before the io loop */
613 #endif
444    initialize_server_capabs();   /* Set up default_server_capabs */
445 <  initialize_global_set_options();
446 <  init_channels();
445 >  initialize_global_set_options();  /* Has to be called after read_conf_files() */
446 >  channel_init();
447 >  read_links_file();
448 >  motd_init();
449 >  user_modes_init();
450  
451 <  if (ServerInfo.name == NULL)
451 >  if (EmptyString(ConfigServerInfo.name))
452    {
453 <    ilog(L_CRIT, "No server name specified in serverinfo block.");
453 >    ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block.");
454      exit(EXIT_FAILURE);
455    }
456  
457 <  strlcpy(me.name, ServerInfo.name, sizeof(me.name));
457 >  strlcpy(me.name, ConfigServerInfo.name, sizeof(me.name));
458  
459 <  /* serverinfo{} description must exist.  If not, error out.*/
460 <  if (ServerInfo.description == NULL)
459 >  /* serverinfo {} description must exist.  If not, error out.*/
460 >  if (EmptyString(ConfigServerInfo.description))
461    {
462 <    ilog(L_CRIT,
630 <      "ERROR: No server description specified in serverinfo block.");
462 >    ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block.");
463      exit(EXIT_FAILURE);
464    }
465  
466 <  strlcpy(me.info, ServerInfo.description, sizeof(me.info));
466 >  strlcpy(me.info, ConfigServerInfo.description, sizeof(me.info));
467 >
468 >  if (EmptyString(ConfigServerInfo.sid))
469 >  {
470 >    ilog(LOG_TYPE_IRCD, "Generating server ID");
471 >    generate_sid();
472 >  }
473 >  else
474 >    strlcpy(me.id, ConfigServerInfo.sid, sizeof(me.id));
475 >
476 >  init_uid();
477  
478 <  me.from    = &me;
478 >  me.from = &me;
479    me.servptr = &me;
480 +  me.connection->lasttime = CurrentTime;
481 +  me.connection->since = CurrentTime;
482 +  me.connection->firsttime = CurrentTime;
483  
484    SetMe(&me);
485    make_server(&me);
486  
487 <  me.lasttime = me.since = me.firsttime = CurrentTime;
487 >  hash_add_id(&me);
488    hash_add_client(&me);
644  
645  /* add ourselves to global_serv_list */
646  dlinkAdd(&me, make_dlink_node(), &global_serv_list);
489  
490 <  check_class();
490 >  dlinkAdd(&me, make_dlink_node(), &global_server_list);
491 >  dlinkAdd(&me, &me.node, &global_client_list);
492  
493 < #ifndef STATIC_MODULES
494 <  if (chdir(MODPATH))
495 <  {
496 <    ilog (L_CRIT, "Could not load core modules. Terminating!");
654 <    exit(EXIT_FAILURE);
655 <  }
493 >  load_kline_database(ConfigGeneral.klinefile);
494 >  load_dline_database(ConfigGeneral.dlinefile);
495 >  load_xline_database(ConfigGeneral.xlinefile);
496 >  load_resv_database(ConfigGeneral.resvfile);
497  
498    load_all_modules(1);
499    load_conf_modules();
500    load_core_modules(1);
660  /* Go back to DPATH after checking to see if we can chdir to MODPATH */
661  chdir(ConfigFileEntry.dpath);
662 #else
663  load_all_modules(1);
664 #endif
665  /*
666   * assemble_umode_buffer() has to be called after
667   * reading conf/loading modules.
668   */
669  assemble_umode_buffer();
501  
502    write_pidfile(pidFileName);
503  
504 <  ilog(L_NOTICE, "Server Ready");
674 <
675 <  eventAddIsh("cleanup_glines", cleanup_glines, NULL, CLEANUP_GLINES_TIME);
676 <  eventAddIsh("cleanup_tklines", cleanup_tklines, NULL, CLEANUP_TKLINES_TIME);
504 >  event_addish(&event_cleanup_tklines, NULL);
505  
506    /* We want try_connections to be called as soon as possible now! -- adrian */
507    /* No, 'cause after a restart it would cause all sorts of nick collides */
508 <  eventAddIsh("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME);
681 <
682 <  eventAddIsh("collect_zipstats", collect_zipstats, NULL, ZIPSTATS_TIME);
508 >  event_addish(&event_try_connections, NULL);
509  
510    /* Setup the timeout check. I'll shift it later :)  -- adrian */
511 <  eventAddIsh("comm_checktimeouts", comm_checktimeouts, NULL, 1);
511 >  event_add(&event_comm_checktimeouts, NULL);
512  
513 <  if (ConfigServerHide.links_delay > 0)
688 <    eventAddIsh("write_links_file", write_links_file, NULL, ConfigServerHide.links_delay);
689 <  else
690 <    ConfigServerHide.links_disabled = 1;
513 >  event_addish(&event_save_all_databases, NULL);
514  
515 <  if (splitmode)
516 <    eventAddIsh("check_splitmode", check_splitmode, NULL, 60);
515 >  if (ConfigServerHide.flatten_links_delay && event_write_links_file.active == 0)
516 >  {
517 >    event_write_links_file.when = ConfigServerHide.flatten_links_delay;
518 >    event_add(&event_write_links_file, NULL);
519 >  }
520  
521 +  ilog(LOG_TYPE_IRCD, "Server Ready");
522    io_loop();
523 +
524    return 0;
525   }

Diff Legend

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