]> jfr.im git - solanum.git/blame - ircd/ircd.c
ircd: do not shadow internal openssl symbol "ssl_ok" (yeah, i know)
[solanum.git] / ircd / ircd.c
CommitLineData
212380e3 1/*
6fce54ff 2 * charybdis: A slightly useful ircd.
212380e3
AC
3 * ircd.c: Starts up and runs the ircd.
4 *
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
6fce54ff 7 * Copyright (C) 2002-2008 ircd-ratbox development team
adef4da1 8 * Copyright (C) 2005-2013 charybdis development team
212380e3
AC
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 * USA
212380e3
AC
24 */
25
fe037171 26#include "rb_lib.h"
212380e3
AC
27#include "stdinc.h"
28#include "setup.h"
29#include "config.h"
212380e3
AC
30#include "ircd.h"
31#include "channel.h"
32#include "class.h"
33#include "client.h"
34#include "common.h"
212380e3 35#include "hash.h"
4562c604 36#include "match.h"
212380e3 37#include "ircd_signal.h"
212380e3
AC
38#include "msg.h" /* msgtab */
39#include "hostmask.h"
40#include "numeric.h"
41#include "parse.h"
212380e3
AC
42#include "restart.h"
43#include "s_auth.h"
212380e3 44#include "s_conf.h"
4016731b 45#include "logger.h"
212380e3
AC
46#include "s_serv.h" /* try_connections */
47#include "s_user.h"
48#include "s_stats.h"
49#include "scache.h"
50#include "send.h"
51#include "supported.h"
52#include "whowas.h"
53#include "modules.h"
212380e3
AC
54#include "hook.h"
55#include "ircd_getopt.h"
212380e3 56#include "newconf.h"
212380e3
AC
57#include "reject.h"
58#include "s_conf.h"
59#include "s_newconf.h"
60#include "cache.h"
61#include "monitor.h"
212380e3
AC
62#include "patchlevel.h"
63#include "serno.h"
c6d72037 64#include "sslproc.h"
efccc22c 65#include "chmode.h"
39a68b53 66#include "privilege.h"
6eebc373 67#include "bandbi.h"
6d063f05 68#include "authd.h"
b02a913b 69#include "operhash.h"
212380e3 70
8bd5767b 71/* /quote set variables */
2af8c7ff 72struct SetOptions GlobalSetOptions;
8bd5767b
JT
73
74/* configuration set from ircd.conf */
75struct config_file_entry ConfigFileEntry;
76/* server info set from ircd.conf */
77struct server_info ServerInfo;
78/* admin info set from ircd.conf */
1aad9782
VY
79struct admin_info AdminInfo;
80
8bd5767b 81struct Counter Count;
47adde3d
VY
82struct ServerStatistics ServerStats;
83
1aad9782 84int maxconnections;
8bd5767b 85struct Client me; /* That's me */
1aad9782
VY
86struct LocalUser meLocalUser; /* That's also part of me */
87
3d3d1a95 88rb_dlink_list global_client_list;
8bd5767b 89
3d3d1a95 90/* unknown/client pointer lists */
8bd5767b 91rb_dlink_list unknown_list; /* unknown clients ON this server only */
3d3d1a95 92rb_dlink_list lclient_list; /* local clients only ON this server */
8bd5767b
JT
93rb_dlink_list serv_list; /* local servers to this server ONLY */
94rb_dlink_list global_serv_list; /* global servers on the network */
95rb_dlink_list local_oper_list; /* our opers, duplicated in lclient_list */
b5b84cad
VY
96rb_dlink_list oper_list; /* network opers */
97
8bd5767b 98const char *logFileName = LPATH;
b5b84cad
VY
99const char *pidFileName = PPATH;
100
1aad9782 101char **myargv;
1b916de5
EM
102bool dorehash = false;
103bool dorehashbans = false;
104bool doremotd = false;
f66f0baa 105bool kline_queued = false;
503727d1
EM
106bool server_state_foreground = false;
107bool opers_see_all_users = false;
bfc44622
AC
108bool ircd_ssl_ok = false;
109bool ircd_zlib_ok = true;
8bd5767b
JT
110
111int testing_conf = 0;
cd27d99c 112time_t startup_time;
8bd5767b 113
346fba92 114int default_server_capabs;
8bd5767b 115
cd27d99c
VY
116int splitmode;
117int splitchecking;
118int split_users;
119int split_servers;
120int eob_count;
c6d72037 121
fd5af3d0
VY
122void
123ircd_shutdown(const char *reason)
124{
125 struct Client *target_p;
126 rb_dlink_node *ptr;
127
128 RB_DLINK_FOREACH(ptr, lclient_list.head)
129 {
130 target_p = ptr->data;
131
132 sendto_one(target_p, ":%s NOTICE %s :Server Terminating. %s",
133 me.name, target_p->name, reason);
134 }
135
136 RB_DLINK_FOREACH(ptr, serv_list.head)
137 {
138 target_p = ptr->data;
139
140 sendto_one(target_p, ":%s ERROR :Terminated by %s",
141 me.name, reason);
142 }
143
144 ilog(L_MAIN, "Server Terminating. %s", reason);
ea82a3ca 145 close_logfiles();
fd5af3d0
VY
146
147 unlink(pidFileName);
148 exit(0);
149}
150
212380e3
AC
151/*
152 * print_startup - print startup information
153 */
154static void
155print_startup(int pid)
156{
b45b2dae
JT
157 int fd;
158
159 close(1);
160 fd = open("/dev/null", O_RDWR);
161 if (fd == -1) {
162 perror("open /dev/null");
163 exit(EXIT_FAILURE);
164 }
165 if (fd == 0)
166 fd = dup(fd);
167 if (fd != 1)
168 abort();
169
212380e3
AC
170 inotice("now running in %s mode from %s as pid %d ...",
171 !server_state_foreground ? "background" : "foreground",
172 ConfigFileEntry.dpath, pid);
173
174 /* let the parent process know the initialization was successful
175 * -- jilles */
176 if (!server_state_foreground)
c084fcaf
EM
177 {
178 if(write(0, ".", 1) < 1)
179 /* The circumstances in which this could fail are pretty implausible.
180 * However, this shuts GCC up about warning the result of write is unused,
181 * and is "standards compliant" behaviour.
182 * --Elizabeth
183 */
184 abort();
185 }
b45b2dae
JT
186 if (dup2(1, 0) == -1)
187 abort();
188 if (dup2(1, 2) == -1)
189 abort();
212380e3
AC
190}
191
212380e3
AC
192/*
193 * init_sys
194 *
195 * inputs - boot_daemon flag
196 * output - none
197 * side effects - if boot_daemon flag is not set, don't daemonize
198 */
199static void
200init_sys(void)
201{
8bd5767b
JT
202#if defined(RLIMIT_NOFILE) && defined(HAVE_SYS_RESOURCE_H)
203 struct rlimit limit;
204
205 if(!getrlimit(RLIMIT_NOFILE, &limit))
206 {
207 maxconnections = limit.rlim_cur;
208 if(maxconnections <= MAX_BUFFER)
209 {
210 fprintf(stderr, "ERROR: Shell FD limits are too low.\n");
ec86417c 211 fprintf(stderr, "ERROR: charybdis reserves %d FDs, shell limits must be above this\n", MAX_BUFFER);
8bd5767b
JT
212 exit(EXIT_FAILURE);
213 }
214 return;
215 }
216#endif /* RLIMIT_FD_MAX */
101db4c4 217 maxconnections = MAXCONNECTIONS;
212380e3
AC
218}
219
220static int
221make_daemon(void)
222{
223 int pid;
224 int pip[2];
225 char c;
226
227 if (pipe(pip) < 0)
228 {
229 perror("pipe");
230 exit(EXIT_FAILURE);
231 }
232 dup2(pip[1], 0);
233 close(pip[1]);
234 if((pid = fork()) < 0)
235 {
236 perror("fork");
237 exit(EXIT_FAILURE);
238 }
239 else if(pid > 0)
240 {
241 close(0);
242 /* Wait for initialization to finish, successfully or
243 * unsuccessfully. Until this point the child may still
244 * write to stdout/stderr.
245 * -- jilles */
246 if (read(pip[0], &c, 1) > 0)
247 exit(EXIT_SUCCESS);
248 else
249 exit(EXIT_FAILURE);
250 }
251
252 close(pip[0]);
253 setsid();
254/* fclose(stdin);
255 fclose(stdout);
256 fclose(stderr); */
257
258 return 0;
259}
260
261static int printVersion = 0;
262
263struct lgetopt myopts[] = {
212380e3
AC
264 {"configfile", &ConfigFileEntry.configfile,
265 STRING, "File to use for ircd.conf"},
212380e3
AC
266 {"logfile", &logFileName,
267 STRING, "File to use for ircd.log"},
268 {"pidfile", &pidFileName,
269 STRING, "File to use for process ID"},
270 {"foreground", &server_state_foreground,
271 YESNO, "Run in foreground (don't detach)"},
272 {"version", &printVersion,
273 YESNO, "Print version and exit"},
274 {"conftest", &testing_conf,
275 YESNO, "Test the configuration files and exit"},
276 {"help", NULL, USAGE, "Print this text"},
277 {NULL, NULL, STRING, NULL},
278};
279
212380e3
AC
280static void
281check_rehash(void *unused)
282{
283 /*
284 * Check to see whether we have to rehash the configuration ..
285 */
286 if(dorehash)
287 {
288 rehash(1);
1b916de5 289 dorehash = false;
212380e3
AC
290 }
291
292 if(dorehashbans)
293 {
294 rehash_bans(1);
1b916de5 295 dorehashbans = false;
212380e3
AC
296 }
297
298 if(doremotd)
299 {
300 sendto_realops_snomask(SNO_GENERAL, L_ALL,
301 "Got signal SIGUSR1, reloading ircd motd file");
041d54ff 302 cache_user_motd();
1b916de5 303 doremotd = false;
212380e3
AC
304 }
305}
306
212380e3
AC
307/*
308 * initalialize_global_set_options
309 *
310 * inputs - none
311 * output - none
55abcbb2 312 * side effects - This sets all global set options needed
212380e3
AC
313 */
314static void
315initialize_global_set_options(void)
316{
317 memset(&GlobalSetOptions, 0, sizeof(GlobalSetOptions));
318 /* memset( &ConfigFileEntry, 0, sizeof(ConfigFileEntry)); */
319
8bd5767b
JT
320 GlobalSetOptions.maxclients = ServerInfo.default_max_clients;
321
322 if(GlobalSetOptions.maxclients > (maxconnections - MAX_BUFFER) || (GlobalSetOptions.maxclients <= 0))
101db4c4
VY
323 GlobalSetOptions.maxclients = maxconnections - MAX_BUFFER;
324
212380e3
AC
325 GlobalSetOptions.autoconn = 1;
326
327 GlobalSetOptions.spam_time = MIN_JOIN_LEAVE_TIME;
328 GlobalSetOptions.spam_num = MAX_JOIN_LEAVE_COUNT;
329
7f3382fe 330 GlobalSetOptions.floodcount = ConfigFileEntry.default_floodcount;
212380e3
AC
331
332 split_servers = ConfigChannel.default_split_server_count;
333 split_users = ConfigChannel.default_split_user_count;
334
335 if(split_users && split_servers
336 && (ConfigChannel.no_create_on_split || ConfigChannel.no_join_on_split))
337 {
338 splitmode = 1;
339 splitchecking = 1;
340 }
341
7f3382fe 342 GlobalSetOptions.ident_timeout = ConfigFileEntry.default_ident_timeout;
212380e3 343
f427c8b0 344 rb_strlcpy(GlobalSetOptions.operstring,
212380e3
AC
345 ConfigFileEntry.default_operstring,
346 sizeof(GlobalSetOptions.operstring));
f427c8b0 347 rb_strlcpy(GlobalSetOptions.adminstring,
212380e3
AC
348 ConfigFileEntry.default_adminstring,
349 sizeof(GlobalSetOptions.adminstring));
350
351 /* memset( &ConfigChannel, 0, sizeof(ConfigChannel)); */
352
353 /* End of global set options */
354
355}
356
357/*
358 * initialize_server_capabs
359 *
360 * inputs - none
361 * output - none
362 */
363static void
364initialize_server_capabs(void)
365{
366 default_server_capabs &= ~CAP_ZIP;
367}
368
369
370/*
371 * write_pidfile
372 *
373 * inputs - filename+path of pid file
374 * output - none
375 * side effects - write the pid of the ircd to filename
376 */
377static void
378write_pidfile(const char *filename)
379{
380 FILE *fb;
381 char buff[32];
382 if((fb = fopen(filename, "w")))
383 {
384 unsigned int pid = (unsigned int) getpid();
385
5203cba5 386 snprintf(buff, sizeof(buff), "%u\n", pid);
212380e3
AC
387 if((fputs(buff, fb) == -1))
388 {
389 ilog(L_MAIN, "Error writing %u to pid file %s (%s)",
390 pid, filename, strerror(errno));
391 }
392 fclose(fb);
393 return;
394 }
395 else
396 {
397 ilog(L_MAIN, "Error opening pid file %s", filename);
398 }
399}
400
401/*
402 * check_pidfile
403 *
404 * inputs - filename+path of pid file
405 * output - none
406 * side effects - reads pid from pidfile and checks if ircd is in process
407 * list. if it is, gracefully exits
408 * -kre
409 */
410static void
411check_pidfile(const char *filename)
412{
413 FILE *fb;
414 char buff[32];
415 pid_t pidfromfile;
416
417 /* Don't do logging here, since we don't have log() initialised */
418 if((fb = fopen(filename, "r")))
419 {
420 if(fgets(buff, 20, fb) != NULL)
421 {
422 pidfromfile = atoi(buff);
423 if(!kill(pidfromfile, 0))
424 {
425 printf("ircd: daemon is already running\n");
426 exit(-1);
427 }
428 }
429 fclose(fb);
430 }
431}
432
433/*
434 * setup_corefile
435 *
436 * inputs - nothing
437 * output - nothing
438 * side effects - setups corefile to system limits.
439 * -kre
440 */
441static void
442setup_corefile(void)
443{
444#ifdef HAVE_SYS_RESOURCE_H
445 struct rlimit rlim; /* resource limits */
446
447 /* Set corefilesize to maximum */
448 if(!getrlimit(RLIMIT_CORE, &rlim))
449 {
450 rlim.rlim_cur = rlim.rlim_max;
451 setrlimit(RLIMIT_CORE, &rlim);
452 }
453#endif
454}
455
6fce54ff
VY
456static void
457ircd_log_cb(const char *str)
458{
fe037171 459 ilog(L_MAIN, "librb reports: %s", str);
6fce54ff
VY
460}
461
462static void
463ircd_restart_cb(const char *str)
464{
fe037171 465 inotice("librb has called the restart callback: %s", str);
6fce54ff
VY
466 restart(str);
467}
468
469/*
470 * Why EXIT_FAILURE here?
471 * Because if ircd_die_cb() is called it's because of a fatal
472 * error inside libcharybdis, and we don't know how to handle the
473 * exception, so it is logical to return a FAILURE exit code here.
474 * --nenolod
475 */
476static void
477ircd_die_cb(const char *str)
478{
479 if(str != NULL)
480 {
481 /* Try to get the message out to currently logged in operators. */
fe037171
EM
482 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "librb has called the die callback..aborting: %s", str);
483 inotice("librb has called the die callback..aborting: %s", str);
6fce54ff 484 }
6643434b 485 else
fe037171 486 inotice("librb has called the die callback..aborting");
6fce54ff
VY
487
488 unlink(pidFileName);
489 exit(EXIT_FAILURE);
490}
491
fa832850
AC
492struct ev_entry *check_splitmode_ev = NULL;
493
d80645d0
VY
494static int
495seed_with_urandom(void)
496{
497 unsigned int seed;
498 int fd;
499
500 fd = open("/dev/urandom", O_RDONLY);
501 if(fd >= 0)
502 {
503 if(read(fd, &seed, sizeof(seed)) == sizeof(seed))
504 {
505 close(fd);
506 srand(seed);
507 return 1;
508 }
5457b102 509 close(fd);
d80645d0
VY
510 }
511 return 0;
512}
513
514static void
515seed_with_clock(void)
516{
55abcbb2 517 const struct timeval *tv;
d80645d0
VY
518 rb_set_time();
519 tv = rb_current_time_tv();
520 srand(tv->tv_sec ^ (tv->tv_usec | (getpid() << 20)));
521}
522
523static void
524seed_random(void *unused)
525{
526 unsigned int seed;
527 if(rb_get_random(&seed, sizeof(seed)) == -1)
528 {
529 if(!seed_with_urandom())
530 seed_with_clock();
531 return;
532 }
533 srand(seed);
534}
535
212380e3
AC
536/*
537 * main
538 *
539 * Initializes the IRCd.
540 *
541 * Inputs - number of commandline args, args themselves
542 * Outputs - none
543 * Side Effects - this is where the ircd gets going right now
544 */
545int
bc38c72c 546charybdis_main(int argc, char *argv[])
212380e3
AC
547{
548 int fd;
549
550 /* Check to see if the user is running us as root, which is a nono */
551 if(geteuid() == 0)
552 {
553 fprintf(stderr, "Don't run ircd as root!!!\n");
554 return -1;
555 }
556
adc7be98
VY
557 init_sys();
558
befa24c8
JT
559 ConfigFileEntry.dpath = DPATH;
560 ConfigFileEntry.configfile = CPATH; /* Server configuration file */
befa24c8 561 ConfigFileEntry.connect_timeout = 30; /* Default to 30 */
346fba92 562
befa24c8 563 umask(077); /* better safe than sorry --SRB */
adc7be98
VY
564
565 myargv = argv;
566 parseargs(&argc, &argv, myopts);
567
568 if(chdir(ConfigFileEntry.dpath))
569 {
570 fprintf(stderr, "Unable to chdir to %s: %s\n", ConfigFileEntry.dpath, strerror(errno));
571 exit(EXIT_FAILURE);
572 }
573
3d3d1a95
VY
574 rb_set_time();
575
212380e3
AC
576 /*
577 * Setup corefile size immediately after boot -kre
578 */
579 setup_corefile();
580
b02a913b
AC
581 /* initialise operhash fairly early. */
582 init_operhash();
583
212380e3
AC
584 memset(&me, 0, sizeof(me));
585 memset(&meLocalUser, 0, sizeof(meLocalUser));
586 me.localClient = &meLocalUser;
587
588 /* Make sure all lists are zeroed */
589 memset(&unknown_list, 0, sizeof(unknown_list));
590 memset(&lclient_list, 0, sizeof(lclient_list));
591 memset(&serv_list, 0, sizeof(serv_list));
592 memset(&global_serv_list, 0, sizeof(global_serv_list));
593 memset(&local_oper_list, 0, sizeof(local_oper_list));
594 memset(&oper_list, 0, sizeof(oper_list));
595
330fc5c1 596 rb_dlinkAddTail(&me, &me.node, &global_client_list);
212380e3 597
2af8c7ff
VY
598 memset(&Count, 0, sizeof(Count));
599 memset(&ServerInfo, 0, sizeof(ServerInfo));
600 memset(&AdminInfo, 0, sizeof(AdminInfo));
601 memset(&ServerStats, 0, sizeof(struct ServerStatistics));
212380e3 602
212380e3
AC
603 if(printVersion)
604 {
b3803848 605 printf("ircd: version %s(%s)\n", ircd_version, serno);
8bd1c8a1
AC
606#ifdef CUSTOM_BRANDING
607 printf("ircd: based on %s-%s\n", PACKAGE_NAME, PACKAGE_VERSION);
608#endif
d2b6b9f3 609 printf("ircd: %s\n", rb_lib_version());
212380e3
AC
610 exit(EXIT_SUCCESS);
611 }
612
212380e3
AC
613 setup_signals();
614
212380e3 615 if (testing_conf)
503727d1 616 server_state_foreground = true;
212380e3
AC
617
618 /* Make sure fd 0, 1 and 2 are in use -- jilles */
619 do
620 {
621 fd = open("/dev/null", O_RDWR);
622 } while (fd < 2 && fd != -1);
623 if (fd > 2)
624 close(fd);
625 else if (fd == -1)
626 exit(1);
627
628 /* Check if there is pidfile and daemon already running */
629 if(!testing_conf)
630 {
631 check_pidfile(pidFileName);
632
633 if(!server_state_foreground)
634 make_daemon();
635 inotice("starting %s ...", ircd_version);
31c86ea8 636 inotice("%s", rb_lib_version());
212380e3
AC
637 }
638
639 /* Init the event subsystem */
0edb29fa 640 rb_lib_init(ircd_log_cb, ircd_restart_cb, ircd_die_cb, !server_state_foreground, maxconnections, DNODE_HEAP_SIZE, FD_HEAP_SIZE);
150f35f7 641 rb_linebuf_init(LINEBUF_HEAP_SIZE);
212380e3 642
e861902f 643 rb_init_prng(NULL, RB_PRNG_DEFAULT);
37cd159e 644
e1db84d8
VY
645 seed_random(NULL);
646
346fba92
AC
647 init_builtin_capabs();
648 default_server_capabs = CAP_MASK;
649
212380e3 650 init_main_logfile();
212380e3
AC
651 newconf_init();
652 init_s_conf();
653 init_s_newconf();
654 init_hash();
655 clear_scache_hash_table(); /* server cache name table */
656 init_host_hash();
657 clear_hash_parse();
658 init_client();
212380e3
AC
659 init_hook();
660 init_channels();
661 initclass();
b47f8a4f 662 whowas_init();
212380e3
AC
663 init_reject();
664 init_cache();
665 init_monitor();
030cdce7 666
19716b9f 667 construct_cflags_strings();
030cdce7 668
212380e3 669 load_all_modules(1);
212380e3 670 load_core_modules(1);
2a19fc3f 671
212380e3 672 init_auth(); /* Initialise the auth code */
6d063f05 673 init_authd(); /* Start up authd. */
068c6c4a 674 init_dns(); /* Start up DNS query system */
8a26cd19 675
39a68b53 676 privilegeset_set_new("default", "", 0);
212380e3
AC
677
678 if (testing_conf)
679 fprintf(stderr, "\nBeginning config test\n");
ea111ea5 680 read_conf_files(true); /* cold start init conf files */
212380e3 681
55abcbb2
KB
682 mod_add_path(MODULE_DIR);
683 mod_add_path(MODULE_DIR "/autoload");
212380e3 684
b583faf9
AC
685 init_isupport();
686
6eebc373 687 init_bandb();
c6d72037
VY
688 init_ssld();
689
80c9ac51
AC
690 rehash_bans(0);
691
212380e3
AC
692 initialize_server_capabs(); /* Set up default_server_capabs */
693 initialize_global_set_options();
694
695 if(ServerInfo.name == NULL)
696 {
697 ierror("no server name specified in serverinfo block.");
698 return -1;
699 }
f427c8b0 700 rb_strlcpy(me.name, ServerInfo.name, sizeof(me.name));
212380e3
AC
701
702 if(ServerInfo.sid[0] == '\0')
703 {
704 ierror("no server sid specified in serverinfo block.");
705 return -2;
706 }
707 strcpy(me.id, ServerInfo.sid);
708 init_uid();
709
710 /* serverinfo{} description must exist. If not, error out. */
711 if(ServerInfo.description == NULL)
712 {
713 ierror("no server description specified in serverinfo block.");
714 return -3;
715 }
f427c8b0 716 rb_strlcpy(me.info, ServerInfo.description, sizeof(me.info));
212380e3 717
8bd5767b
JT
718 if(ServerInfo.ssl_cert != NULL && ServerInfo.ssl_private_key != NULL)
719 {
720 /* just do the rb_setup_ssl_server to validate the config */
c1725bda 721 if(!rb_setup_ssl_server(ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params, ServerInfo.ssl_cipher_list))
8bd5767b
JT
722 {
723 ilog(L_MAIN, "WARNING: Unable to setup SSL.");
bfc44622 724 ircd_ssl_ok = false;
8bd5767b
JT
725 }
726 else
bfc44622 727 ircd_ssl_ok = true;
c6d72037
VY
728 }
729
212380e3
AC
730 if (testing_conf)
731 {
732 fprintf(stderr, "\nConfig testing complete.\n");
733 fflush(stderr);
734 return 0; /* Why? We want the launcher to exit out. */
735 }
736
737 me.from = &me;
738 me.servptr = &me;
739 SetMe(&me);
740 make_server(&me);
e3354945 741 startup_time = rb_current_time();
212380e3
AC
742 add_to_client_hash(me.name, &me);
743 add_to_id_hash(me.id, &me);
994544c2 744 me.serv->nameinfo = scache_connect(me.name, me.info, 0);
212380e3 745
330fc5c1 746 rb_dlinkAddAlloc(&me, &global_serv_list);
212380e3
AC
747
748 construct_umodebuf();
749
750 check_class();
751 write_pidfile(pidFileName);
752 load_help();
753 open_logfiles();
754
755 ilog(L_MAIN, "Server Ready");
756
212380e3
AC
757 /* We want try_connections to be called as soon as possible now! -- adrian */
758 /* No, 'cause after a restart it would cause all sorts of nick collides */
759 /* um. by waiting even longer, that just means we have even *more*
760 * nick collisions. what a stupid idea. set an event for the IO loop --fl
761 */
12aea5fe 762 rb_event_addish("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME);
36645728
VY
763 rb_event_addonce("try_connections_startup", try_connections, NULL, 2);
764 rb_event_add("check_rehash", check_rehash, NULL, 3);
d80645d0 765 rb_event_addish("reseed_srand", seed_random, NULL, 300); /* reseed every 10 minutes */
212380e3 766
212380e3 767 if(splitmode)
36645728 768 check_splitmode_ev = rb_event_add("check_splitmode", check_splitmode, NULL, 5);
212380e3 769
212380e3
AC
770 print_startup(getpid());
771
39944e1f 772 rb_lib_loop(0);
212380e3
AC
773
774 return 0;
775}