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

Comparing:
ircd-hybrid-8/src/ircd.c (property svn:keywords), Revision 1307 by michael, Sat Mar 24 09:33:33 2012 UTC vs.
ircd-hybrid/trunk/src/ircd.c (property svn:keywords), Revision 8166 by michael, Sun Apr 9 16:09:54 2017 UTC

# Line 1 | Line 1
1 < Id Revision
1 > Id

Diff Legend

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