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

Comparing ircd-hybrid/src/ircd.c (file contents):
Revision 257 by michael, Sat Nov 12 16:00:08 2005 UTC vs.
Revision 743 by adx, Sun Jul 23 20:03:42 2006 UTC

# Line 24 | Line 24
24  
25   #ifdef IN_IRCD
26   #include "stdinc.h"
27 + #include "conf/conf.h"
28   #include "s_user.h"
29   #include "ircd.h"
30   #include "channel.h"
# Line 32 | Line 33
33   #include "common.h"
34   #include "hash.h"
35   #include "ircd_signal.h"
35 #include "s_gline.h"
36   #include "motd.h"
37   #include "ircd_handler.h"
38   #include "msg.h"         /* msgtab */
# Line 42 | Line 42
42   #include "parse.h"
43   #include "restart.h"
44   #include "s_auth.h"
45 #include "s_conf.h"
45   #include "parse_aline.h"
46   #include "s_serv.h"
48 #include "s_stats.h"
47   #include "send.h"
48   #include "whowas.h"
51 #include "modules.h"
52 #include "ircd_getopt.h"
49   #include "motd.h"
54 #include "supported.h"
50   #include "watch.h"
51 + #include "patchlevel.h"
52 + #include "serno.h"
53  
57 /* Try and find the correct name to use with getrlimit() for setting the max.
58 * number of files allowed to be open by this process.
59 */
54  
55   /* /quote set variables */
56   struct SetOptions GlobalSetOptions;
57 <
64 < /* configuration set from ircd.conf */
65 < struct config_file_entry ConfigFileEntry;
66 < /* server info set from ircd.conf */
67 < struct server_info ServerInfo;
57 > struct ServerStatistics ServerStats;
58   /* admin info set from ircd.conf */
69 struct admin_info AdminInfo = { NULL, NULL, NULL };
59   struct Counter Count = { 0, 0, 0, 0, 0, 0, 0, 0 };
60 < struct ServerState_t server_state = { 0 };
72 < struct logging_entry ConfigLoggingEntry = { 1, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0} };
60 > struct ServerState_t ServerState = { 0 };
61   struct Client me;             /* That's me */
62   struct LocalUser meLocalUser; /* That's also part of me */
75 unsigned long connect_id = 0; /* unique connect ID */
76
77 static unsigned long initialVMTop = 0;   /* top of virtual memory at init */
78 const char *logFileName = LPATH;
79 const char *pidFileName = PPATH;
63  
64   char **myargv;
65 < char ircd_platform[PLATFORMLEN];
65 > const char *ircd_version = PATCHLEVEL;
66 > const char *serno = SERIALNUM;
67 > char ircd_platform[IRCD_BUFSIZE];
68  
69   int dorehash = 0;
70   int doremotd = 0;
86 time_t nextconnect = 1;       /* time for next try_connections call */
71  
72   /* Set to zero because it should be initialized later using
73   * initialize_server_capabs
# Line 96 | Line 80 | int bio_spare_fd = -1;
80  
81   int splitmode;
82   int splitchecking;
99 int split_users;
100 unsigned int split_servers;
83  
84   static dlink_node *fdlimit_hook;
85  
# Line 113 | Line 95 | static dlink_node *fdlimit_hook;
95  
96   int rehashed_klines = 0;
97  
116 /*
117 * get_vm_top - get the operating systems notion of the resident set size
118 */
98   #ifndef _WIN32
120 static unsigned long
121 get_vm_top(void)
122 {
123  /*
124   * NOTE: sbrk is not part of the ANSI C library or the POSIX.1 standard
125   * however it seems that everyone defines it. Calling sbrk with a 0
126   * argument will return a pointer to the top of the process virtual
127   * memory without changing the process size, so this call should be
128   * reasonably safe (sbrk returns the new value for the top of memory).
129   * This code relies on the notion that the address returned will be an
130   * offset from 0 (NULL), so the result of sbrk is cast to a size_t and
131   * returned. We really shouldn't be using it here but...
132   */
133
134  void *vptr = sbrk(0);
135  return((unsigned long)vptr);
136 }
137
99   /*
100   * print_startup - print startup information
101   */
# Line 143 | Line 104 | print_startup(int pid)
104   {
105    printf("ircd: version %s\n", ircd_version);
106    printf("ircd: pid %d\n", pid);
107 <  printf("ircd: running in %s mode from %s\n", !server_state.foreground ? "background"
108 <         : "foreground", ConfigFileEntry.dpath);
107 >  printf("ircd: running in %s mode from %s\n",
108 >         ServerState.foreground ? "foreground" : "background", DPATH);
109   }
110  
111   static void
# Line 167 | Line 128 | make_daemon(void)
128   }
129   #endif
130  
131 < /*
132 < * get_maxrss - get the operating systems notion of the resident set size
172 < */
173 < unsigned long
174 < get_maxrss(void)
175 < {
176 < #ifdef _WIN32
177 <  return (0);   /* FIXME */
178 < #else
179 <  return (get_vm_top() - initialVMTop);
180 < #endif
181 < }
182 <
183 < static int printVersion = 0;
184 <
185 < struct lgetopt myopts[] = {
186 <  {"dlinefile",  &ConfigFileEntry.dlinefile,
187 <   STRING, "File to use for dline.conf"},
188 <  {"configfile", &ConfigFileEntry.configfile,
131 > static struct lgetopt myopts[] = {
132 >  {"configfile", &ServerState.configfile,
133     STRING, "File to use for ircd.conf"},
134 <  {"klinefile",  &ConfigFileEntry.klinefile,
134 >  {"klinefile",  &ServerState.klinefile,
135     STRING, "File to use for kline.conf"},
136 <  {"xlinefile",  &ConfigFileEntry.xlinefile,
136 >  {"rklinefile", &ServerState.rklinefile,
137 >   STRING, "File to use for rkline.conf"},
138 >  {"dlinefile",  &ServerState.dlinefile,
139 >   STRING, "File to use for dline.conf"},
140 >  {"glinefile",  &ServerState.glinefile,
141 >   STRING, "File to use for gline.conf"},
142 >  {"xlinefile",  &ServerState.xlinefile,
143     STRING, "File to use for xline.conf"},
144 <  {"logfile",    &logFileName,
144 >  {"rxlinefile", &ServerState.rxlinefile,
145 >   STRING, "File to use for rxline.conf"},
146 >  {"cresvfile",  &ServerState.cresvfile,
147 >   STRING, "File to use for cresv.conf"},
148 >  {"nresvfile",  &ServerState.nresvfile,
149 >   STRING, "File to use for nresv.conf"},
150 >  {"logfile",    &ServerState.logfile,
151     STRING, "File to use for ircd.log"},
152 <  {"pidfile",    &pidFileName,
152 >  {"pidfile",    &ServerState.pidfile,
153     STRING, "File to use for process ID"},
154 <  {"foreground", &server_state.foreground,
154 >  {"foreground", &ServerState.foreground,
155     YESNO, "Run in foreground (don't detach)"},
156 <  {"version",    &printVersion,
156 >  {"version",    &ServerState.printversion,
157     YESNO, "Print version and exit"},
158    {"help", NULL, USAGE, "Print this text"},
159    {NULL, NULL, STRING, NULL},
# Line 229 | Line 185 | io_loop(void)
185        {
186          struct Client *client_p = ptr->data;
187          assert(client_p->localClient->list_task);
188 <        safe_list_channels(client_p, client_p->localClient->list_task, 0, 0);
188 >        safe_list_channels(client_p, client_p->localClient->list_task, 0);
189        }
190      }
191  
# Line 244 | Line 200 | io_loop(void)
200      free_exited_clients();
201      send_queued_all();
202  
203 <    /* Check to see whether we have to rehash the configuration .. */
203 >    // Check to see whether we have to rehash the configuration ..
204      if (dorehash)
205      {
206 <      rehash(1);
206 >      sendto_realops_flags(UMODE_ALL, L_ALL,
207 >        "Got signal SIGHUP, reloading ircd configuration");
208 >      read_conf_files(NO);
209        dorehash = 0;
210      }
211 +
212      if (doremotd)
213      {
214 <      read_message_file(&ConfigFileEntry.motd);
214 >      read_message_file(&motd);
215        sendto_realops_flags(UMODE_ALL, L_ALL,
216 <                           "Got signal SIGUSR1, reloading ircd motd file");
216 >        "Got signal SIGUSR1, reloading ircd MOTD file");
217        doremotd = 0;
218      }
219    }
# Line 276 | Line 235 | initialize_global_set_options(void)
235    GlobalSetOptions.spam_time = MIN_JOIN_LEAVE_TIME;
236    GlobalSetOptions.spam_num  = MAX_JOIN_LEAVE_COUNT;
237  
238 <  if (ConfigFileEntry.default_floodcount)
239 <    GlobalSetOptions.floodcount = ConfigFileEntry.default_floodcount;
238 >  if (General.default_floodcount)
239 >    GlobalSetOptions.floodcount = General.default_floodcount;
240    else
241      GlobalSetOptions.floodcount = 10;
242  
243 <  /* XXX I have no idea what to try here - Dianora */
243 >  // XXX I have no idea what to try here - Dianora
244    GlobalSetOptions.joinfloodcount = 16;
245    GlobalSetOptions.joinfloodtime = 8;
246  
247 <  split_servers = ConfigChannel.default_split_server_count;
248 <  split_users   = ConfigChannel.default_split_user_count;
247 >  GlobalSetOptions.split_servers = Channel.default_split_server_count;
248 >  GlobalSetOptions.split_users   = Channel.default_split_user_count;
249  
250 <  if (split_users && split_servers && (ConfigChannel.no_create_on_split ||
251 <                                       ConfigChannel.no_join_on_split))
250 >  if (GlobalSetOptions.split_users && GlobalSetOptions.split_servers &&
251 >      (Channel.no_create_on_split || Channel.no_join_on_split))
252    {
253      splitmode     = 1;
254      splitchecking = 1;
255    }
256  
257    GlobalSetOptions.ident_timeout = IDENT_TIMEOUT;
258 <  GlobalSetOptions.idletime = ConfigFileEntry.idletime;
259 <  /* End of global set options */
301 < }
302 <
303 < /* initialize_message_files()
304 < *
305 < * inputs       - none
306 < * output       - none
307 < * side effects - Set up all message files needed, motd etc.
308 < */
309 < static void
310 < initialize_message_files(void)
311 < {
312 <  init_message_file(USER_MOTD, MPATH, &ConfigFileEntry.motd);
313 <  init_message_file(OPER_MOTD, OPATH, &ConfigFileEntry.opermotd);
314 <  init_message_file(USER_LINKS, LIPATH, &ConfigFileEntry.linksfile);
315 <
316 <  read_message_file(&ConfigFileEntry.motd);
317 <  read_message_file(&ConfigFileEntry.opermotd);
318 <  read_message_file(&ConfigFileEntry.linksfile);
319 <
320 <  init_isupport();
321 < }
322 <
323 < /* initialize_server_capabs()
324 < *
325 < * inputs       - none
326 < * output       - none
327 < */
328 < static void
329 < initialize_server_capabs(void)
330 < {
331 <  add_capability("QS", CAP_QS, 1);
332 <  add_capability("EOB", CAP_EOB, 1);
333 <  add_capability("HUB", CAP_HUB, 0);
334 <  add_capability("LL", CAP_LL, 0);
335 <  add_capability("TS6", CAP_TS6, 0);
336 <  add_capability("ZIP", CAP_ZIP, 0);
337 <  add_capability("CLUSTER", CAP_CLUSTER, 1);
338 < #ifdef HALFOPS
339 <  add_capability("HOPS", CAP_HOPS, 1);
340 < #endif
258 >  GlobalSetOptions.idletime = General.idletime;
259 >  GlobalSetOptions.maxlisters = 10; /* XXX ya ya ya - db */
260   }
261  
262   /* write_pidfile()
# Line 362 | Line 281 | write_pidfile(const char *filename)
281             pid, filename, strerror(errno));
282  
283      fbclose(fb);
365    return;
284    }
285    else
286    {
# Line 386 | Line 304 | check_pidfile(const char *filename)
304    char buff[32];
305    pid_t pidfromfile;
306  
307 <  /* Don't do logging here, since we don't have log() initialised */
307 >  // Don't do logging here, since we don't have log() initialised
308    if ((fb = fbopen(filename, "r")))
309    {
310      if (fbgets(buff, 20, fb) == NULL)
# Line 401 | Line 319 | check_pidfile(const char *filename)
319  
320        if (!kill(pidfromfile, 0))
321        {
322 <        /* log(L_ERROR, "Server is already running"); */
322 >        // log(L_ERROR, "Server is already running");
323          printf("ircd: daemon is already running\n");
324          exit(-1);
325        }
# Line 411 | Line 329 | check_pidfile(const char *filename)
329    }
330    else if (errno != ENOENT)
331    {
332 <    /* log(L_ERROR, "Error opening pid file %s", filename); */
415 <  }
416 < #endif
417 < }
418 <
419 < /* setup_corefile()
420 < *
421 < * inputs       - nothing
422 < * output       - nothing
423 < * side effects - setups corefile to system limits.
424 < * -kre
425 < */
426 < static void
427 < setup_corefile(void)
428 < {
429 < #ifdef HAVE_SYS_RESOURCE_H
430 <  struct rlimit rlim; /* resource limits */
431 <
432 <  /* Set corefilesize to maximum */
433 <  if (!getrlimit(RLIMIT_CORE, &rlim))
434 <  {
435 <    rlim.rlim_cur = rlim.rlim_max;
436 <    setrlimit(RLIMIT_CORE, &rlim);
332 >    // log(L_ERROR, "Error opening pid file %s", filename);
333    }
334   #endif
335   }
# Line 445 | Line 341 | setup_corefile(void)
341   * side effects - setups SSL context.
342   */
343   static void
344 < init_ssl(void)
344 > ssl_init(void)
345   {
346   #ifdef HAVE_LIBCRYPTO
347 +  SSL_library_init();
348    SSL_load_error_strings();
452  SSLeay_add_ssl_algorithms();
349  
350    ServerInfo.ctx = SSL_CTX_new(SSLv23_server_method());
351 +
352    if (!ServerInfo.ctx)
353    {
354      const char *s;
# Line 483 | Line 380 | init_callbacks(void)
380    iosend_cb = register_callback("iosend", iosend_default);
381    iorecvctrl_cb = register_callback("iorecvctrl", NULL);
382    iosendctrl_cb = register_callback("iosendctrl", NULL);
383 <  uid_get_cb = register_callback("uid_get", uid_get);
383 >  authorize_client = register_callback("authorize_client", do_authorize_client);
384 >  uid_get = register_callback("uid_get", do_uid_get);
385    umode_cb = register_callback("changing_umode", change_simple_umode);
386   }
387  
# Line 493 | Line 391 | changing_fdlimit(va_list args)
391    int old_fdlimit = hard_fdlimit;
392    int fdmax = va_arg(args, int);
393  
394 <  /* allow MAXCLIENTS_MIN clients even at the cost of MAX_BUFFER and
395 <   * some not really LEAKED_FDS */
396 <  fdmax = IRCD_MAX(fdmax, LEAKED_FDS + MAX_BUFFER + MAXCLIENTS_MIN);
394 >  /*
395 >   * allow MAXCLIENTS_MIN clients even at the cost of MAX_BUFFER and
396 >   * some not really LEAKED_FDS
397 >   */
398 >  fdmax = LIBIO_MAX(fdmax, LEAKED_FDS + MAX_BUFFER + MAXCLIENTS_MIN);
399  
400    pass_callback(fdlimit_hook, fdmax);
401  
# Line 515 | Line 415 | changing_fdlimit(va_list args)
415   EXTERN int
416   main(int argc, char *argv[])
417   {
418 <  /* Check to see if the user is running
419 <   * us as root, which is a nono
418 >  /*
419 >   * Check to see if the user is running us as root, which is a nono
420     */
421   #ifndef _WIN32
422    if (geteuid() == 0)
# Line 525 | Line 425 | main(int argc, char *argv[])
425      return 1;
426    }
427  
428 <  /* Setup corefile size immediately after boot -kre */
428 >  // Setup corefile size immediately after boot -kre
429    setup_corefile();
530
531  /* set initialVMTop before we allocate any memory */
532  initialVMTop = get_vm_top();
430   #endif
431  
432    memset(&ServerInfo, 0, sizeof(ServerInfo));
433 +  memset(&ServerStats, 0, sizeof(ServerStats));
434  
435 <  ConfigFileEntry.dpath      = DPATH;
436 <  ConfigFileEntry.configfile = CPATH;  /* Server configuration file */
437 <  ConfigFileEntry.klinefile  = KPATH;  /* Server kline file         */
438 <  ConfigFileEntry.xlinefile  = XPATH;  /* Server xline file         */
439 <  ConfigFileEntry.rxlinefile = RXPATH; /* Server regex xline file   */
440 <  ConfigFileEntry.rklinefile = RKPATH; /* Server regex kline file   */
441 <  ConfigFileEntry.dlinefile  = DLPATH; /* dline file                */
442 <  ConfigFileEntry.glinefile  = GPATH;  /* gline log file            */
443 <  ConfigFileEntry.cresvfile  = CRESVPATH; /* channel resv file      */
546 <  ConfigFileEntry.nresvfile  = NRESVPATH; /* nick resv file         */
435 >  ServerState.configfile = CPATH;  // Server configuration file
436 >  ServerState.klinefile  = KPATH;  // Server kline file
437 >  ServerState.xlinefile  = XPATH;  // Server xline file
438 >  ServerState.rxlinefile = RXPATH; // Server regex xline file
439 >  ServerState.rklinefile = RKPATH; // Server regex kline file
440 >  ServerState.dlinefile  = DLPATH; // dline file
441 >  ServerState.glinefile  = GPATH;  // gline log file
442 >  ServerState.cresvfile  = CRESVPATH; // channel resv file
443 >  ServerState.nresvfile  = NRESVPATH; // nick resv file
444    myargv = argv;
445 <  umask(077);                /* better safe than sorry --SRB */
445 >  umask(077);                // better safe than sorry --SRB
446  
447    parseargs(&argc, &argv, myopts);
448  
449 <  if (printVersion)
449 >  if (ServerState.printversion)
450    {
451      printf("ircd: version %s\n", ircd_version);
452      exit(EXIT_SUCCESS);
453    }
454  
455 <  if (chdir(ConfigFileEntry.dpath))
455 >  if (chdir(DPATH))
456    {
457      perror("chdir");
458      exit(EXIT_FAILURE);
459    }
460  
461 <  init_ssl();
461 >  ssl_init();
462  
463   #ifndef _WIN32
464 <  if (!server_state.foreground)
464 >  if (!ServerState.foreground)
465      make_daemon();
466    else
467      print_startup(getpid());
468   #endif
469  
470 <  libio_init(!server_state.foreground);
470 >  libio_init(!ServerState.foreground);
471    outofmemory = ircd_outofmemory;
472    fdlimit_hook = install_hook(fdlimit_cb, changing_fdlimit);
473  
474 <  check_pidfile(pidFileName);
474 >  check_pidfile(ServerState.pidfile);
475    setup_signals();
476 <  get_ircd_platform(ircd_platform);
477 <  init_log(logFileName);
478 <  ServerInfo.can_use_v6 = check_can_use_v6();
476 >  libio_get_platform(ircd_platform, sizeof(ircd_platform));
477 >  init_log(ServerState.logfile);
478 >  ServerState.can_use_v6 = check_can_use_v6();
479  
583  /* make_dlink_node() cannot be called until after libio_init() */
480    memset(&me, 0, sizeof(me));
481    memset(&meLocalUser, 0, sizeof(meLocalUser));
482    me.localClient = &meLocalUser;
483    me.from = me.servptr = &me;
484    me.lasttime = me.since = me.firsttime = CurrentTime;
589
485    SetMe(&me);
486    make_server(&me);
487    dlinkAdd(&me, &me.node, &global_client_list);
488    dlinkAdd(&me, make_dlink_node(), &global_serv_list);
489  
490    init_callbacks();
491 <  initialize_message_files();
492 <  init_hash();
493 <  init_ip_hash_table();      /* client host ip hash table */
494 <  init_host_hash();          /* Host-hashtable. */
491 >  init_motd();
492 >  init_isupport();
493 >  hash_init();
494 >  init_ip_hash_table(); // client host ip hash table
495    clear_tree_parse();
496    init_client();
497 <  init_class();
498 <  init_whowas();
499 <  init_stats();
500 <  initServerMask();
606 <  init_auth();          /* Initialise the auth code */
607 <  init_channels();
497 >  whowas_init();
498 >  watch_init();
499 >  init_auth();
500 >  channel_init();
501    init_channel_modes();
502 <  initialize_server_capabs();   /* Set up default_server_capabs */
503 <
504 <  read_conf_files(1);   /* cold start init conf files */
612 <  check_class();
613 <  init_watch();
614 <
615 <  if (ServerInfo.name == NULL)
616 <  {
617 <    ilog(L_CRIT, "No server name specified in serverinfo block.");
618 <    exit(EXIT_FAILURE);
619 <  }
620 <  strlcpy(me.name, ServerInfo.name, sizeof(me.name));
621 <
622 <  /* serverinfo{} description must exist.  If not, error out.*/
623 <  if (ServerInfo.description == NULL)
624 <  {
625 <    ilog(L_CRIT,
626 <      "ERROR: No server description specified in serverinfo block.");
627 <    exit(EXIT_FAILURE);
628 <  }
629 <  strlcpy(me.info, ServerInfo.description, sizeof(me.info));
502 >  server_init();
503 >  init_conf();
504 >  read_conf_files(YES); // cold start init conf files
505  
506    hash_add_client(&me);
507 +  if (me.id[0])
508 +    hash_add_id(&me);
509  
510 <  init_uid();     /* XXX move this one up after inculcating new conf system */
511 <  initialize_global_set_options();   /* and this one is going to be deleted */
635 <
636 < #ifndef STATIC_MODULES
637 <  if (chdir(MODPATH))
638 <  {
639 <    ilog (L_CRIT, "Could not load core modules. Terminating!");
640 <    exit(EXIT_FAILURE);
641 <  }
510 >  init_uid();
511 >  initialize_global_set_options();
512  
643  load_all_modules(1);
644  load_conf_modules();
645  load_core_modules(1);
646
647  /* Go back to DPATH after checking to see if we can chdir to MODPATH */
648  chdir(ConfigFileEntry.dpath);
649 #else
650  load_all_modules(1);
651 #endif
513    /*
514     * assemble_umode_buffer() has to be called after
515     * reading conf/loading modules.
516     */
517    assemble_umode_buffer();
518  
519 <  write_pidfile(pidFileName);
519 >  write_pidfile(ServerState.pidfile);
520  
521    ilog(L_NOTICE, "Server Ready");
522  
523 <  eventAddIsh("cleanup_glines", cleanup_glines, NULL, CLEANUP_GLINES_TIME);
524 <  eventAddIsh("cleanup_tklines", cleanup_tklines, NULL, CLEANUP_TKLINES_TIME);
664 <
665 <  /* We want try_connections to be called as soon as possible now! -- adrian */
666 <  /* No, 'cause after a restart it would cause all sorts of nick collides */
523 >  // We want try_connections to be called as soon as possible now! -- adrian
524 >  // No, 'cause after a restart it would cause all sorts of nick collides
525    eventAddIsh("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME);
526  
527    eventAddIsh("collect_zipstats", collect_zipstats, NULL, ZIPSTATS_TIME);
528  
529 <  /* Setup the timeout check. I'll shift it later :)  -- adrian */
529 >  // Setup the timeout check. I'll shift it later :)  -- adrian
530    eventAddIsh("comm_checktimeouts", comm_checktimeouts, NULL, 1);
531  
674  /* XXX to be removed with old s_conf.c [superseded] */
675  if (ConfigServerHide.links_delay > 0)
676    eventAddIsh("write_links_file", write_links_file, NULL, ConfigServerHide.links_delay);
677  else
678    ConfigServerHide.links_disabled = 1;
679
680  if (splitmode)   /* XXX */
681    eventAddIsh("check_splitmode", check_splitmode, NULL, 60);
682
532    io_loop();
533 <  return(0);
533 >  return 0;
534   }
535  
536   #else

Diff Legend

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