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

Comparing:
ircd-hybrid-7.2/src/ircd.c (file contents), Revision 998 by michael, Sun Aug 23 12:43:17 2009 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"
# Line 65 | Line 60
60   #include "supported.h"
61   #include "watch.h"
62  
68 /* Try and find the correct name to use with getrlimit() for setting the max.
69 * number of files allowed to be open by this process.
70 */
63  
64   /* /quote set variables */
65   struct SetOptions GlobalSetOptions;
# Line 78 | 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 */
# 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 123 | Line 114 | unsigned int split_servers;
114   int rehashed_klines = 0;
115  
116  
126 #ifndef _WIN32
117   /*
118   * print_startup - print startup information
119   */
# Line 154 | Line 144 | make_daemon(void)
144  
145    setsid();
146   }
157 #endif
147  
148   static int printVersion = 0;
149  
# Line 184 | Line 173 | set_time(void)
173   {
174    static char to_send[200];
175    struct timeval newtime;
187 #ifdef _WIN32
188  FILETIME ft;
189
190  GetSystemTimeAsFileTime(&ft);
191  if (ft.dwLowDateTime < 0xd53e8000)
192    ft.dwHighDateTime--;
193  ft.dwLowDateTime -= 0xd53e8000;
194  ft.dwHighDateTime -= 0x19db1de;
195
196  newtime.tv_sec  = (*(uint64_t *) &ft) / 10000000;
197  newtime.tv_usec = (*(uint64_t *) &ft) / 10 % 1000000;
198 #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    }
211 #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 314 | Line 291 | initialize_global_set_options(void)
291    }
292  
293    GlobalSetOptions.ident_timeout = IDENT_TIMEOUT;
317  GlobalSetOptions.idletime = ConfigFileEntry.idletime;
294    /* End of global set options */
295   }
296  
# Line 348 | Line 324 | initialize_server_capabs(void)
324   {
325    add_capability("QS", CAP_QS, 1);
326    add_capability("EOB", CAP_EOB, 1);
327 <
352 <  if (ServerInfo.sid != NULL)   /* only enable TS6 if we have an SID */
353 <    add_capability("TS6", CAP_TS6, 0);
354 <
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 374 | 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 385 | 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 400 | Line 374 | write_pidfile(const char *filename)
374   static void
375   check_pidfile(const char *filename)
376   {
403 #ifndef _WIN32
377    FBFILE *fb;
378    char buff[32];
379    pid_t pidfromfile;
# Line 432 | Line 405 | check_pidfile(const char *filename)
405    {
406      /* log(L_ERROR, "Error opening pid file %s", filename); */
407    }
435 #endif
408   }
409  
410   /* setup_corefile()
# Line 476 | Line 448 | init_ssl(void)
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.server_ctx, SSL_OP_NO_SSLv2);
# Line 508 | 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     */
511 #ifndef _WIN32
483    if (geteuid() == 0)
484    {
485      fprintf(stderr, "Don't run ircd as root!!!\n");
# Line 517 | Line 488 | main(int argc, char *argv[])
488  
489    /* Setup corefile size immediately after boot -kre */
490    setup_corefile();
520 #endif
491  
492    /* save server boot time right away, so getrusage works correctly */
493    set_time();
# Line 525 | Line 495 | main(int argc, char *argv[])
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  
528  memset(&me, 0, sizeof(me));
529  memset(&meLocalUser, 0, sizeof(meLocalUser));
498    me.localClient = &meLocalUser;
499    dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning
500                                                     of Client list */
533
534  memset(&ServerInfo, 0, sizeof(ServerInfo));
535  memset(&ServerStats, 0, sizeof(ServerStats));
536
501    /* Initialise the channel capability usage counts... */
502    init_chcap_usage_counts();
503  
# Line 566 | Line 530 | main(int argc, char *argv[])
530  
531    init_ssl();
532  
569 #ifndef _WIN32
533    if (!server_state.foreground)
534    {
535      make_daemon();
# Line 576 | Line 539 | main(int argc, char *argv[])
539      print_startup(getpid());
540  
541    setup_signals();
579 #endif
542  
543    get_ircd_platform(ircd_platform);
544  
# Line 584 | 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  
593 #ifndef NOBALLOC
555    initBlockHeap();
595 #endif
556    init_dlink_nodes();
557    init_callbacks();
558    initialize_message_files();
# Line 608 | Line 568 | main(int argc, char *argv[])
568    init_auth();          /* Initialise the auth code */
569    init_resolver();      /* Needs to be setup before the io loop */
570    read_conf_files(1);   /* cold start init conf files */
611  me.id[0] = '\0';
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(L_CRIT, "No server name specified in serverinfo block.");
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(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,
629 <      "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  
647  check_class();
648
649 #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 669 | 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);

Diff Legend

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