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/trunk/src/ircd.c (file contents), Revision 2632 by michael, Sun Dec 8 18:33:48 2013 UTC vs.
ircd-hybrid/branches/8.2.x/src/ircd.c (file contents), Revision 3906 by michael, Fri Jun 6 23:52:50 2014 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 < *  ircd.c: Starts up and runs the ircd.
2 > *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (C) 2002 by the past and present ircd coders, and others.
4 > *  Copyright (c) 1997-2014 ircd-hybrid development team
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 18 | Line 17
17   *  along with this program; if not, write to the Free Software
18   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
19   *  USA
20 < *
21 < *  $Id$
20 > */
21 >
22 > /*! \file ircd.c
23 > * \brief Starts up and runs the ircd.
24 > * \version $Id$
25   */
26  
27   #include "stdinc.h"
28 < #include "s_user.h"
28 > #include "user.h"
29   #include "list.h"
30   #include "ircd.h"
31   #include "channel.h"
30 #include "channel_mode.h"
32   #include "client.h"
33   #include "event.h"
34   #include "fdlist.h"
35   #include "hash.h"
36   #include "irc_string.h"
37   #include "ircd_signal.h"
38 < #include "s_gline.h"
38 > #include "gline.h"
39   #include "motd.h"
40   #include "conf.h"
41   #include "hostmask.h"
41 #include "numeric.h"
42 #include "packet.h"
42   #include "parse.h"
43 < #include "irc_res.h"
43 > #include "res.h"
44   #include "restart.h"
45   #include "rng_mt.h"
46 < #include "s_auth.h"
46 > #include "auth.h"
47   #include "s_bsd.h"
48   #include "log.h"
49 < #include "s_misc.h"
51 < #include "s_serv.h"      /* try_connections */
49 > #include "server.h"      /* try_connections */
50   #include "send.h"
51   #include "whowas.h"
52   #include "modules.h"
53   #include "memory.h"
54   #include "mempool.h"
57 #include "hook.h"
55   #include "ircd_getopt.h"
56   #include "supported.h"
57   #include "watch.h"
# Line 65 | Line 62
62   #ifdef HAVE_LIBGEOIP
63   GeoIP *geoip_ctx;
64   #endif
65 +
66   /* /quote set variables */
67   struct SetOptions GlobalSetOptions;
68 <
69 < /* configuration set from ircd.conf */
72 < struct config_file_entry ConfigFileEntry;
73 < /* server info set from ircd.conf */
74 < struct server_info ServerInfo;
75 < /* admin info set from ircd.conf */
76 < struct admin_info AdminInfo = { NULL, NULL, NULL };
77 < struct Counter Count = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
78 < struct ServerState_t server_state = { 0 };
79 < struct logging_entry ConfigLoggingEntry = { .use_logging = 1 };
68 > struct Counter Count;
69 > struct ServerState_t server_state;
70   struct ServerStatistics ServerStats;
71   struct timeval SystemTime;
72   struct Client me;             /* That's me */
# Line 93 | Line 83 | int doremotd = 0;
83   /* Set to zero because it should be initialized later using
84   * initialize_server_capabs
85   */
86 < int default_server_capabs = 0;
86 > unsigned int default_server_capabs;
87   unsigned int splitmode;
88   unsigned int splitchecking;
89   unsigned int split_users;
# Line 118 | Line 108 | int rehashed_klines = 0;
108   static void
109   print_startup(int pid)
110   {
111 <  printf("ircd: version %s\n", ircd_version);
111 >  printf("ircd: version %s(%s)\n", ircd_version, serno);
112    printf("ircd: pid %d\n", pid);
113    printf("ircd: running in %s mode from %s\n", !server_state.foreground ? "background"
114           : "foreground", ConfigFileEntry.dpath);
# Line 145 | Line 135 | make_daemon(void)
135  
136   static int printVersion = 0;
137  
138 < static struct lgetopt myopts[] = {
139 <  {"configfile", &ConfigFileEntry.configfile,
138 > static struct lgetopt myopts[] =
139 > {
140 >  {"configfile", &ConfigFileEntry.configfile,
141     STRING, "File to use for ircd.conf"},
142    {"glinefile",  &ConfigFileEntry.glinefile,
143     STRING, "File to use for gline database"},
144 <  {"klinefile",  &ConfigFileEntry.klinefile,
144 >  {"klinefile",  &ConfigFileEntry.klinefile,
145     STRING, "File to use for kline database"},
146    {"dlinefile",  &ConfigFileEntry.dlinefile,
147     STRING, "File to use for dline database"},
148 <  {"xlinefile",  &ConfigFileEntry.xlinefile,
148 >  {"xlinefile",  &ConfigFileEntry.xlinefile,
149     STRING, "File to use for xline database"},
150    {"resvfile",  &ConfigFileEntry.resvfile,
151     STRING, "File to use for resv database"},
152 <  {"logfile",    &logFileName,
152 >  {"logfile",    &logFileName,
153     STRING, "File to use for ircd.log"},
154    {"pidfile",    &pidFileName,
155     STRING, "File to use for process ID"},
156 <  {"foreground", &server_state.foreground,
156 >  {"foreground", &server_state.foreground,
157     YESNO, "Run in foreground (don't detach)"},
158 <  {"version",    &printVersion,
158 >  {"version",    &printVersion,
159     YESNO, "Print version and exit"},
160    {"help", NULL, USAGE, "Print this text"},
161    {NULL, NULL, STRING, NULL},
# Line 173 | Line 164 | static struct lgetopt myopts[] = {
164   void
165   set_time(void)
166   {
167 <  static char to_send[200];
177 <  struct timeval newtime;
178 <  newtime.tv_sec  = 0;
179 <  newtime.tv_usec = 0;
167 >  struct timeval newtime = { .tv_sec = 0, .tv_usec = 0 };
168  
169    if (gettimeofday(&newtime, NULL) == -1)
170    {
# Line 185 | Line 173 | set_time(void)
173      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
174                           "Clock Failure (%s), TS can be corrupted",
175                           strerror(errno));
176 <    restart("Clock Failure");
176 >    server_die("Clock Failure", 1);
177    }
178  
179    if (newtime.tv_sec < CurrentTime)
180    {
181 <    snprintf(to_send, sizeof(to_send),
182 <             "System clock is running backwards - (%lu < %lu)",
183 <             (unsigned long)newtime.tv_sec, (unsigned long)CurrentTime);
184 <    report_error(L_ALL, to_send, me.name, 0);
181 >    ilog(LOG_TYPE_IRCD, "System clock is running backwards - (%lu < %lu)",
182 >         (unsigned long)newtime.tv_sec, (unsigned long)CurrentTime);
183 >    sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE,
184 >                         "System clock is running backwards - (%lu < %lu)",
185 >                         (unsigned long)newtime.tv_sec,
186 >                         (unsigned long)CurrentTime);
187      set_back_events(CurrentTime - newtime.tv_sec);
188    }
189  
# Line 204 | Line 194 | set_time(void)
194   static void
195   io_loop(void)
196   {
197 <  while (1 == 1)
197 >  while (1)
198    {
199      /*
200       * Maybe we want a flags word?
201 <     * ie. if (REHASHED_KLINES(global_flags))
201 >     * ie. if (REHASHED_KLINES(global_flags))
202       * SET_REHASHED_KLINES(global_flags)
203       * CLEAR_REHASHED_KLINES(global_flags)
204       *
# Line 224 | Line 214 | io_loop(void)
214      {
215        dlink_node *ptr = NULL, *ptr_next = NULL;
216        DLINK_FOREACH_SAFE(ptr, ptr_next, listing_client_list.head)
217 <      {
228 <        struct Client *client_p = ptr->data;
229 <        assert(client_p->localClient->list_task);
230 <        safe_list_channels(client_p, client_p->localClient->list_task, 0);
231 <      }
217 >        safe_list_channels(ptr->data, 0);
218      }
219  
220      /* Run pending events, then get the number of seconds to the next
# Line 240 | Line 226 | io_loop(void)
226      comm_select();
227      exit_aborted_clients();
228      free_exited_clients();
243    send_queued_all();
229  
230      /* Check to see whether we have to rehash the configuration .. */
231      if (dorehash)
# Line 248 | Line 233 | io_loop(void)
233        rehash(1);
234        dorehash = 0;
235      }
236 +
237      if (doremotd)
238      {
239        motd_recache();
240        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
241 <                           "Got signal SIGUSR1, reloading motd files");
241 >                           "Got signal SIGUSR1, reloading motd file(s)");
242        doremotd = 0;
243      }
244    }
# Line 262 | Line 248 | io_loop(void)
248   *
249   * inputs       - none
250   * output       - none
251 < * side effects - This sets all global set options needed
251 > * side effects - This sets all global set options needed
252   */
253   static void
254   initialize_global_set_options(void)
# Line 308 | Line 294 | initialize_server_capabs(void)
294    add_capability("EOB", CAP_EOB, 1);
295    add_capability("TS6", CAP_TS6, 0);
296    add_capability("CLUSTER", CAP_CLUSTER, 1);
311 //  add_capability("FAKEHOST", CAP_FAKEHOST, 1);
297    add_capability("SVS", CAP_SVS, 1);
298 < #ifdef HALFOPS
298 >  add_capability("CHW", CAP_CHW, 1);
299    add_capability("HOPS", CAP_HOPS, 1);
315 #endif
300   }
301  
302   /* write_pidfile()
# Line 328 | Line 312 | write_pidfile(const char *filename)
312  
313    if ((fb = fopen(filename, "w")))
314    {
315 <    char buff[32];
315 >    char buff[IRCD_BUFSIZE];
316      unsigned int pid = (unsigned int)getpid();
317  
318      snprintf(buff, sizeof(buff), "%u\n", pid);
# Line 357 | Line 341 | static void
341   check_pidfile(const char *filename)
342   {
343    FILE *fb;
344 <  char buff[32];
344 >  char buff[IRCD_BUFSIZE];
345    pid_t pidfromfile;
346  
347    /* Don't do logging here, since we don't have log() initialised */
# Line 429 | Line 413 | static void
413   ssl_init(void)
414   {
415   #ifdef HAVE_LIBCRYPTO
416 +  const unsigned char session_id[] = "ircd-hybrid";
417 +
418    SSL_load_error_strings();
419    SSLeay_add_ssl_algorithms();
420  
# Line 445 | Line 431 | ssl_init(void)
431    SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
432    SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
433                       always_accept_verify_cb);
434 +  SSL_CTX_set_session_id_context(ServerInfo.server_ctx, session_id, sizeof(session_id) - 1);
435  
436    if ((ServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL)
437    {
# Line 468 | Line 455 | main(int argc, char *argv[])
455    /* Check to see if the user is running us as root, which is a nono */
456    if (geteuid() == 0)
457    {
458 <    fprintf(stderr, "Don't run ircd as root!!!\n");
458 >    fprintf(stderr, "ERROR: This server won't run as root/superuser\n");
459      return -1;
460    }
461  
# Line 484 | Line 471 | main(int argc, char *argv[])
471    me.localClient = &meLocalUser;
472    dlinkAdd(&me, &me.node, &global_client_list);  /* Pointer to beginning
473                                                     of Client list */
487  /* Initialise the channel capability usage counts... */
488  init_chcap_usage_counts();
489
474    ConfigFileEntry.dpath      = DPATH;
475 +  ConfigFileEntry.spath      = SPATH;
476 +  ConfigFileEntry.mpath      = MPATH;
477    ConfigFileEntry.configfile = CPATH;    /* Server configuration file */
478    ConfigFileEntry.klinefile  = KPATH;    /* Server kline file         */
479    ConfigFileEntry.glinefile  = GPATH;    /* Server gline file         */
# Line 502 | Line 488 | main(int argc, char *argv[])
488  
489    if (printVersion)
490    {
491 <    printf("ircd: version %s\n", ircd_version);
491 >    printf("ircd: version %s(%s)\n", ircd_version, serno);
492      exit(EXIT_SUCCESS);
493    }
494  
# Line 597 | Line 583 | main(int argc, char *argv[])
583  
584    hash_add_id(&me);
585    hash_add_client(&me);
586 <  
586 >
587    /* add ourselves to global_serv_list */
588    dlinkAdd(&me, make_dlink_node(), &global_serv_list);
589  

Diff Legend

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