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 30 by adx, Sun Oct 2 20:03:27 2005 UTC vs.
ircd-hybrid-8/src/ircd.c (file contents), Revision 1176 by michael, Sun Aug 14 11:24:24 2011 UTC

# Line 19 | Line 19
19   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
20   *  USA
21   *
22 < *  $Id: ircd.c,v 7.369 2005/09/24 09:27:18 michael Exp $
22 > *  $Id$
23   */
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  
66   /* Try and find the correct name to use with getrlimit() for setting the max.
67   * number of files allowed to be open by this process.
# Line 77 | Line 76 | struct config_file_entry ConfigFileEntry
76   struct server_info ServerInfo;
77   /* admin info set from ircd.conf */
78   struct admin_info AdminInfo = { NULL, NULL, NULL };
79 < struct Counter Count = { 0, 0, 0, 0, 0, 0, 0, 0 };
79 > struct Counter Count = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
80   struct ServerState_t server_state = { 0 };
81   struct logging_entry ConfigLoggingEntry = { 1, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0} };
82 + struct ServerStatistics ServerStats;
83   struct timeval SystemTime;
84   struct Client me;             /* That's me */
85   struct LocalUser meLocalUser; /* That's also part of me */
86 unsigned long connect_id = 0; /* unique connect ID */
86  
88 static unsigned long initialVMTop = 0;   /* top of virtual memory at init */
87   const char *logFileName = LPATH;
88   const char *pidFileName = PPATH;
89  
# Line 94 | Line 92 | char ircd_platform[PLATFORMLEN];
92  
93   int dorehash = 0;
94   int doremotd = 0;
97 time_t nextconnect = 1;       /* time for next try_connections call */
95  
96   /* Set to zero because it should be initialized later using
97   * initialize_server_capabs
# Line 105 | Line 102 | int default_server_capabs = 0;
102   int bio_spare_fd = -1;
103   #endif
104  
105 < int splitmode;
106 < int splitchecking;
107 < int split_users;
105 > unsigned int splitmode;
106 > unsigned int splitchecking;
107 > unsigned int split_users;
108   unsigned int split_servers;
109  
110   /* Do klines the same way hybrid-6 did them, i.e. at the
# Line 122 | Line 119 | unsigned int split_servers;
119  
120   int rehashed_klines = 0;
121  
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 }
122  
123   /*
124   * print_startup - print startup information
# Line 174 | Line 150 | make_daemon(void)
150  
151    setsid();
152   }
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 }
153  
154   static int printVersion = 0;
155  
# Line 217 | Line 179 | set_time(void)
179   {
180    static char to_send[200];
181    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
182    newtime.tv_sec  = 0;
183    newtime.tv_usec = 0;
184  
# Line 241 | Line 191 | set_time(void)
191                           strerror(errno));
192      restart("Clock Failure");
193    }
244 #endif
194  
195    if (newtime.tv_sec < CurrentTime)
196    {
197 <    ircsprintf(to_send, "System clock is running backwards - (%lu < %lu)",
198 <               (unsigned long)newtime.tv_sec, (unsigned long)CurrentTime);
197 >    snprintf(to_send, sizeof(to_send),
198 >             "System clock is running backwards - (%lu < %lu)",
199 >             (unsigned long)newtime.tv_sec, (unsigned long)CurrentTime);
200      report_error(L_ALL, to_send, me.name, 0);
201      set_back_events(CurrentTime - newtime.tv_sec);
202    }
# Line 281 | 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 347 | Line 297 | initialize_global_set_options(void)
297    }
298  
299    GlobalSetOptions.ident_timeout = IDENT_TIMEOUT;
350  GlobalSetOptions.idletime = ConfigFileEntry.idletime;
300    /* End of global set options */
301   }
302  
# Line 380 | Line 329 | static void
329   initialize_server_capabs(void)
330   {
331    add_capability("QS", CAP_QS, 1);
383  add_capability("LL", CAP_LL, 1);
332    add_capability("EOB", CAP_EOB, 1);
333 <  if (ServerInfo.sid != NULL)   /* only enable TS6 if we have an SID */
386 <    add_capability("TS6", CAP_TS6, 0);
333 >  add_capability("TS6", CAP_TS6, 0);
334    add_capability("ZIP", CAP_ZIP, 0);
335    add_capability("CLUSTER", CAP_CLUSTER, 1);
336   #ifdef HALFOPS
# Line 406 | Line 353 | write_pidfile(const char *filename)
353    {
354      char buff[32];
355      unsigned int pid = (unsigned int)getpid();
356 <    size_t nbytes = ircsprintf(buff, "%u\n", pid);
356 >    size_t nbytes = snprintf(buff, sizeof(buff), "%u\n", pid);
357  
358      if ((fbputs(buff, fb, nbytes) == -1))
359        ilog(L_ERROR, "Error writing %u to pid file %s (%s)",
# Line 432 | Line 379 | write_pidfile(const char *filename)
379   static void
380   check_pidfile(const char *filename)
381   {
435 #ifndef _WIN32
382    FBFILE *fb;
383    char buff[32];
384    pid_t pidfromfile;
# Line 464 | Line 410 | check_pidfile(const char *filename)
410    {
411      /* log(L_ERROR, "Error opening pid file %s", filename); */
412    }
467 #endif
413   }
414  
415   /* setup_corefile()
# Line 502 | Line 447 | init_ssl(void)
447    SSL_load_error_strings();
448    SSLeay_add_ssl_algorithms();
449  
450 <  ServerInfo.ctx = SSL_CTX_new(SSLv23_server_method());
506 <  if (!ServerInfo.ctx)
450 >  if ((ServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL)
451    {
452      const char *s;
453  
# Line 512 | Line 456 | init_ssl(void)
456      ilog(L_CRIT, "ERROR: Could not initialize the SSL context -- %s\n", s);
457    }
458  
459 <  SSL_CTX_set_options(ServerInfo.ctx, SSL_OP_NO_SSLv2);
460 <  SSL_CTX_set_options(ServerInfo.ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
461 <  SSL_CTX_set_verify(ServerInfo.ctx, SSL_VERIFY_NONE, NULL);
459 >  SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2);
460 >  SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
461 >  SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_NONE, NULL);
462  
463    bio_spare_fd = save_spare_fd("SSL private key validation");
464   #endif /* HAVE_LIBCRYPTO */
# Line 529 | Line 473 | init_ssl(void)
473   static void
474   init_callbacks(void)
475   {
476 <  iorecv_cb = register_callback("iorecv", NULL);
477 <  iosend_cb = register_callback("iosend", NULL);
476 >  iorecv_cb = register_callback("iorecv", iorecv_default);
477 >  iosend_cb = register_callback("iosend", iosend_default);
478    iorecvctrl_cb = register_callback("iorecvctrl", NULL);
479    iosendctrl_cb = register_callback("iosendctrl", NULL);
480   }
# Line 541 | Line 485 | main(int argc, char *argv[])
485    /* Check to see if the user is running
486     * us as root, which is a nono
487     */
544 #ifndef _WIN32
488    if (geteuid() == 0)
489    {
490      fprintf(stderr, "Don't run ircd as root!!!\n");
491 <    return(-1);
491 >    return -1;
492    }
493  
494    /* Setup corefile size immediately after boot -kre */
495    setup_corefile();
496  
554  /* set initialVMTop before we allocate any memory */
555  initialVMTop = get_vm_top();
556 #endif
557
497    /* save server boot time right away, so getrusage works correctly */
498    set_time();
499  
500 <    /* It ain't random, but it ought to be a little harder to guess */
501 <  srand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20)));
502 <  memset(&me, 0, sizeof(me));
564 <  memset(&meLocalUser, 0, sizeof(meLocalUser));
500 >  /* It ain't random, but it ought to be a little harder to guess */
501 >  init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20)));
502 >
503    me.localClient = &meLocalUser;
504    dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning
505                                                     of Client list */
568
569  memset(&ServerInfo, 0, sizeof(ServerInfo));
570
506    /* Initialise the channel capability usage counts... */
507    init_chcap_usage_counts();
508  
# Line 600 | Line 535 | main(int argc, char *argv[])
535  
536    init_ssl();
537  
603 #ifndef _WIN32
538    if (!server_state.foreground)
539    {
540      make_daemon();
# Line 610 | Line 544 | main(int argc, char *argv[])
544      print_startup(getpid());
545  
546    setup_signals();
613 #endif
547  
548    get_ircd_platform(ircd_platform);
549  
# Line 624 | Line 557 | main(int argc, char *argv[])
557    /* Check if there is pidfile and daemon already running */
558    check_pidfile(pidFileName);
559  
627 #ifndef NOBALLOC
560    initBlockHeap();
629 #endif
561    init_dlink_nodes();
562    init_callbacks();
563    initialize_message_files();
# Line 638 | Line 569 | main(int argc, char *argv[])
569    init_client();
570    init_class();
571    init_whowas();
572 <  init_stats();
642 <  read_conf_files(1);   /* cold start init conf files */
643 <  initServerMask();
644 <  me.id[0] = '\0';
645 <  init_uid();
572 >  watch_init();
573    init_auth();          /* Initialise the auth code */
647 #ifndef _WIN32
574    init_resolver();      /* Needs to be setup before the io loop */
575 < #endif
575 >  read_conf_files(1);   /* cold start init conf files */
576 >  init_uid();
577    initialize_server_capabs();   /* Set up default_server_capabs */
578    initialize_global_set_options();
579    init_channels();
580  
581 <  if (ServerInfo.name == NULL)
581 >  if (EmptyString(ServerInfo.sid))
582    {
583 <    ilog(L_CRIT, "No server name specified in serverinfo block.");
583 >    ilog(L_CRIT, "ERROR: No server id specified in serverinfo block.");
584      exit(EXIT_FAILURE);
585    }
586 +
587 +  strlcpy(me.id, ServerInfo.sid, sizeof(me.id));
588 +
589 +  if (EmptyString(ServerInfo.name))
590 +  {
591 +    ilog(L_CRIT, "ERROR: No server name specified in serverinfo block.");
592 +    exit(EXIT_FAILURE);
593 +  }
594 +
595    strlcpy(me.name, ServerInfo.name, sizeof(me.name));
596  
597    /* serverinfo{} description must exist.  If not, error out.*/
598 <  if (ServerInfo.description == NULL)
598 >  if (EmptyString(ServerInfo.description))
599    {
600 <    ilog(L_CRIT,
665 <      "ERROR: No server description specified in serverinfo block.");
600 >    ilog(L_CRIT, "ERROR: No server description specified in serverinfo block.");
601      exit(EXIT_FAILURE);
602    }
603 +
604    strlcpy(me.info, ServerInfo.description, sizeof(me.info));
605  
606 <  me.from    = &me;
607 <  me.servptr = &me;
606 >  me.from     = &me;
607 >  me.servptr  = &me;
608 >  me.lasttime = me.since = me.firsttime = CurrentTime;
609  
610    SetMe(&me);
611    make_server(&me);
612  
613 <  me.lasttime = me.since = me.firsttime = CurrentTime;
613 >  hash_add_id(&me);
614    hash_add_client(&me);
615    
616    /* add ourselves to global_serv_list */
617    dlinkAdd(&me, make_dlink_node(), &global_serv_list);
618  
682  check_class();
683
684 #ifndef STATIC_MODULES
619    if (chdir(MODPATH))
620    {
621 <    ilog (L_CRIT, "Could not load core modules. Terminating!");
621 >    ilog(L_CRIT, "Could not load core modules. Terminating!");
622      exit(EXIT_FAILURE);
623    }
624  
625    load_all_modules(1);
626    load_conf_modules();
627    load_core_modules(1);
628 +
629    /* Go back to DPATH after checking to see if we can chdir to MODPATH */
630 <  chdir(ConfigFileEntry.dpath);
631 < #else
632 <  load_all_modules(1);
633 < #endif
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.
# Line 727 | Line 664 | main(int argc, char *argv[])
664      eventAddIsh("check_splitmode", check_splitmode, NULL, 60);
665  
666    io_loop();
667 <  return(0);
667 >  return 0;
668   }

Comparing:
ircd-hybrid/src/ircd.c (property svn:keywords), Revision 30 by adx, Sun Oct 2 20:03:27 2005 UTC vs.
ircd-hybrid-8/src/ircd.c (property svn:keywords), Revision 1176 by michael, Sun Aug 14 11:24:24 2011 UTC

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

Diff Legend

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