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 885 by michael, Wed Oct 31 18:09:24 2007 UTC vs.
ircd-hybrid-7.3/src/ircd.c (file contents), Revision 1121 by michael, Sun Jan 9 11:03:03 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 36 | Line 36
36   #include "irc_string.h"
37   #include "sprintf_irc.h"
38   #include "ircd_signal.h"
39 #include "list.h"
39   #include "s_gline.h"
40   #include "motd.h"
41   #include "ircd_handler.h"
# Line 47 | Line 46
46   #include "parse.h"
47   #include "irc_res.h"
48   #include "restart.h"
49 + #include "rng_mt.h"
50   #include "s_auth.h"
51   #include "s_bsd.h"
52   #include "s_conf.h"
53   #include "s_log.h"
54   #include "s_misc.h"
55   #include "s_serv.h"      /* try_connections */
56 #include "s_stats.h"
56   #include "send.h"
57   #include "whowas.h"
58   #include "modules.h"
# Line 81 | Line 80 | struct admin_info AdminInfo = { NULL, NU
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} };
83 + struct ServerStatistics ServerStats;
84   struct timeval SystemTime;
85   struct Client me;             /* That's me */
86   struct LocalUser meLocalUser; /* That's also part of me */
87 unsigned long connect_id = 0; /* unique connect ID */
87  
89 static unsigned long initialVMTop = 0;   /* top of virtual memory at init */
88   const char *logFileName = LPATH;
89   const char *pidFileName = PPATH;
90  
# Line 95 | Line 93 | char ircd_platform[PLATFORMLEN];
93  
94   int dorehash = 0;
95   int doremotd = 0;
98 time_t nextconnect = 1;       /* time for next try_connections call */
96  
97   /* Set to zero because it should be initialized later using
98   * initialize_server_capabs
# Line 106 | Line 103 | int default_server_capabs = 0;
103   int bio_spare_fd = -1;
104   #endif
105  
106 < int splitmode;
107 < int splitchecking;
108 < int split_users;
106 > unsigned int splitmode;
107 > unsigned int splitchecking;
108 > unsigned int split_users;
109   unsigned int split_servers;
110  
111   /* Do klines the same way hybrid-6 did them, i.e. at the
# Line 123 | Line 120 | unsigned int split_servers;
120  
121   int rehashed_klines = 0;
122  
126 /*
127 * get_vm_top - get the operating systems notion of the resident set size
128 */
129 #ifndef _WIN32
130 static unsigned long
131 get_vm_top(void)
132 {
133  /*
134   * NOTE: sbrk is not part of the ANSI C library or the POSIX.1 standard
135   * however it seems that everyone defines it. Calling sbrk with a 0
136   * argument will return a pointer to the top of the process virtual
137   * memory without changing the process size, so this call should be
138   * reasonably safe (sbrk returns the new value for the top of memory).
139   * This code relies on the notion that the address returned will be an
140   * offset from 0 (NULL), so the result of sbrk is cast to a size_t and
141   * returned. We really shouldn't be using it here but...
142   */
143
144  void *vptr = sbrk(0);
145  return((unsigned long)vptr);
146 }
123  
124   /*
125   * print_startup - print startup information
# Line 175 | Line 151 | make_daemon(void)
151  
152    setsid();
153   }
178 #endif
179
180 /*
181 * get_maxrss - get the operating systems notion of the resident set size
182 */
183 unsigned long
184 get_maxrss(void)
185 {
186 #ifdef _WIN32
187  return (0);   /* FIXME */
188 #else
189  return (get_vm_top() - initialVMTop);
190 #endif
191 }
154  
155   static int printVersion = 0;
156  
# Line 218 | Line 180 | set_time(void)
180   {
181    static char to_send[200];
182    struct timeval newtime;
221 #ifdef _WIN32
222  FILETIME ft;
223
224  GetSystemTimeAsFileTime(&ft);
225  if (ft.dwLowDateTime < 0xd53e8000)
226    ft.dwHighDateTime--;
227  ft.dwLowDateTime -= 0xd53e8000;
228  ft.dwHighDateTime -= 0x19db1de;
229
230  newtime.tv_sec  = (*(uint64_t *) &ft) / 10000000;
231  newtime.tv_usec = (*(uint64_t *) &ft) / 10 % 1000000;
232 #else
183    newtime.tv_sec  = 0;
184    newtime.tv_usec = 0;
185  
# Line 242 | Line 192 | set_time(void)
192                           strerror(errno));
193      restart("Clock Failure");
194    }
245 #endif
195  
196    if (newtime.tv_sec < CurrentTime)
197    {
# Line 282 | Line 231 | io_loop(void)
231        {
232          struct Client *client_p = ptr->data;
233          assert(client_p->localClient->list_task);
234 <        safe_list_channels(client_p, client_p->localClient->list_task, 0, 0);
234 >        safe_list_channels(client_p, client_p->localClient->list_task, 0);
235        }
236      }
237  
# Line 382 | Line 331 | initialize_server_capabs(void)
331   {
332    add_capability("QS", CAP_QS, 1);
333    add_capability("EOB", CAP_EOB, 1);
334 <
386 <  if (ServerInfo.sid != NULL)   /* only enable TS6 if we have an SID */
387 <    add_capability("TS6", CAP_TS6, 0);
388 <
334 >  add_capability("TS6", CAP_TS6, 0);
335    add_capability("ZIP", CAP_ZIP, 0);
336    add_capability("CLUSTER", CAP_CLUSTER, 1);
337   #ifdef HALFOPS
# Line 434 | Line 380 | write_pidfile(const char *filename)
380   static void
381   check_pidfile(const char *filename)
382   {
437 #ifndef _WIN32
383    FBFILE *fb;
384    char buff[32];
385    pid_t pidfromfile;
# Line 466 | Line 411 | check_pidfile(const char *filename)
411    {
412      /* log(L_ERROR, "Error opening pid file %s", filename); */
413    }
469 #endif
414   }
415  
416   /* setup_corefile()
# Line 504 | Line 448 | init_ssl(void)
448    SSL_load_error_strings();
449    SSLeay_add_ssl_algorithms();
450  
451 <  ServerInfo.ctx = SSL_CTX_new(SSLv23_server_method());
508 <  if (!ServerInfo.ctx)
451 >  if ((ServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL)
452    {
453      const char *s;
454  
# Line 514 | Line 457 | init_ssl(void)
457      ilog(L_CRIT, "ERROR: Could not initialize the SSL context -- %s\n", s);
458    }
459  
460 <  SSL_CTX_set_options(ServerInfo.ctx, SSL_OP_NO_SSLv2);
461 <  SSL_CTX_set_options(ServerInfo.ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
462 <  SSL_CTX_set_verify(ServerInfo.ctx, SSL_VERIFY_NONE, NULL);
460 >  SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2);
461 >  SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
462 >  SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_NONE, NULL);
463  
464    bio_spare_fd = save_spare_fd("SSL private key validation");
465   #endif /* HAVE_LIBCRYPTO */
# Line 543 | Line 486 | main(int argc, char *argv[])
486    /* Check to see if the user is running
487     * us as root, which is a nono
488     */
546 #ifndef _WIN32
489    if (geteuid() == 0)
490    {
491      fprintf(stderr, "Don't run ircd as root!!!\n");
492 <    return(-1);
492 >    return -1;
493    }
494  
495    /* Setup corefile size immediately after boot -kre */
496    setup_corefile();
497  
556  /* set initialVMTop before we allocate any memory */
557  initialVMTop = get_vm_top();
558 #endif
559
498    /* save server boot time right away, so getrusage works correctly */
499    set_time();
500  
501 <    /* It ain't random, but it ought to be a little harder to guess */
502 <  srand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20)));
501 >  /* It ain't random, but it ought to be a little harder to guess */
502 >  init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20)));
503 >
504    memset(&me, 0, sizeof(me));
505    memset(&meLocalUser, 0, sizeof(meLocalUser));
506    me.localClient = &meLocalUser;
# Line 569 | Line 508 | main(int argc, char *argv[])
508                                                     of Client list */
509  
510    memset(&ServerInfo, 0, sizeof(ServerInfo));
511 +  memset(&ServerStats, 0, sizeof(ServerStats));
512  
513    /* Initialise the channel capability usage counts... */
514    init_chcap_usage_counts();
# Line 602 | Line 542 | main(int argc, char *argv[])
542  
543    init_ssl();
544  
605 #ifndef _WIN32
545    if (!server_state.foreground)
546    {
547      make_daemon();
# Line 612 | Line 551 | main(int argc, char *argv[])
551      print_startup(getpid());
552  
553    setup_signals();
615 #endif
554  
555    get_ircd_platform(ircd_platform);
556  
# Line 626 | Line 564 | main(int argc, char *argv[])
564    /* Check if there is pidfile and daemon already running */
565    check_pidfile(pidFileName);
566  
629 #ifndef NOBALLOC
567    initBlockHeap();
631 #endif
568    init_dlink_nodes();
569    init_callbacks();
570    initialize_message_files();
# Line 641 | Line 577 | main(int argc, char *argv[])
577    init_class();
578    init_whowas();
579    watch_init();
644  init_stats();
645  read_conf_files(1);   /* cold start init conf files */
646  me.id[0] = '\0';
647  init_uid();
580    init_auth();          /* Initialise the auth code */
649 #ifndef _WIN32
581    init_resolver();      /* Needs to be setup before the io loop */
582 < #endif
582 >  read_conf_files(1);   /* cold start init conf files */
583 >  init_uid();
584    initialize_server_capabs();   /* Set up default_server_capabs */
585    initialize_global_set_options();
586    init_channels();
587  
588 <  if (ServerInfo.name == NULL)
588 >  if (EmptyString(ServerInfo.sid))
589 >  {
590 >    ilog(L_CRIT, "ERROR: No server id specified in serverinfo block.");
591 >    exit(EXIT_FAILURE);
592 >  }
593 >
594 >  strlcpy(me.id, ServerInfo.sid, sizeof(me.id));
595 >
596 >  if (EmptyString(ServerInfo.name))
597    {
598 <    ilog(L_CRIT, "No server name specified in serverinfo block.");
598 >    ilog(L_CRIT, "ERROR: No server name specified in serverinfo block.");
599      exit(EXIT_FAILURE);
600    }
601  
602    strlcpy(me.name, ServerInfo.name, sizeof(me.name));
603  
604    /* serverinfo{} description must exist.  If not, error out.*/
605 <  if (ServerInfo.description == NULL)
605 >  if (EmptyString(ServerInfo.description))
606    {
607 <    ilog(L_CRIT,
668 <      "ERROR: No server description specified in serverinfo block.");
607 >    ilog(L_CRIT, "ERROR: No server description specified in serverinfo block.");
608      exit(EXIT_FAILURE);
609    }
610  
# Line 678 | Line 617 | main(int argc, char *argv[])
617    make_server(&me);
618  
619    me.lasttime = me.since = me.firsttime = CurrentTime;
620 +
621 +  hash_add_id(&me);
622    hash_add_client(&me);
623    
624    /* add ourselves to global_serv_list */
625    dlinkAdd(&me, make_dlink_node(), &global_serv_list);
626  
686  check_class();
687
688 #ifndef STATIC_MODULES
627    if (chdir(MODPATH))
628    {
629 <    ilog (L_CRIT, "Could not load core modules. Terminating!");
629 >    ilog(L_CRIT, "Could not load core modules. Terminating!");
630      exit(EXIT_FAILURE);
631    }
632  
633    load_all_modules(1);
634    load_conf_modules();
635    load_core_modules(1);
636 +
637    /* Go back to DPATH after checking to see if we can chdir to MODPATH */
638 <  chdir(ConfigFileEntry.dpath);
639 < #else
640 <  load_all_modules(1);
641 < #endif
638 >  if (chdir(ConfigFileEntry.dpath))
639 >  {
640 >    perror("chdir");
641 >    exit(EXIT_FAILURE);
642 >  }
643 >
644    /*
645     * assemble_umode_buffer() has to be called after
646     * reading conf/loading modules.

Diff Legend

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