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/src/ircd.c (file contents), Revision 32 by knight, Sun Oct 2 20:41:23 2005 UTC vs.
ircd-hybrid-8/src/ircd.c (file contents), Revision 1236 by michael, Thu Sep 29 11:21:27 2011 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"
# Line 34 | Line 34
34   #include "fdlist.h"
35   #include "hash.h"
36   #include "irc_string.h"
37 #include "sprintf_irc.h"
37   #include "ircd_signal.h"
39 #include "list.h"
38   #include "s_gline.h"
39   #include "motd.h"
40   #include "ircd_handler.h"
# Line 47 | Line 45
45   #include "parse.h"
46   #include "irc_res.h"
47   #include "restart.h"
48 + #include "rng_mt.h"
49   #include "s_auth.h"
50   #include "s_bsd.h"
51   #include "s_conf.h"
52   #include "s_log.h"
53   #include "s_misc.h"
54   #include "s_serv.h"      /* try_connections */
56 #include "s_stats.h"
55   #include "send.h"
56   #include "whowas.h"
57   #include "modules.h"
# Line 63 | Line 61
61   #include "balloc.h"
62   #include "motd.h"
63   #include "supported.h"
64 + #include "watch.h"
65  
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 */
66  
67   /* /quote set variables */
68   struct SetOptions GlobalSetOptions;
# Line 77 | Line 73 | struct config_file_entry ConfigFileEntry
73   struct server_info ServerInfo;
74   /* admin info set from ircd.conf */
75   struct admin_info AdminInfo = { NULL, NULL, NULL };
76 < struct Counter Count = { 0, 0, 0, 0, 0, 0, 0, 0 };
76 > struct Counter Count = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
77   struct ServerState_t server_state = { 0 };
78   struct logging_entry ConfigLoggingEntry = { 1, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0} };
79 + struct ServerStatistics ServerStats;
80   struct timeval SystemTime;
81   struct Client me;             /* That's me */
82   struct LocalUser meLocalUser; /* That's also part of me */
86 unsigned long connect_id = 0; /* unique connect ID */
83  
88 static unsigned long initialVMTop = 0;   /* top of virtual memory at init */
84   const char *logFileName = LPATH;
85   const char *pidFileName = PPATH;
86  
# Line 94 | Line 89 | char ircd_platform[PLATFORMLEN];
89  
90   int dorehash = 0;
91   int doremotd = 0;
97 time_t nextconnect = 1;       /* time for next try_connections call */
92  
93   /* Set to zero because it should be initialized later using
94   * initialize_server_capabs
# Line 105 | Line 99 | int default_server_capabs = 0;
99   int bio_spare_fd = -1;
100   #endif
101  
102 < int splitmode;
103 < int splitchecking;
104 < int split_users;
102 > unsigned int splitmode;
103 > unsigned int splitchecking;
104 > unsigned int split_users;
105   unsigned int split_servers;
106  
107   /* Do klines the same way hybrid-6 did them, i.e. at the
# Line 122 | Line 116 | unsigned int split_servers;
116  
117   int rehashed_klines = 0;
118  
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 }
119  
120   /*
121   * print_startup - print startup information
# Line 174 | Line 147 | make_daemon(void)
147  
148    setsid();
149   }
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 }
150  
151   static int printVersion = 0;
152  
# Line 217 | Line 176 | set_time(void)
176   {
177    static char to_send[200];
178    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
179    newtime.tv_sec  = 0;
180    newtime.tv_usec = 0;
181  
# Line 241 | Line 188 | set_time(void)
188                           strerror(errno));
189      restart("Clock Failure");
190    }
244 #endif
191  
192    if (newtime.tv_sec < CurrentTime)
193    {
194 <    ircsprintf(to_send, "System clock is running backwards - (%lu < %lu)",
195 <               (unsigned long)newtime.tv_sec, (unsigned long)CurrentTime);
194 >    snprintf(to_send, sizeof(to_send),
195 >             "System clock is running backwards - (%lu < %lu)",
196 >             (unsigned long)newtime.tv_sec, (unsigned long)CurrentTime);
197      report_error(L_ALL, to_send, me.name, 0);
198      set_back_events(CurrentTime - newtime.tv_sec);
199    }
# Line 281 | Line 228 | io_loop(void)
228        {
229          struct Client *client_p = ptr->data;
230          assert(client_p->localClient->list_task);
231 <        safe_list_channels(client_p, client_p->localClient->list_task, 0, 0);
231 >        safe_list_channels(client_p, client_p->localClient->list_task, 0);
232        }
233      }
234  
# Line 347 | Line 294 | initialize_global_set_options(void)
294    }
295  
296    GlobalSetOptions.ident_timeout = IDENT_TIMEOUT;
350  GlobalSetOptions.idletime = ConfigFileEntry.idletime;
297    /* End of global set options */
298   }
299  
# Line 380 | Line 326 | static void
326   initialize_server_capabs(void)
327   {
328    add_capability("QS", CAP_QS, 1);
383  add_capability("LL", CAP_LL, 1);
329    add_capability("EOB", CAP_EOB, 1);
330 <  if (ServerInfo.sid != NULL)   /* only enable TS6 if we have an SID */
386 <    add_capability("TS6", CAP_TS6, 0);
330 >  add_capability("TS6", CAP_TS6, 0);
331    add_capability("ZIP", CAP_ZIP, 0);
332    add_capability("CLUSTER", CAP_CLUSTER, 1);
333 +  add_capability("SVS", CAP_SVS, 1);
334   #ifdef HALFOPS
335    add_capability("HOPS", CAP_HOPS, 1);
336   #endif
# Line 406 | Line 351 | write_pidfile(const char *filename)
351    {
352      char buff[32];
353      unsigned int pid = (unsigned int)getpid();
354 <    size_t nbytes = ircsprintf(buff, "%u\n", pid);
354 >    size_t nbytes = snprintf(buff, sizeof(buff), "%u\n", pid);
355  
356      if ((fbputs(buff, fb, nbytes) == -1))
357        ilog(L_ERROR, "Error writing %u to pid file %s (%s)",
# Line 432 | Line 377 | write_pidfile(const char *filename)
377   static void
378   check_pidfile(const char *filename)
379   {
435 #ifndef _WIN32
380    FBFILE *fb;
381    char buff[32];
382    pid_t pidfromfile;
# Line 464 | Line 408 | check_pidfile(const char *filename)
408    {
409      /* log(L_ERROR, "Error opening pid file %s", filename); */
410    }
467 #endif
411   }
412  
413   /* setup_corefile()
# Line 502 | Line 445 | init_ssl(void)
445    SSL_load_error_strings();
446    SSLeay_add_ssl_algorithms();
447  
448 <  ServerInfo.ctx = SSL_CTX_new(SSLv23_server_method());
506 <  if (!ServerInfo.ctx)
448 >  if ((ServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL)
449    {
450      const char *s;
451  
# Line 512 | Line 454 | init_ssl(void)
454      ilog(L_CRIT, "ERROR: Could not initialize the SSL context -- %s\n", s);
455    }
456  
457 <  SSL_CTX_set_options(ServerInfo.ctx, SSL_OP_NO_SSLv2);
458 <  SSL_CTX_set_options(ServerInfo.ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
459 <  SSL_CTX_set_verify(ServerInfo.ctx, SSL_VERIFY_NONE, NULL);
457 >  SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2);
458 >  SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
459 >  SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_NONE, NULL);
460  
461    bio_spare_fd = save_spare_fd("SSL private key validation");
462   #endif /* HAVE_LIBCRYPTO */
# Line 529 | Line 471 | init_ssl(void)
471   static void
472   init_callbacks(void)
473   {
474 <  iorecv_cb = register_callback("iorecv", NULL);
475 <  iosend_cb = register_callback("iosend", NULL);
474 >  iorecv_cb = register_callback("iorecv", iorecv_default);
475 >  iosend_cb = register_callback("iosend", iosend_default);
476    iorecvctrl_cb = register_callback("iorecvctrl", NULL);
477    iosendctrl_cb = register_callback("iosendctrl", NULL);
478   }
# Line 541 | Line 483 | main(int argc, char *argv[])
483    /* Check to see if the user is running
484     * us as root, which is a nono
485     */
544 #ifndef _WIN32
486    if (geteuid() == 0)
487    {
488      fprintf(stderr, "Don't run ircd as root!!!\n");
489 <    return(-1);
489 >    return -1;
490    }
491  
492    /* Setup corefile size immediately after boot -kre */
493    setup_corefile();
494  
554  /* set initialVMTop before we allocate any memory */
555  initialVMTop = get_vm_top();
556 #endif
557
495    /* save server boot time right away, so getrusage works correctly */
496    set_time();
497  
498 <    /* It ain't random, but it ought to be a little harder to guess */
499 <  srand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20)));
500 <  memset(&me, 0, sizeof(me));
564 <  memset(&meLocalUser, 0, sizeof(meLocalUser));
498 >  /* It ain't random, but it ought to be a little harder to guess */
499 >  init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20)));
500 >
501    me.localClient = &meLocalUser;
502    dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning
503                                                     of Client list */
568
569  memset(&ServerInfo, 0, sizeof(ServerInfo));
570
504    /* Initialise the channel capability usage counts... */
505    init_chcap_usage_counts();
506  
# Line 600 | Line 533 | main(int argc, char *argv[])
533  
534    init_ssl();
535  
603 #ifndef _WIN32
536    if (!server_state.foreground)
537    {
538      make_daemon();
# Line 610 | Line 542 | main(int argc, char *argv[])
542      print_startup(getpid());
543  
544    setup_signals();
613 #endif
545  
546    get_ircd_platform(ircd_platform);
547  
# Line 624 | Line 555 | main(int argc, char *argv[])
555    /* Check if there is pidfile and daemon already running */
556    check_pidfile(pidFileName);
557  
627 #ifndef NOBALLOC
558    initBlockHeap();
629 #endif
559    init_dlink_nodes();
560    init_callbacks();
561    initialize_message_files();
# Line 638 | Line 567 | main(int argc, char *argv[])
567    init_client();
568    init_class();
569    init_whowas();
570 <  init_stats();
642 <  read_conf_files(1);   /* cold start init conf files */
643 <  initServerMask();
644 <  me.id[0] = '\0';
645 <  init_uid();
570 >  watch_init();
571    init_auth();          /* Initialise the auth code */
647 #ifndef _WIN32
572    init_resolver();      /* Needs to be setup before the io loop */
573 < #endif
573 >  read_conf_files(1);   /* cold start init conf files */
574 >  init_uid();
575    initialize_server_capabs();   /* Set up default_server_capabs */
576    initialize_global_set_options();
577    init_channels();
578  
579 <  if (ServerInfo.name == NULL)
579 >  if (EmptyString(ServerInfo.sid))
580    {
581 <    ilog(L_CRIT, "No server name specified in serverinfo block.");
581 >    ilog(L_CRIT, "ERROR: No server id specified in serverinfo block.");
582      exit(EXIT_FAILURE);
583    }
584 +
585 +  strlcpy(me.id, ServerInfo.sid, sizeof(me.id));
586 +
587 +  if (EmptyString(ServerInfo.name))
588 +  {
589 +    ilog(L_CRIT, "ERROR: No server name specified in serverinfo block.");
590 +    exit(EXIT_FAILURE);
591 +  }
592 +
593    strlcpy(me.name, ServerInfo.name, sizeof(me.name));
594  
595    /* serverinfo{} description must exist.  If not, error out.*/
596 <  if (ServerInfo.description == NULL)
596 >  if (EmptyString(ServerInfo.description))
597    {
598 <    ilog(L_CRIT,
665 <      "ERROR: No server description specified in serverinfo block.");
598 >    ilog(L_CRIT, "ERROR: No server description specified in serverinfo block.");
599      exit(EXIT_FAILURE);
600    }
601 +
602    strlcpy(me.info, ServerInfo.description, sizeof(me.info));
603  
604 <  me.from    = &me;
605 <  me.servptr = &me;
604 >  me.from     = &me;
605 >  me.servptr  = &me;
606 >  me.lasttime = me.since = me.firsttime = CurrentTime;
607  
608    SetMe(&me);
609    make_server(&me);
610  
611 <  me.lasttime = me.since = me.firsttime = CurrentTime;
611 >  hash_add_id(&me);
612    hash_add_client(&me);
613    
614    /* add ourselves to global_serv_list */
615    dlinkAdd(&me, make_dlink_node(), &global_serv_list);
616  
682  check_class();
683
684 #ifndef STATIC_MODULES
617    if (chdir(MODPATH))
618    {
619 <    ilog (L_CRIT, "Could not load core modules. Terminating!");
619 >    ilog(L_CRIT, "Could not load core modules. Terminating!");
620      exit(EXIT_FAILURE);
621    }
622  
623    load_all_modules(1);
624    load_conf_modules();
625    load_core_modules(1);
626 +
627    /* Go back to DPATH after checking to see if we can chdir to MODPATH */
628 <  chdir(ConfigFileEntry.dpath);
629 < #else
630 <  load_all_modules(1);
631 < #endif
628 >  if (chdir(ConfigFileEntry.dpath))
629 >  {
630 >    perror("chdir");
631 >    exit(EXIT_FAILURE);
632 >  }
633 >
634    /*
635     * assemble_umode_buffer() has to be called after
636     * reading conf/loading modules.
# Line 727 | Line 662 | main(int argc, char *argv[])
662      eventAddIsh("check_splitmode", check_splitmode, NULL, 60);
663  
664    io_loop();
665 <  return(0);
665 >  return 0;
666   }

Comparing:
ircd-hybrid/src/ircd.c (property svn:keywords), Revision 32 by knight, Sun Oct 2 20:41:23 2005 UTC vs.
ircd-hybrid-8/src/ircd.c (property svn:keywords), Revision 1236 by michael, Thu Sep 29 11:21:27 2011 UTC

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

Diff Legend

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