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 34 by lusky, Sun Oct 2 21:05:51 2005 UTC vs.
ircd-hybrid/trunk/src/ircd.c (file contents), Revision 7668 by michael, Wed Jul 20 17:09:49 2016 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-2016 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 16 | Line 15
15   *
16   *  You should have received a copy of the GNU General Public License
17   *  along with this program; if not, write to the Free Software
18 < *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
18 > *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
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"
29 < #include "tools.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"
32 #include "common.h"
33   #include "event.h"
34   #include "fdlist.h"
35   #include "hash.h"
36 + #include "id.h"
37   #include "irc_string.h"
37 #include "sprintf_irc.h"
38   #include "ircd_signal.h"
39 #include "list.h"
40 #include "s_gline.h"
39   #include "motd.h"
40 < #include "ircd_handler.h"
43 < #include "msg.h"         /* msgtab */
40 > #include "conf.h"
41   #include "hostmask.h"
45 #include "numeric.h"
46 #include "packet.h"
42   #include "parse.h"
43 < #include "irc_res.h"
43 > #include "res.h"
44   #include "restart.h"
45 < #include "s_auth.h"
45 > #include "rng_mt.h"
46 > #include "auth.h"
47   #include "s_bsd.h"
48 < #include "s_conf.h"
49 < #include "s_log.h"
54 < #include "s_misc.h"
55 < #include "s_serv.h"      /* try_connections */
56 < #include "s_stats.h"
48 > #include "log.h"
49 > #include "server.h"
50   #include "send.h"
51   #include "whowas.h"
52   #include "modules.h"
53   #include "memory.h"
54 < #include "hook.h"
54 > #include "mempool.h"
55   #include "ircd_getopt.h"
56 < #include "balloc.h"
57 < #include "motd.h"
58 < #include "supported.h"
56 > #include "watch.h"
57 > #include "conf_db.h"
58 > #include "conf_class.h"
59 > #include "ipcache.h"
60 > #include "isupport.h"
61 > #include "userhost.h"
62 >
63 >
64 > #ifdef HAVE_LIBGEOIP
65 > GeoIP *GeoIPv4_ctx;
66 > GeoIP *GeoIPv6_ctx;
67 > #endif
68 >
69 > struct SetOptions GlobalSetOptions;  /* /quote set variables */
70 > struct Counter Count;
71 > struct ServerState_t server_state;
72 > struct ServerStatistics ServerStats;
73 > struct ServerTime SystemTime;
74 > struct Connection meConnection;  /* That's also part of me */
75 > struct Client me = { .connection = &meConnection };  /* That's me */
76  
77 < /* 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 < */
70 <
71 < /* /quote set variables */
72 < struct SetOptions GlobalSetOptions;
73 <
74 < /* configuration set from ircd.conf */
75 < struct config_file_entry ConfigFileEntry;
76 < /* server info set from ircd.conf */
77 < struct server_info ServerInfo;
78 < /* admin info set from ircd.conf */
79 < struct admin_info AdminInfo = { NULL, NULL, NULL };
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 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 */
87 <
88 < static unsigned long initialVMTop = 0;   /* top of virtual memory at init */
77 > char **myargv;
78   const char *logFileName = LPATH;
79   const char *pidFileName = PPATH;
80  
81 < char **myargv;
82 < char ircd_platform[PLATFORMLEN];
94 <
95 < int dorehash = 0;
96 < int doremotd = 0;
97 < time_t nextconnect = 1;       /* time for next try_connections call */
98 <
99 < /* Set to zero because it should be initialized later using
100 < * initialize_server_capabs
101 < */
102 < int default_server_capabs = 0;
81 > unsigned int dorehash;
82 > unsigned int doremotd;
83  
84 < #ifdef HAVE_LIBCRYPTO
105 < int bio_spare_fd = -1;
106 < #endif
84 > static int printVersion;
85  
86 < int splitmode;
109 < int splitchecking;
110 < int split_users;
111 < unsigned int split_servers;
112 <
113 < /* Do klines the same way hybrid-6 did them, i.e. at the
114 < * top of the next io_loop instead of in the same loop as
115 < * the klines are being applied.
116 < *
117 < * This should fix strange CPU starvation as very indirectly reported.
118 < * (Why do you people not email bug reports? WHY? WHY?)
119 < *
120 < * - Dianora
121 < */
122 <
123 < int rehashed_klines = 0;
124 <
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 < }
146 <
147 < /*
148 < * print_startup - print startup information
149 < */
150 < static void
151 < print_startup(int pid)
86 > static struct lgetopt myopts[] =
87   {
88 <  printf("ircd: version %s\n", ircd_version);
89 <  printf("ircd: pid %d\n", pid);
90 <  printf("ircd: running in %s mode from %s\n", !server_state.foreground ? "background"
91 <         : "foreground", ConfigFileEntry.dpath);
92 < }
88 >  { "configfile", &ConfigGeneral.configfile,
89 >   STRING, "File to use for ircd.conf" },
90 >  { "klinefile",  &ConfigGeneral.klinefile,
91 >   STRING, "File to use for kline database" },
92 >  { "dlinefile",  &ConfigGeneral.dlinefile,
93 >   STRING, "File to use for dline database" },
94 >  { "xlinefile",  &ConfigGeneral.xlinefile,
95 >   STRING, "File to use for xline database" },
96 >  { "resvfile",   &ConfigGeneral.resvfile,
97 >   STRING, "File to use for resv database" },
98 >  { "logfile",    &logFileName,
99 >   STRING, "File to use for ircd.log" },
100 >  { "pidfile",    &pidFileName,
101 >   STRING, "File to use for process ID" },
102 >  { "foreground", &server_state.foreground,
103 >   YESNO, "Run in foreground (don't detach)" },
104 >  { "version",    &printVersion,
105 >   YESNO, "Print version and exit" },
106 >  { "help", NULL, USAGE, "Print this text" },
107 >  { NULL, NULL, STRING, NULL },
108 > };
109  
110 < static void
160 < make_daemon(void)
110 > static struct event event_cleanup_tklines =
111   {
112 <  int pid;
113 <
114 <  if ((pid = fork()) < 0)
115 <  {
166 <    perror("fork");
167 <    exit(EXIT_FAILURE);
168 <  }
169 <  else if (pid > 0)
170 <  {
171 <    print_startup(pid);
172 <    exit(EXIT_SUCCESS);
173 <  }
112 >  .name = "cleanup_tklines",
113 >  .handler = cleanup_tklines,
114 >  .when = CLEANUP_TKLINES_TIME
115 > };
116  
117 <  setsid();
118 < }
119 < #endif
117 > static struct event event_try_connections =
118 > {
119 >  .name = "try_connections",
120 >  .handler = try_connections,
121 >  .when = STARTUP_CONNECTIONS_TIME
122 > };
123  
124 < /*
180 < * get_maxrss - get the operating systems notion of the resident set size
181 < */
182 < unsigned long
183 < get_maxrss(void)
124 > static struct event event_comm_checktimeouts =
125   {
126 < #ifdef _WIN32
127 <  return (0);   /* FIXME */
128 < #else
129 <  return (get_vm_top() - initialVMTop);
189 < #endif
190 < }
126 >  .name = "comm_checktimeouts",
127 >  .handler = comm_checktimeouts,
128 >  .when = 1
129 > };
130  
131 < static int printVersion = 0;
131 > static struct event event_save_all_databases =
132 > {
133 >  .name = "save_all_databases",
134 >  .handler = save_all_databases,
135 >  .when = DATABASE_UPDATE_TIMEOUT
136 > };
137  
138 < struct lgetopt myopts[] = {
139 <  {"dlinefile",  &ConfigFileEntry.dlinefile,
140 <   STRING, "File to use for dline.conf"},
141 <  {"configfile", &ConfigFileEntry.configfile,
198 <   STRING, "File to use for ircd.conf"},
199 <  {"klinefile",  &ConfigFileEntry.klinefile,
200 <   STRING, "File to use for kline.conf"},
201 <  {"xlinefile",  &ConfigFileEntry.xlinefile,
202 <   STRING, "File to use for xline.conf"},
203 <  {"logfile",    &logFileName,
204 <   STRING, "File to use for ircd.log"},
205 <  {"pidfile",    &pidFileName,
206 <   STRING, "File to use for process ID"},
207 <  {"foreground", &server_state.foreground,
208 <   YESNO, "Run in foreground (don't detach)"},
209 <  {"version",    &printVersion,
210 <   YESNO, "Print version and exit"},
211 <  {"help", NULL, USAGE, "Print this text"},
212 <  {NULL, NULL, STRING, NULL},
138 > struct event event_write_links_file =
139 > {
140 >  .name = "write_links_file",
141 >  .handler = write_links_file,
142   };
143  
144 +
145   void
146   set_time(void)
147   {
148 <  static char to_send[200];
219 <  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
232 <  newtime.tv_sec  = 0;
233 <  newtime.tv_usec = 0;
148 >  struct timeval newtime = { .tv_sec = 0, .tv_usec = 0 };
149  
150    if (gettimeofday(&newtime, NULL) == -1)
151    {
152 <    ilog(L_ERROR, "Clock Failure (%s), TS can be corrupted",
153 <         strerror(errno));
154 <    sendto_realops_flags(UMODE_ALL, L_ALL,
155 <                         "Clock Failure (%s), TS can be corrupted",
156 <                         strerror(errno));
242 <    restart("Clock Failure");
152 >    char buf[IRCD_BUFSIZE];
153 >
154 >    snprintf(buf, sizeof(buf), "Clock failure, TS can be corrupted: %s",
155 >             strerror(errno));
156 >    server_die(buf, SERVER_SHUTDOWN);
157    }
244 #endif
158  
159 <  if (newtime.tv_sec < CurrentTime)
159 >  if ((uintmax_t)newtime.tv_sec < CurrentTime)
160    {
161 <    ircsprintf(to_send, "System clock is running backwards - (%lu < %lu)",
162 <               (unsigned long)newtime.tv_sec, (unsigned long)CurrentTime);
163 <    report_error(L_ALL, to_send, me.name, 0);
164 <    set_back_events(CurrentTime - newtime.tv_sec);
161 >    ilog(LOG_TYPE_IRCD, "System clock is running backwards - (%ju < %ju)",
162 >         (uintmax_t)newtime.tv_sec, CurrentTime);
163 >    sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE,
164 >                         "System clock is running backwards - (%ju < %ju)",
165 >                         (uintmax_t)newtime.tv_sec, CurrentTime);
166 >    event_set_back_events(CurrentTime - (uintmax_t)newtime.tv_sec);
167    }
168  
169 <  SystemTime.tv_sec  = newtime.tv_sec;
169 >  SystemTime.tv_sec = newtime.tv_sec;
170    SystemTime.tv_usec = newtime.tv_usec;
171   }
172  
173   static void
174   io_loop(void)
175   {
176 <  while (1 == 1)
176 >  while (1)
177    {
263    /*
264     * Maybe we want a flags word?
265     * ie. if (REHASHED_KLINES(global_flags))
266     * SET_REHASHED_KLINES(global_flags)
267     * CLEAR_REHASHED_KLINES(global_flags)
268     *
269     * - Dianora
270     */
271    if (rehashed_klines)
272    {
273      check_conf_klines();
274      rehashed_klines = 0;
275    }
276
178      if (listing_client_list.head)
179      {
180 <      dlink_node *ptr = NULL, *ptr_next = NULL;
181 <      DLINK_FOREACH_SAFE(ptr, ptr_next, listing_client_list.head)
182 <      {
282 <        struct Client *client_p = ptr->data;
283 <        assert(client_p->localClient->list_task);
284 <        safe_list_channels(client_p, client_p->localClient->list_task, 0, 0);
285 <      }
180 >      dlink_node *node = NULL, *node_next = NULL;
181 >      DLINK_FOREACH_SAFE(node, node_next, listing_client_list.head)
182 >        safe_list_channels(node->data, 0);
183      }
184  
185 <    /* Run pending events, then get the number of seconds to the next
186 <     * event
290 <     */
291 <    while (eventNextTime() <= CurrentTime)
292 <      eventRun();
185 >    /* Run pending events */
186 >    event_run();
187  
188      comm_select();
189      exit_aborted_clients();
190      free_exited_clients();
297    send_queued_all();
191  
192 <    /* Check to see whether we have to rehash the configuration .. */
192 >    /* Check to see whether we have to rehash the configuration. */
193      if (dorehash)
194      {
195 <      rehash(1);
195 >      conf_rehash(1);
196        dorehash = 0;
197      }
198 +
199      if (doremotd)
200      {
201 <      read_message_file(&ConfigFileEntry.motd);
202 <      sendto_realops_flags(UMODE_ALL, L_ALL,
203 <                           "Got signal SIGUSR1, reloading ircd motd file");
201 >      motd_recache();
202 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
203 >                           "Got signal SIGUSR1, reloading motd file(s)");
204        doremotd = 0;
205      }
206    }
# Line 316 | Line 210 | io_loop(void)
210   *
211   * inputs       - none
212   * output       - none
213 < * side effects - This sets all global set options needed
213 > * side effects - This sets all global set options needed
214   */
215   static void
216   initialize_global_set_options(void)
217   {
218 <  memset(&GlobalSetOptions, 0, sizeof(GlobalSetOptions));
219 <
326 <  GlobalSetOptions.autoconn  = 1;
218 >  GlobalSetOptions.maxclients = ConfigServerInfo.default_max_clients;
219 >  GlobalSetOptions.autoconn = 1;
220    GlobalSetOptions.spam_time = MIN_JOIN_LEAVE_TIME;
221 <  GlobalSetOptions.spam_num  = MAX_JOIN_LEAVE_COUNT;
222 <
223 <  if (ConfigFileEntry.default_floodcount)
224 <    GlobalSetOptions.floodcount = ConfigFileEntry.default_floodcount;
332 <  else
333 <    GlobalSetOptions.floodcount = 10;
334 <
335 <  /* XXX I have no idea what to try here - Dianora */
336 <  GlobalSetOptions.joinfloodcount = 16;
337 <  GlobalSetOptions.joinfloodtime = 8;
338 <
339 <  split_servers = ConfigChannel.default_split_server_count;
340 <  split_users   = ConfigChannel.default_split_user_count;
341 <
342 <  if (split_users && split_servers && (ConfigChannel.no_create_on_split ||
343 <                                       ConfigChannel.no_join_on_split))
344 <  {
345 <    splitmode     = 1;
346 <    splitchecking = 1;
347 <  }
348 <
221 >  GlobalSetOptions.spam_num = MAX_JOIN_LEAVE_COUNT;
222 >  GlobalSetOptions.floodcount = ConfigGeneral.default_floodcount;
223 >  GlobalSetOptions.joinfloodcount = ConfigChannel.default_join_flood_count;
224 >  GlobalSetOptions.joinfloodtime = ConfigChannel.default_join_flood_time;
225    GlobalSetOptions.ident_timeout = IDENT_TIMEOUT;
350  GlobalSetOptions.idletime = ConfigFileEntry.idletime;
351  /* End of global set options */
352 }
353
354 /* initialize_message_files()
355 *
356 * inputs       - none
357 * output       - none
358 * side effects - Set up all message files needed, motd etc.
359 */
360 static void
361 initialize_message_files(void)
362 {
363  init_message_file(USER_MOTD, MPATH, &ConfigFileEntry.motd);
364  init_message_file(OPER_MOTD, OPATH, &ConfigFileEntry.opermotd);
365  init_message_file(USER_LINKS, LIPATH, &ConfigFileEntry.linksfile);
366
367  read_message_file(&ConfigFileEntry.motd);
368  read_message_file(&ConfigFileEntry.opermotd);
369  read_message_file(&ConfigFileEntry.linksfile);
370
371  init_isupport();
372 }
373
374 /* initialize_server_capabs()
375 *
376 * inputs       - none
377 * output       - none
378 */
379 static void
380 initialize_server_capabs(void)
381 {
382  add_capability("QS", CAP_QS, 1);
383  add_capability("LL", CAP_LL, 1);
384  add_capability("EOB", CAP_EOB, 1);
385  if (ServerInfo.sid != NULL)   /* only enable TS6 if we have an SID */
386    add_capability("TS6", CAP_TS6, 0);
387  add_capability("ZIP", CAP_ZIP, 0);
388  add_capability("CLUSTER", CAP_CLUSTER, 1);
389 #ifdef HALFOPS
390  add_capability("HOPS", CAP_HOPS, 1);
391 #endif
226   }
227  
228   /* write_pidfile()
# Line 400 | Line 234 | initialize_server_capabs(void)
234   static void
235   write_pidfile(const char *filename)
236   {
237 <  FBFILE *fb;
237 >  FILE *fb;
238  
239 <  if ((fb = fbopen(filename, "w")))
239 >  if ((fb = fopen(filename, "w")))
240    {
241 <    char buff[32];
241 >    char buf[IRCD_BUFSIZE];
242      unsigned int pid = (unsigned int)getpid();
409    size_t nbytes = ircsprintf(buff, "%u\n", pid);
243  
244 <    if ((fbputs(buff, fb, nbytes) == -1))
412 <      ilog(L_ERROR, "Error writing %u to pid file %s (%s)",
413 <           pid, filename, strerror(errno));
244 >    snprintf(buf, sizeof(buf), "%u\n", pid);
245  
246 <    fbclose(fb);
247 <    return;
246 >    if (fputs(buf, fb) == -1)
247 >      ilog(LOG_TYPE_IRCD, "Error writing to pid file %s: %s",
248 >           filename, strerror(errno));
249 >
250 >    fclose(fb);
251    }
252    else
253 <  {
254 <    ilog(L_ERROR, "Error opening pid file %s", filename);
421 <  }
253 >    ilog(LOG_TYPE_IRCD, "Error opening pid file %s: %s",
254 >         filename, strerror(errno));
255   }
256  
257   /* check_pidfile()
# Line 432 | Line 265 | write_pidfile(const char *filename)
265   static void
266   check_pidfile(const char *filename)
267   {
268 < #ifndef _WIN32
269 <  FBFILE *fb;
437 <  char buff[32];
438 <  pid_t pidfromfile;
268 >  FILE *fb;
269 >  char buf[IRCD_BUFSIZE];
270  
271 <  /* Don't do logging here, since we don't have log() initialised */
441 <  if ((fb = fbopen(filename, "r")))
271 >  if ((fb = fopen(filename, "r")))
272    {
273 <    if (fbgets(buff, 20, fb) == NULL)
274 <    {
275 <      /* log(L_ERROR, "Error reading from pid file %s (%s)", filename,
446 <       * strerror(errno));
447 <       */
448 <    }
273 >    if (!fgets(buf, 20, fb))
274 >      ilog(LOG_TYPE_IRCD, "Error reading from pid file %s: %s",
275 >           filename, strerror(errno));
276      else
277      {
278 <      pidfromfile = atoi(buff);
278 >      pid_t pid = atoi(buf);
279  
280 <      if (!kill(pidfromfile, 0))
280 >      if (!kill(pid, 0))
281        {
282          /* log(L_ERROR, "Server is already running"); */
283          printf("ircd: daemon is already running\n");
284 <        exit(-1);
284 >        exit(EXIT_FAILURE);
285        }
286      }
287  
288 <    fbclose(fb);
288 >    fclose(fb);
289    }
290    else if (errno != ENOENT)
291 <  {
292 <    /* log(L_ERROR, "Error opening pid file %s", filename); */
466 <  }
467 < #endif
291 >    ilog(LOG_TYPE_IRCD, "Error opening pid file %s: %s",
292 >         filename, strerror(errno));
293   }
294  
295   /* setup_corefile()
# Line 489 | Line 314 | setup_corefile(void)
314   #endif
315   }
316  
317 < /* init_ssl()
318 < *
494 < * inputs       - nothing
495 < * output       - nothing
496 < * side effects - setups SSL context.
317 > /*
318 > * print_startup - print startup information
319   */
320   static void
321 < init_ssl(void)
321 > print_startup(int pid)
322   {
323 < #ifdef HAVE_LIBCRYPTO
324 <  SSL_load_error_strings();
325 <  SSLeay_add_ssl_algorithms();
326 <
505 <  ServerInfo.ctx = SSL_CTX_new(SSLv23_server_method());
506 <  if (!ServerInfo.ctx)
507 <  {
508 <    const char *s;
509 <
510 <    fprintf(stderr, "ERROR: Could not initialize the SSL context -- %s\n",
511 <            s = ERR_lib_error_string(ERR_get_error()));
512 <    ilog(L_CRIT, "ERROR: Could not initialize the SSL context -- %s\n", s);
513 <  }
514 <
515 <  SSL_CTX_set_options(ServerInfo.ctx, SSL_OP_NO_SSLv2);
516 <  SSL_CTX_set_options(ServerInfo.ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
517 <  SSL_CTX_set_verify(ServerInfo.ctx, SSL_VERIFY_NONE, NULL);
518 <
519 <  bio_spare_fd = save_spare_fd("SSL private key validation");
520 < #endif /* HAVE_LIBCRYPTO */
323 >  printf("ircd: version %s(%s)\n", ircd_version, serno);
324 >  printf("ircd: pid %d\n", pid);
325 >  printf("ircd: running in %s mode from %s\n", !server_state.foreground ? "background"
326 >         : "foreground", ConfigGeneral.dpath);
327   }
328  
523 /* init_callbacks()
524 *
525 * inputs       - nothing
526 * output       - nothing
527 * side effects - setups standard hook points
528 */
329   static void
330 < init_callbacks(void)
330 > make_daemon(void)
331   {
332 <  iorecv_cb = register_callback("iorecv", NULL);
333 <  iosend_cb = register_callback("iosend", NULL);
334 <  iorecvctrl_cb = register_callback("iorecvctrl", NULL);
335 <  iosendctrl_cb = register_callback("iosendctrl", NULL);
332 >  int pid;
333 >
334 >  if ((pid = fork()) < 0)
335 >  {
336 >    perror("fork");
337 >    exit(EXIT_FAILURE);
338 >  }
339 >  else if (pid > 0)
340 >  {
341 >    print_startup(pid);
342 >    exit(EXIT_SUCCESS);
343 >  }
344 >
345 >  setsid();
346   }
347  
348   int
349   main(int argc, char *argv[])
350   {
351 <  /* Check to see if the user is running
352 <   * us as root, which is a nono
543 <   */
544 < #ifndef _WIN32
545 <  if (geteuid() == 0)
351 >  /* Check to see if the user is running us as root, which is a nono */
352 >  if (!geteuid())
353    {
354 <    fprintf(stderr, "Don't run ircd as root!!!\n");
355 <    return(-1);
354 >    fprintf(stderr, "ERROR: This server won't run as root/superuser\n");
355 >    return -1;
356    }
357  
358    /* Setup corefile size immediately after boot -kre */
359    setup_corefile();
360  
361 <  /* set initialVMTop before we allocate any memory */
555 <  initialVMTop = get_vm_top();
556 < #endif
557 <
558 <  /* save server boot time right away, so getrusage works correctly */
361 >  /* Save server boot time right away, so getrusage works correctly */
362    set_time();
363  
364 <    /* It ain't random, but it ought to be a little harder to guess */
365 <  srand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20)));
366 <  memset(&me, 0, sizeof(me));
367 <  memset(&meLocalUser, 0, sizeof(meLocalUser));
368 <  me.localClient = &meLocalUser;
369 <  dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning
370 <                                                   of Client list */
371 <
372 <  memset(&ServerInfo, 0, sizeof(ServerInfo));
373 <
374 <  /* Initialise the channel capability usage counts... */
375 <  init_chcap_usage_counts();
573 <
574 <  ConfigFileEntry.dpath      = DPATH;
575 <  ConfigFileEntry.configfile = CPATH;  /* Server configuration file */
576 <  ConfigFileEntry.klinefile  = KPATH;  /* Server kline file         */
577 <  ConfigFileEntry.xlinefile  = XPATH;  /* Server xline file         */
578 <  ConfigFileEntry.rxlinefile = RXPATH; /* Server regex xline file   */
579 <  ConfigFileEntry.rklinefile = RKPATH; /* Server regex kline file   */
580 <  ConfigFileEntry.dlinefile  = DLPATH; /* dline file                */
581 <  ConfigFileEntry.glinefile  = GPATH;  /* gline log file            */
582 <  ConfigFileEntry.cresvfile  = CRESVPATH; /* channel resv file      */
583 <  ConfigFileEntry.nresvfile  = NRESVPATH; /* nick resv file         */
364 >  /* It's not random, but it ought to be a little harder to guess */
365 >  init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20)));
366 >
367 >  ConfigGeneral.dpath      = DPATH;
368 >  ConfigGeneral.spath      = SPATH;
369 >  ConfigGeneral.mpath      = MPATH;
370 >  ConfigGeneral.configfile = CPATH;    /* Server configuration file */
371 >  ConfigGeneral.klinefile  = KPATH;    /* Server kline file         */
372 >  ConfigGeneral.xlinefile  = XPATH;    /* Server xline file         */
373 >  ConfigGeneral.dlinefile  = DLPATH;   /* dline file                */
374 >  ConfigGeneral.resvfile   = RESVPATH; /* resv file                 */
375 >
376    myargv = argv;
377 <  umask(077);                /* better safe than sorry --SRB */
377 >  umask(077);  /* umask 077: u=rwx,g=,o= */
378  
379    parseargs(&argc, &argv, myopts);
380  
381    if (printVersion)
382    {
383 <    printf("ircd: version %s\n", ircd_version);
383 >    printf("ircd: version %s(%s)\n", ircd_version, serno);
384      exit(EXIT_SUCCESS);
385    }
386  
387 <  if (chdir(ConfigFileEntry.dpath))
387 >  if (chdir(ConfigGeneral.dpath))
388    {
389      perror("chdir");
390      exit(EXIT_FAILURE);
391    }
392  
601  init_ssl();
602
603 #ifndef _WIN32
393    if (!server_state.foreground)
394    {
395      make_daemon();
396 <    close_standard_fds(); /* this needs to be before init_netio()! */
396 >    close_standard_fds(); /* this needs to be before netio_init()! */
397    }
398    else
399      print_startup(getpid());
400  
401    setup_signals();
613 #endif
614
615  get_ircd_platform(ircd_platform);
402  
617  /* Init the event subsystem */
618  eventInit();
403    /* We need this to initialise the fd array before anything else */
404    fdlist_init();
405 <  init_log(logFileName);
406 <  check_can_use_v6();
407 <  init_comm();         /* This needs to be setup early ! -- adrian */
405 >  log_set_file(LOG_TYPE_IRCD, 0, logFileName);
406 >
407 >  netio_init();         /* This needs to be setup early ! -- adrian */
408 >  tls_init();
409 >
410    /* Check if there is pidfile and daemon already running */
411    check_pidfile(pidFileName);
412  
413 < #ifndef NOBALLOC
628 <  initBlockHeap();
629 < #endif
413 >  mp_pool_init();
414    init_dlink_nodes();
415 <  init_callbacks();
632 <  initialize_message_files();
415 >  isupport_init();
416    dbuf_init();
417 <  init_hash();
418 <  init_ip_hash_table();      /* client host ip hash table */
419 <  init_host_hash();          /* Host-hashtable. */
420 <  clear_tree_parse();
421 <  init_client();
422 <  init_class();
423 <  init_whowas();
424 <  init_stats();
417 >  hash_init();
418 >  userhost_init();
419 >  ipcache_init();
420 >  client_init();
421 >  class_init();
422 >  whowas_init();
423 >  watch_init();
424 >  auth_init();          /* Initialise the auth code */
425 >  resolver_init();      /* Needs to be setup before the io loop */
426 >  modules_init();
427    read_conf_files(1);   /* cold start init conf files */
428 <  initServerMask();
429 <  me.id[0] = '\0';
430 <  init_uid();
431 <  init_auth();          /* Initialise the auth code */
432 < #ifndef _WIN32
433 <  init_resolver();      /* Needs to be setup before the io loop */
649 < #endif
650 <  initialize_server_capabs();   /* Set up default_server_capabs */
651 <  initialize_global_set_options();
652 <  init_channels();
428 >  server_capab_init();  /* Set up default_server_capabs */
429 >  initialize_global_set_options();  /* Has to be called after read_conf_files() */
430 >  channel_init();
431 >  read_links_file();
432 >  motd_init();
433 >  user_modes_init();
434  
435 <  if (ServerInfo.name == NULL)
435 >  if (EmptyString(ConfigServerInfo.name))
436    {
437 <    ilog(L_CRIT, "No server name specified in serverinfo block.");
437 >    ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block.");
438      exit(EXIT_FAILURE);
439    }
659  strlcpy(me.name, ServerInfo.name, sizeof(me.name));
440  
441 <  /* serverinfo{} description must exist.  If not, error out.*/
442 <  if (ServerInfo.description == NULL)
441 >  strlcpy(me.name, ConfigServerInfo.name, sizeof(me.name));
442 >
443 >  /* serverinfo {} description must exist.  If not, error out.*/
444 >  if (EmptyString(ConfigServerInfo.description))
445    {
446 <    ilog(L_CRIT,
665 <      "ERROR: No server description specified in serverinfo block.");
446 >    ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block.");
447      exit(EXIT_FAILURE);
448    }
668  strlcpy(me.info, ServerInfo.description, sizeof(me.info));
449  
450 <  me.from    = &me;
450 >  strlcpy(me.info, ConfigServerInfo.description, sizeof(me.info));
451 >
452 >  if (EmptyString(ConfigServerInfo.sid))
453 >  {
454 >    ilog(LOG_TYPE_IRCD, "Generating server ID");
455 >    generate_sid();
456 >  }
457 >  else
458 >    strlcpy(me.id, ConfigServerInfo.sid, sizeof(me.id));
459 >
460 >  init_uid();
461 >
462 >  me.from = &me;
463    me.servptr = &me;
464 +  me.connection->lasttime = CurrentTime;
465 +  me.connection->since = CurrentTime;
466 +  me.connection->firsttime = CurrentTime;
467  
468    SetMe(&me);
469    make_server(&me);
470  
471 <  me.lasttime = me.since = me.firsttime = CurrentTime;
471 >  hash_add_id(&me);
472    hash_add_client(&me);
678  
679  /* add ourselves to global_serv_list */
680  dlinkAdd(&me, make_dlink_node(), &global_serv_list);
473  
474 <  check_class();
474 >  dlinkAdd(&me, make_dlink_node(), &global_server_list);
475 >  dlinkAdd(&me, &me.node, &global_client_list);
476  
477 < #ifndef STATIC_MODULES
478 <  if (chdir(MODPATH))
479 <  {
480 <    ilog (L_CRIT, "Could not load core modules. Terminating!");
688 <    exit(EXIT_FAILURE);
689 <  }
477 >  load_kline_database(ConfigGeneral.klinefile);
478 >  load_dline_database(ConfigGeneral.dlinefile);
479 >  load_xline_database(ConfigGeneral.xlinefile);
480 >  load_resv_database(ConfigGeneral.resvfile);
481  
482    load_all_modules(1);
483    load_conf_modules();
484    load_core_modules(1);
694  /* Go back to DPATH after checking to see if we can chdir to MODPATH */
695  chdir(ConfigFileEntry.dpath);
696 #else
697  load_all_modules(1);
698 #endif
699  /*
700   * assemble_umode_buffer() has to be called after
701   * reading conf/loading modules.
702   */
703  assemble_umode_buffer();
485  
486    write_pidfile(pidFileName);
487  
488 <  ilog(L_NOTICE, "Server Ready");
708 <
709 <  eventAddIsh("cleanup_glines", cleanup_glines, NULL, CLEANUP_GLINES_TIME);
710 <  eventAddIsh("cleanup_tklines", cleanup_tklines, NULL, CLEANUP_TKLINES_TIME);
488 >  event_addish(&event_cleanup_tklines, NULL);
489  
490    /* We want try_connections to be called as soon as possible now! -- adrian */
491    /* No, 'cause after a restart it would cause all sorts of nick collides */
492 <  eventAddIsh("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME);
715 <
716 <  eventAddIsh("collect_zipstats", collect_zipstats, NULL, ZIPSTATS_TIME);
492 >  event_addish(&event_try_connections, NULL);
493  
494    /* Setup the timeout check. I'll shift it later :)  -- adrian */
495 <  eventAddIsh("comm_checktimeouts", comm_checktimeouts, NULL, 1);
495 >  event_add(&event_comm_checktimeouts, NULL);
496  
497 <  if (ConfigServerHide.links_delay > 0)
722 <    eventAddIsh("write_links_file", write_links_file, NULL, ConfigServerHide.links_delay);
723 <  else
724 <    ConfigServerHide.links_disabled = 1;
497 >  event_addish(&event_save_all_databases, NULL);
498  
499 <  if (splitmode)
500 <    eventAddIsh("check_splitmode", check_splitmode, NULL, 60);
499 >  if (ConfigServerHide.flatten_links_delay && event_write_links_file.active == 0)
500 >  {
501 >    event_write_links_file.when = ConfigServerHide.flatten_links_delay;
502 >    event_add(&event_write_links_file, NULL);
503 >  }
504  
505 +  ilog(LOG_TYPE_IRCD, "Server Ready");
506    io_loop();
507 <  return(0);
507 >
508 >  return 0;
509   }

Comparing:
ircd-hybrid-7.2/src/ircd.c (property svn:keywords), Revision 34 by lusky, Sun Oct 2 21:05:51 2005 UTC vs.
ircd-hybrid/trunk/src/ircd.c (property svn:keywords), Revision 7668 by michael, Wed Jul 20 17:09:49 2016 UTC

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

Diff Legend

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