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-8/src/ircd.c (file contents), Revision 1286 by michael, Sun Feb 5 15:20:03 2012 UTC

# Line 24 | Line 24
24  
25   #include "stdinc.h"
26   #include "s_user.h"
27 < #include "tools.h"
27 > #include "list.h"
28   #include "ircd.h"
29   #include "channel.h"
30   #include "channel_mode.h"
31   #include "client.h"
32 #include "common.h"
32   #include "event.h"
33   #include "fdlist.h"
34   #include "hash.h"
35   #include "irc_string.h"
37 #include "sprintf_irc.h"
36   #include "ircd_signal.h"
39 #include "list.h"
37   #include "s_gline.h"
38   #include "motd.h"
42 #include "ircd_handler.h"
43 #include "msg.h"         /* msgtab */
39   #include "hostmask.h"
40   #include "numeric.h"
41   #include "packet.h"
42   #include "parse.h"
43   #include "irc_res.h"
44   #include "restart.h"
45 + #include "rng_mt.h"
46   #include "s_auth.h"
47   #include "s_bsd.h"
48   #include "s_conf.h"
49   #include "s_log.h"
50   #include "s_misc.h"
51   #include "s_serv.h"      /* try_connections */
56 #include "s_stats.h"
52   #include "send.h"
53   #include "whowas.h"
54   #include "modules.h"
# Line 63 | Line 58
58   #include "balloc.h"
59   #include "motd.h"
60   #include "supported.h"
61 + #include "watch.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;
# Line 77 | Line 70 | struct config_file_entry ConfigFileEntry
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 };
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, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0} };
75 > struct logging_entry ConfigLoggingEntry = { 1, 1 };
76 > struct ServerStatistics ServerStats;
77   struct timeval SystemTime;
78   struct Client me;             /* That's me */
79   struct LocalUser meLocalUser; /* That's also part of me */
86 unsigned long connect_id = 0; /* unique connect ID */
80  
88 static unsigned long initialVMTop = 0;   /* top of virtual memory at init */
81   const char *logFileName = LPATH;
82   const char *pidFileName = PPATH;
83  
# Line 94 | Line 86 | char ircd_platform[PLATFORMLEN];
86  
87   int dorehash = 0;
88   int doremotd = 0;
97 time_t nextconnect = 1;       /* time for next try_connections call */
89  
90   /* Set to zero because it should be initialized later using
91   * initialize_server_capabs
# Line 105 | Line 96 | int default_server_capabs = 0;
96   int bio_spare_fd = -1;
97   #endif
98  
99 < int splitmode;
100 < int splitchecking;
101 < int split_users;
99 > unsigned int splitmode;
100 > unsigned int splitchecking;
101 > unsigned int split_users;
102   unsigned int split_servers;
103  
104   /* Do klines the same way hybrid-6 did them, i.e. at the
# Line 122 | Line 113 | unsigned int split_servers;
113  
114   int rehashed_klines = 0;
115  
125 /*
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)
131 {
132  /*
133   * NOTE: sbrk is not part of the ANSI C library or the POSIX.1 standard
134   * however it seems that everyone defines it. Calling sbrk with a 0
135   * 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   */
142
143  void *vptr = sbrk(0);
144  return((unsigned long)vptr);
145 }
116  
117   /*
118   * print_startup - print startup information
# Line 174 | Line 144 | make_daemon(void)
144  
145    setsid();
146   }
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 }
147  
148   static int printVersion = 0;
149  
# Line 217 | Line 173 | set_time(void)
173   {
174    static char to_send[200];
175    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
176    newtime.tv_sec  = 0;
177    newtime.tv_usec = 0;
178  
179    if (gettimeofday(&newtime, NULL) == -1)
180    {
181 <    ilog(L_ERROR, "Clock Failure (%s), TS can be corrupted",
181 >    ilog(LOG_TYPE_IRCD, "Clock Failure (%s), TS can be corrupted",
182           strerror(errno));
183      sendto_realops_flags(UMODE_ALL, L_ALL,
184                           "Clock Failure (%s), TS can be corrupted",
185                           strerror(errno));
186      restart("Clock Failure");
187    }
244 #endif
188  
189    if (newtime.tv_sec < CurrentTime)
190    {
191 <    ircsprintf(to_send, "System clock is running backwards - (%lu < %lu)",
192 <               (unsigned long)newtime.tv_sec, (unsigned long)CurrentTime);
191 >    snprintf(to_send, sizeof(to_send),
192 >             "System clock is running backwards - (%lu < %lu)",
193 >             (unsigned long)newtime.tv_sec, (unsigned long)CurrentTime);
194      report_error(L_ALL, to_send, me.name, 0);
195      set_back_events(CurrentTime - newtime.tv_sec);
196    }
# Line 281 | Line 225 | io_loop(void)
225        {
226          struct Client *client_p = ptr->data;
227          assert(client_p->localClient->list_task);
228 <        safe_list_channels(client_p, client_p->localClient->list_task, 0, 0);
228 >        safe_list_channels(client_p, client_p->localClient->list_task, 0);
229        }
230      }
231  
# Line 347 | Line 291 | initialize_global_set_options(void)
291    }
292  
293    GlobalSetOptions.ident_timeout = IDENT_TIMEOUT;
350  GlobalSetOptions.idletime = ConfigFileEntry.idletime;
294    /* End of global set options */
295   }
296  
# Line 380 | Line 323 | static void
323   initialize_server_capabs(void)
324   {
325    add_capability("QS", CAP_QS, 1);
383  add_capability("LL", CAP_LL, 1);
326    add_capability("EOB", CAP_EOB, 1);
327 <  if (ServerInfo.sid != NULL)   /* only enable TS6 if we have an SID */
386 <    add_capability("TS6", CAP_TS6, 0);
327 >  add_capability("TS6", CAP_TS6, 0);
328    add_capability("ZIP", CAP_ZIP, 0);
329    add_capability("CLUSTER", CAP_CLUSTER, 1);
330 +  add_capability("SVS", CAP_SVS, 1);
331   #ifdef HALFOPS
332    add_capability("HOPS", CAP_HOPS, 1);
333   #endif
# Line 406 | Line 348 | write_pidfile(const char *filename)
348    {
349      char buff[32];
350      unsigned int pid = (unsigned int)getpid();
351 <    size_t nbytes = ircsprintf(buff, "%u\n", pid);
351 >    size_t nbytes = snprintf(buff, sizeof(buff), "%u\n", pid);
352  
353      if ((fbputs(buff, fb, nbytes) == -1))
354 <      ilog(L_ERROR, "Error writing %u to pid file %s (%s)",
354 >      ilog(LOG_TYPE_IRCD, "Error writing %u to pid file %s (%s)",
355             pid, filename, strerror(errno));
356  
357      fbclose(fb);
# Line 417 | Line 359 | write_pidfile(const char *filename)
359    }
360    else
361    {
362 <    ilog(L_ERROR, "Error opening pid file %s", filename);
362 >    ilog(LOG_TYPE_IRCD, "Error opening pid file %s", filename);
363    }
364   }
365  
# Line 432 | Line 374 | write_pidfile(const char *filename)
374   static void
375   check_pidfile(const char *filename)
376   {
435 #ifndef _WIN32
377    FBFILE *fb;
378    char buff[32];
379    pid_t pidfromfile;
# Line 464 | Line 405 | check_pidfile(const char *filename)
405    {
406      /* log(L_ERROR, "Error opening pid file %s", filename); */
407    }
467 #endif
408   }
409  
410   /* setup_corefile()
# Line 502 | Line 442 | init_ssl(void)
442    SSL_load_error_strings();
443    SSLeay_add_ssl_algorithms();
444  
445 <  ServerInfo.ctx = SSL_CTX_new(SSLv23_server_method());
506 <  if (!ServerInfo.ctx)
445 >  if ((ServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL)
446    {
447      const char *s;
448  
449      fprintf(stderr, "ERROR: Could not initialize the SSL context -- %s\n",
450              s = ERR_lib_error_string(ERR_get_error()));
451 <    ilog(L_CRIT, "ERROR: Could not initialize the SSL context -- %s\n", s);
451 >    ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL context -- %s\n", s);
452    }
453  
454 <  SSL_CTX_set_options(ServerInfo.ctx, SSL_OP_NO_SSLv2);
455 <  SSL_CTX_set_options(ServerInfo.ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
456 <  SSL_CTX_set_verify(ServerInfo.ctx, SSL_VERIFY_NONE, NULL);
454 >  SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2);
455 >  SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
456 >  SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_NONE, NULL);
457  
458    bio_spare_fd = save_spare_fd("SSL private key validation");
459   #endif /* HAVE_LIBCRYPTO */
# Line 529 | Line 468 | init_ssl(void)
468   static void
469   init_callbacks(void)
470   {
471 <  iorecv_cb = register_callback("iorecv", NULL);
472 <  iosend_cb = register_callback("iosend", NULL);
471 >  iorecv_cb = register_callback("iorecv", iorecv_default);
472 >  iosend_cb = register_callback("iosend", iosend_default);
473    iorecvctrl_cb = register_callback("iorecvctrl", NULL);
474    iosendctrl_cb = register_callback("iosendctrl", NULL);
475   }
# Line 541 | Line 480 | main(int argc, char *argv[])
480    /* Check to see if the user is running
481     * us as root, which is a nono
482     */
544 #ifndef _WIN32
483    if (geteuid() == 0)
484    {
485      fprintf(stderr, "Don't run ircd as root!!!\n");
486 <    return(-1);
486 >    return -1;
487    }
488  
489    /* Setup corefile size immediately after boot -kre */
490    setup_corefile();
491  
554  /* set initialVMTop before we allocate any memory */
555  initialVMTop = get_vm_top();
556 #endif
557
492    /* save server boot time right away, so getrusage works correctly */
493    set_time();
494  
495 <    /* It ain't random, but it ought to be a little harder to guess */
496 <  srand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20)));
497 <  memset(&me, 0, sizeof(me));
564 <  memset(&meLocalUser, 0, sizeof(meLocalUser));
495 >  /* It ain't random, but it ought to be a little harder to guess */
496 >  init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20)));
497 >
498    me.localClient = &meLocalUser;
499    dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning
500                                                     of Client list */
568
569  memset(&ServerInfo, 0, sizeof(ServerInfo));
570
501    /* Initialise the channel capability usage counts... */
502    init_chcap_usage_counts();
503  
# Line 600 | Line 530 | main(int argc, char *argv[])
530  
531    init_ssl();
532  
603 #ifndef _WIN32
533    if (!server_state.foreground)
534    {
535      make_daemon();
# Line 610 | Line 539 | main(int argc, char *argv[])
539      print_startup(getpid());
540  
541    setup_signals();
613 #endif
542  
543    get_ircd_platform(ircd_platform);
544  
# Line 618 | Line 546 | main(int argc, char *argv[])
546    eventInit();
547    /* We need this to initialise the fd array before anything else */
548    fdlist_init();
549 <  init_log(logFileName);
549 >  log_add_file(LOG_TYPE_IRCD, 0, logFileName);
550    check_can_use_v6();
551    init_comm();         /* This needs to be setup early ! -- adrian */
552    /* Check if there is pidfile and daemon already running */
553    check_pidfile(pidFileName);
554  
627 #ifndef NOBALLOC
555    initBlockHeap();
629 #endif
556    init_dlink_nodes();
557    init_callbacks();
558    initialize_message_files();
# Line 638 | Line 564 | main(int argc, char *argv[])
564    init_client();
565    init_class();
566    init_whowas();
567 <  init_stats();
642 <  read_conf_files(1);   /* cold start init conf files */
643 <  initServerMask();
644 <  me.id[0] = '\0';
645 <  init_uid();
567 >  watch_init();
568    init_auth();          /* Initialise the auth code */
647 #ifndef _WIN32
569    init_resolver();      /* Needs to be setup before the io loop */
570 < #endif
570 >  read_conf_files(1);   /* cold start init conf files */
571 >  init_uid();
572    initialize_server_capabs();   /* Set up default_server_capabs */
573    initialize_global_set_options();
574    init_channels();
575  
576 <  if (ServerInfo.name == NULL)
576 >  if (EmptyString(ServerInfo.sid))
577 >  {
578 >    ilog(LOG_TYPE_IRCD, "ERROR: No server id specified in serverinfo block.");
579 >    exit(EXIT_FAILURE);
580 >  }
581 >
582 >  strlcpy(me.id, ServerInfo.sid, sizeof(me.id));
583 >
584 >  if (EmptyString(ServerInfo.name))
585    {
586 <    ilog(L_CRIT, "No server name specified in serverinfo block.");
586 >    ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block.");
587      exit(EXIT_FAILURE);
588    }
589 +
590    strlcpy(me.name, ServerInfo.name, sizeof(me.name));
591  
592    /* serverinfo{} description must exist.  If not, error out.*/
593 <  if (ServerInfo.description == NULL)
593 >  if (EmptyString(ServerInfo.description))
594    {
595 <    ilog(L_CRIT,
665 <      "ERROR: No server description specified in serverinfo block.");
595 >    ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block.");
596      exit(EXIT_FAILURE);
597    }
598 +
599    strlcpy(me.info, ServerInfo.description, sizeof(me.info));
600  
601 <  me.from    = &me;
602 <  me.servptr = &me;
601 >  me.from                   = &me;
602 >  me.servptr                = &me;
603 >  me.localClient->lasttime  = CurrentTime;
604 >  me.localClient->since     = CurrentTime;
605 >  me.localClient->firsttime = CurrentTime;
606  
607    SetMe(&me);
608    make_server(&me);
609  
610 <  me.lasttime = me.since = me.firsttime = CurrentTime;
610 >  hash_add_id(&me);
611    hash_add_client(&me);
612    
613    /* add ourselves to global_serv_list */
614    dlinkAdd(&me, make_dlink_node(), &global_serv_list);
615  
682  check_class();
683
684 #ifndef STATIC_MODULES
616    if (chdir(MODPATH))
617    {
618 <    ilog (L_CRIT, "Could not load core modules. Terminating!");
618 >    ilog(LOG_TYPE_IRCD, "Could not load core modules. Terminating!");
619      exit(EXIT_FAILURE);
620    }
621  
622    load_all_modules(1);
623    load_conf_modules();
624    load_core_modules(1);
625 +
626    /* Go back to DPATH after checking to see if we can chdir to MODPATH */
627 <  chdir(ConfigFileEntry.dpath);
628 < #else
629 <  load_all_modules(1);
630 < #endif
627 >  if (chdir(ConfigFileEntry.dpath))
628 >  {
629 >    perror("chdir");
630 >    exit(EXIT_FAILURE);
631 >  }
632 >
633    /*
634     * assemble_umode_buffer() has to be called after
635     * reading conf/loading modules.
# Line 704 | Line 638 | main(int argc, char *argv[])
638  
639    write_pidfile(pidFileName);
640  
641 <  ilog(L_NOTICE, "Server Ready");
641 >  ilog(LOG_TYPE_IRCD, "Server Ready");
642  
643    eventAddIsh("cleanup_glines", cleanup_glines, NULL, CLEANUP_GLINES_TIME);
644    eventAddIsh("cleanup_tklines", cleanup_tklines, NULL, CLEANUP_TKLINES_TIME);
# Line 727 | Line 661 | main(int argc, char *argv[])
661      eventAddIsh("check_splitmode", check_splitmode, NULL, 60);
662  
663    io_loop();
664 <  return(0);
664 >  return 0;
665   }

Diff Legend

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