]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/inspircd.cpp
Convert remaining InspIRCd::Log() calls to new logging system
[user/henk/code/inspircd.git] / src / inspircd.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *          the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 /* $Install: src/inspircd $(BINPATH) */
15
16 #include "inspircd.h"
17 #include <signal.h>
18
19 #ifndef WIN32
20         #include <dirent.h>
21         #include <unistd.h>
22         #include <sys/resource.h>
23         #include <dlfcn.h>
24         #include <getopt.h>
25
26         /* Some systems don't define RUSAGE_SELF. This should fix them. */
27         #ifndef RUSAGE_SELF
28                 #define RUSAGE_SELF 0
29         #endif
30 #endif
31
32 #include <fstream>
33 #include "xline.h"
34 #include "bancache.h"
35 #include "socketengine.h"
36 #include "inspircd_se_config.h"
37 #include "socket.h"
38 #include "command_parse.h"
39 #include "exitcodes.h"
40 #include "caller.h"
41 #include "testsuite.h"
42
43 using irc::sockets::insp_ntoa;
44 using irc::sockets::insp_inaddr;
45 using irc::sockets::insp_sockaddr;
46
47 InspIRCd* SI = NULL;
48 int* mysig = NULL;
49
50
51 /* Moved from exitcodes.h -- due to duplicate symbols -- Burlex
52  * XXX this is a bit ugly. -- w00t
53  */
54 const char* ExitCodes[] =
55 {
56                 "No error", /* 0 */
57                 "DIE command", /* 1 */
58                 "execv() failed", /* 2 */
59                 "Internal error", /* 3 */
60                 "Config file error", /* 4 */
61                 "Logfile error", /* 5 */
62                 "POSIX fork failed", /* 6 */
63                 "Bad commandline parameters", /* 7 */
64                 "No ports could be bound", /* 8 */
65                 "Can't write PID file", /* 9 */
66                 "SocketEngine could not initialize", /* 10 */
67                 "Refusing to start up as root", /* 11 */
68                 "Found a <die> tag!", /* 12 */
69                 "Couldn't load module on startup", /* 13 */
70                 "Could not create windows forked process", /* 14 */
71                 "Received SIGTERM", /* 15 */
72 };
73
74 void InspIRCd::Cleanup()
75 {
76         if (Config)
77         {
78                 for (unsigned int i = 0; i < Config->ports.size(); i++)
79                 {
80                         /* This calls the constructor and closes the listening socket */
81                         delete Config->ports[i];
82                 }
83
84                 Config->ports.clear();
85         }
86
87         /* Close all client sockets, or the new process inherits them */
88         for (std::vector<User*>::const_iterator i = this->Users->local_users.begin(); i != this->Users->local_users.end(); i++)
89         {
90                 (*i)->SetWriteError("Server shutdown");
91                 (*i)->CloseSocket();
92         }
93
94         /* We do this more than once, so that any service providers get a
95          * chance to be unhooked by the modules using them, but then get
96          * a chance to be removed themsleves.
97          *
98          * XXX there may be a better way to do this with 1.2
99          */
100         for (int tries = 0; tries < 3; tries++)
101         {
102                 std::vector<std::string> module_names = Modules->GetAllModuleNames(0);
103                 for (std::vector<std::string>::iterator k = module_names.begin(); k != module_names.end(); ++k)
104                 {
105                         /* Unload all modules, so they get a chance to clean up their listeners */
106                         this->Modules->Unload(k->c_str());
107                 }
108         }
109
110         /* Close logging */
111         this->Logs->CloseLogs();
112
113         /* Cleanup Server Names */
114         for(servernamelist::iterator itr = servernames.begin(); itr != servernames.end(); ++itr)
115                 delete (*itr);
116
117
118 }
119
120 void InspIRCd::Restart(const std::string &reason)
121 {
122         /* SendError flushes each client's queue,
123          * regardless of writeability state
124          */
125         this->SendError(reason);
126
127         this->Cleanup();
128
129         /* Figure out our filename (if theyve renamed it, we're boned) */
130         std::string me;
131
132 #ifdef WINDOWS
133         char module[MAX_PATH];
134         if (GetModuleFileName(NULL, module, MAX_PATH))
135                 me = module;
136 #else
137         me = Config->MyDir + "/inspircd";
138 #endif
139
140         if (execv(me.c_str(), Config->argv) == -1)
141         {
142                 /* Will raise a SIGABRT if not trapped */
143                 throw CoreException(std::string("Failed to execv()! error: ") + strerror(errno));
144         }
145 }
146
147 void InspIRCd::ResetMaxBans()
148 {
149         for (chan_hash::const_iterator i = chanlist->begin(); i != chanlist->end(); i++)
150                 i->second->ResetMaxBans();
151 }
152
153 /** Because hash_map doesnt free its buckets when we delete items (this is a 'feature')
154  * we must occasionally rehash the hash (yes really).
155  * We do this by copying the entries from the old hash to a new hash, causing all
156  * empty buckets to be weeded out of the hash. We dont do this on a timer, as its
157  * very expensive, so instead we do it when the user types /REHASH and expects a
158  * short delay anyway.
159  */
160 void InspIRCd::RehashUsersAndChans()
161 {
162         user_hash* old_users = this->Users->clientlist;
163         user_hash* old_uuid  = this->Users->uuidlist;
164         chan_hash* old_chans = this->chanlist;
165
166         this->Users->clientlist = new user_hash();
167         this->Users->uuidlist = new user_hash();
168         this->chanlist = new chan_hash();
169
170         for (user_hash::const_iterator n = old_users->begin(); n != old_users->end(); n++)
171                 this->Users->clientlist->insert(*n);
172
173         delete old_users;
174
175         for (user_hash::const_iterator n = old_uuid->begin(); n != old_uuid->end(); n++)
176                 this->Users->uuidlist->insert(*n);
177
178         delete old_uuid;
179
180         for (chan_hash::const_iterator n = old_chans->begin(); n != old_chans->end(); n++)
181                 this->chanlist->insert(*n);
182
183         delete old_chans;
184 }
185
186 void InspIRCd::SetSignals()
187 {
188 #ifndef WIN32
189         signal(SIGALRM, SIG_IGN);
190         signal(SIGHUP, InspIRCd::SetSignal);
191         signal(SIGPIPE, SIG_IGN);
192         signal(SIGCHLD, SIG_IGN);
193 #endif
194         signal(SIGTERM, InspIRCd::SetSignal);
195 }
196
197 void InspIRCd::QuickExit(int status)
198 {
199         exit(0);
200 }
201
202 bool InspIRCd::DaemonSeed()
203 {
204 #ifdef WINDOWS
205         printf_c("InspIRCd Process ID: \033[1;32m%lu\033[0m\n", GetCurrentProcessId());
206         return true;
207 #else
208         signal(SIGTERM, InspIRCd::QuickExit);
209
210         int childpid;
211         if ((childpid = fork ()) < 0)
212                 return false;
213         else if (childpid > 0)
214         {
215                 /* We wait here for the child process to kill us,
216                  * so that the shell prompt doesnt come back over
217                  * the output.
218                  * Sending a kill with a signal of 0 just checks
219                  * if the child pid is still around. If theyre not,
220                  * they threw an error and we should give up.
221                  */
222                 while (kill(childpid, 0) != -1)
223                         sleep(1);
224                 exit(0);
225         }
226         setsid ();
227         umask (007);
228         printf("InspIRCd Process ID: \033[1;32m%lu\033[0m\n",(unsigned long)getpid());
229
230         signal(SIGTERM, InspIRCd::SetSignal);
231
232         rlimit rl;
233         if (getrlimit(RLIMIT_CORE, &rl) == -1)
234         {
235                 this->Logs->Log("STARTUP",DEFAULT,"Failed to getrlimit()!");
236                 return false;
237         }
238         else
239         {
240                 rl.rlim_cur = rl.rlim_max;
241                 if (setrlimit(RLIMIT_CORE, &rl) == -1)
242                         this->Logs->Log("STARTUP",DEFAULT,"setrlimit() failed, cannot increase coredump size.");
243         }
244
245         return true;
246 #endif
247 }
248
249 void InspIRCd::WritePID(const std::string &filename)
250 {
251         std::string fname = (filename.empty() ? "inspircd.pid" : filename);
252         if (*(fname.begin()) != '/')
253         {
254                 std::string::size_type pos;
255                 std::string confpath = this->ConfigFileName;
256                 if ((pos = confpath.rfind("/")) != std::string::npos)
257                 {
258                         /* Leaves us with just the path */
259                         fname = confpath.substr(0, pos) + std::string("/") + fname;
260                 }
261         }
262         std::ofstream outfile(fname.c_str());
263         if (outfile.is_open())
264         {
265                 outfile << getpid();
266                 outfile.close();
267         }
268         else
269         {
270                 printf("Failed to write PID-file '%s', exiting.\n",fname.c_str());
271                 this->Logs->Log("STARTUP",DEFAULT,"Failed to write PID-file '%s', exiting.",fname.c_str());
272                 Exit(EXIT_STATUS_PID);
273         }
274 }
275
276 InspIRCd::InspIRCd(int argc, char** argv)
277         : GlobalCulls(this),
278
279          /* Functor initialisation. Note that the ordering here is very important. */
280          HandleProcessUser(this),
281          HandleIsNick(this),
282          HandleIsIdent(this),
283          HandleFindDescriptor(this),
284          HandleFloodQuitUser(this),
285
286          /* Functor pointer initialisation. Must match the order of the list above */
287          ProcessUser(&HandleProcessUser),
288          IsNick(&HandleIsNick),
289          IsIdent(&HandleIsIdent),
290          FindDescriptor(&HandleFindDescriptor),
291          FloodQuitUser(&HandleFloodQuitUser)
292
293 {
294
295         int found_ports = 0;
296         FailedPortList pl;
297         int do_version = 0, do_nofork = 0, do_debug = 0,
298             do_nolog = 0, do_root = 0, do_testsuite = 0;    /* flag variables */
299         char c = 0;
300
301         memset(&server, 0, sizeof(server));
302         memset(&client, 0, sizeof(client));
303
304         // This must be created first, so other parts of Insp can use it while starting up
305         this->Logs = new LogManager(this);
306
307         SocketEngineFactory* SEF = new SocketEngineFactory();
308         SE = SEF->Create(this);
309         delete SEF;
310
311         this->s_signal = 0;
312         
313         // Create base manager classes early, so nothing breaks
314         this->Users = new UserManager(this);
315         
316         this->Users->unregistered_count = 0;
317
318         this->Users->clientlist = new user_hash();
319         this->Users->uuidlist = new user_hash();
320         this->chanlist = new chan_hash();
321
322         this->Res = NULL;
323
324         this->Config = new ServerConfig(this);
325         this->SNO = new SnomaskManager(this);
326         this->BanCache = new BanCacheManager(this);
327         this->Modules = new ModuleManager(this);
328         this->stats = new serverstats();
329         this->Timers = new TimerManager(this);
330         this->Parser = new CommandParser(this);
331         this->XLines = new XLineManager(this);
332
333         this->Config->argv = argv;
334         this->Config->argc = argc;
335
336         if (chdir(Config->GetFullProgDir().c_str()))
337         {
338                 printf("Unable to change to my directory: %s\nAborted.", strerror(errno));
339                 exit(0);
340         }
341
342         this->Config->opertypes.clear();
343         this->Config->operclass.clear();
344
345         this->TIME = this->OLDTIME = this->startup_time = time(NULL);
346         srand(this->TIME);
347
348         *this->LogFileName = 0;
349         strlcpy(this->ConfigFileName, CONFIG_FILE, MAXBUF);
350
351         struct option longopts[] =
352         {
353                 { "nofork",     no_argument,            &do_nofork,     1       },
354                 { "logfile",    required_argument,      NULL,           'f'     },
355                 { "config",     required_argument,      NULL,           'c'     },
356                 { "debug",      no_argument,            &do_debug,      1       },
357                 { "nolog",      no_argument,            &do_nolog,      1       },
358                 { "runasroot",  no_argument,            &do_root,       1       },
359                 { "version",    no_argument,            &do_version,    1       },
360                 { "testsuite",  no_argument,            &do_testsuite,  1       },
361                 { 0, 0, 0, 0 }
362         };
363
364         while ((c = getopt_long_only(argc, argv, ":f:", longopts, NULL)) != -1)
365         {
366                 switch (c)
367                 {
368                         case 'f':
369                                 /* Log filename was set */
370                                 strlcpy(LogFileName, optarg, MAXBUF);
371                         break;
372                         case 'c':
373                                 /* Config filename was set */
374                                 strlcpy(ConfigFileName, optarg, MAXBUF);
375                         break;
376                         case 0:
377                                 /* getopt_long_only() set an int variable, just keep going */
378                         break;
379                         default:
380                                 /* Unknown parameter! DANGER, INTRUDER.... err.... yeah. */
381                                 printf("Usage: %s [--nofork] [--nolog] [--debug] [--logfile <filename>]\n\
382                                                   [--runasroot] [--version] [--config <config>] [--testsuite]\n", argv[0]);
383                                 Exit(EXIT_STATUS_ARGV);
384                         break;
385                 }
386         }
387
388         if (do_testsuite)
389                 do_nofork = do_debug = true;
390
391         if (do_version)
392         {
393                 printf("\n%s r%s\n", VERSION, REVISION);
394                 Exit(EXIT_STATUS_NOERROR);
395         }
396
397 #ifdef WIN32
398
399         // Handle forking
400         if(!do_nofork)
401         {
402                 DWORD ExitCode = WindowsForkStart(this);
403                 if(ExitCode)
404                         exit(ExitCode);
405         }
406
407         // Set up winsock
408         WSADATA wsadata;
409         WSAStartup(MAKEWORD(2,0), &wsadata);
410         ChangeWindowsSpecificPointers(this);
411 #endif
412         strlcpy(Config->MyExecutable,argv[0],MAXBUF);
413
414         /* Set the finished argument values */
415         Config->nofork = do_nofork;
416         Config->forcedebug = do_debug;
417         Config->writelog = !do_nolog;
418         Config->TestSuite = do_testsuite;
419
420         if (!this->OpenLog(argv, argc))
421         {
422                 printf("ERROR: Could not open logfile %s: %s\n\n", Config->logpath.c_str(), strerror(errno));
423                 Exit(EXIT_STATUS_LOG);
424         }
425
426         if (!ServerConfig::FileExists(this->ConfigFileName))
427         {
428                 printf("ERROR: Cannot open config file: %s\nExiting...\n", this->ConfigFileName);
429                 this->Logs->Log("STARTUP",DEFAULT,"Unable to open config file %s", this->ConfigFileName);
430                 Exit(EXIT_STATUS_CONFIG);
431         }
432
433         printf_c("\033[1;32mInspire Internet Relay Chat Server, compiled %s at %s\n",__DATE__,__TIME__);
434         printf_c("(C) InspIRCd Development Team.\033[0m\n\n");
435         printf_c("Developers:\n");
436         printf_c("\t\033[1;32mBrain, FrostyCoolSlug, w00t, Om, Special\n");
437         printf_c("\t\033[1;32mpippijn, peavey, aquanight, fez\033[0m\n\n");
438         printf_c("Others:\t\t\t\033[1;32mSee /INFO Output\033[0m\n");
439
440         Config->ClearStack();
441
442         this->Modes = new ModeParser(this);
443
444         /* set up fake client (uid is incorrect at this point,
445          * until after config is read. we set up the user again
446          * at that point 
447          */
448         this->FakeClient = new User(this);
449         this->FakeClient->SetFd(FD_MAGIC_NUMBER);
450
451         if (!do_root)
452                 this->CheckRoot();
453         else
454         {
455                 printf("* WARNING * WARNING * WARNING * WARNING * WARNING * \n\n");
456                 printf("YOU ARE RUNNING INSPIRCD AS ROOT. THIS IS UNSUPPORTED\n");
457                 printf("AND IF YOU ARE HACKED, CRACKED, SPINDLED OR MUTILATED\n");
458                 printf("OR ANYTHING ELSE UNEXPECTED HAPPENS TO YOU OR YOUR\n");
459                 printf("SERVER, THEN IT IS YOUR OWN FAULT. IF YOU DID NOT MEAN\n");
460                 printf("TO START INSPIRCD AS ROOT, HIT CTRL+C NOW AND RESTART\n");
461                 printf("THE PROGRAM AS A NORMAL USER. YOU HAVE BEEN WARNED!\n");
462                 printf("\nInspIRCd starting in 20 seconds, ctrl+c to abort...\n");
463                 sleep(20);
464         }
465
466         this->SetSignals();
467
468         if (!Config->nofork)
469         {
470                 if (!this->DaemonSeed())
471                 {
472                         printf("ERROR: could not go into daemon mode. Shutting down.\n");
473                         Logs->Log("STARTUP", DEFAULT, "ERROR: could not go into daemon mode. Shutting down.");
474                         Exit(EXIT_STATUS_FORK);
475                 }
476         }
477
478         SE->RecoverFromFork();
479
480         /* Read config, pass 0. At the end if this pass,
481          * the Config->IncludeFiles is populated, we call
482          * Config->StartDownloads to initialize the downlaods of all
483          * these files.
484          */
485         Config->Read(true, NULL, 0);
486         Config->DoDownloads();
487         /* We have all the files we can get, initiate pass 1 */
488         Config->Read(true, NULL, 1);
489
490         this->AddServerName(Config->ServerName);
491
492         /*
493          * Initialise SID/UID.
494          * For an explanation as to exactly how this works, and why it works this way, see GetUID().
495          *   -- w00t
496          */
497         if (*Config->sid)
498         {
499         }
500         else
501         {
502                 // Generate one
503                 size_t sid = 0;
504
505                 for (const char* x = Config->ServerName; *x; ++x)
506                         sid = 5 * sid + *x;
507                 for (const char* y = Config->ServerDesc; *y; ++y)
508                         sid = 5 * sid + *y;
509                 sid = sid % 999;
510
511                 Config->sid[0] = (char)(sid / 100 + 48);
512                 Config->sid[1] = (char)(((sid / 10) % 10) + 48);
513                 Config->sid[2] = (char)(sid % 10 + 48);
514         }
515
516         this->InitialiseUID();
517
518         /* set up fake client again this time with the correct uid */
519         delete FakeClient;
520         this->FakeClient = new User(this);
521         this->FakeClient->SetFd(FD_MAGIC_NUMBER);
522
523         // Get XLine to do it's thing.
524         this->XLines->CheckELines();
525         this->XLines->ApplyLines();
526
527
528         CheckDie();
529         int bounditems = BindPorts(true, found_ports, pl);
530
531         printf("\n");
532
533         /*this->Modules->LoadAll();*/
534         
535         /* Just in case no modules were loaded - fix for bug #101 */
536         this->BuildISupport();
537         InitializeDisabledCommands(Config->DisabledCommands, this);
538
539         if ((Config->ports.size() == 0) && (found_ports > 0))
540         {
541                 printf("\nERROR: I couldn't bind any ports! Are you sure you didn't start InspIRCd twice?\n");
542                 Logs->Log("STARTUP", DEFAULT,"ERROR: I couldn't bind any ports! Something else is bound to those ports!");
543                 Exit(EXIT_STATUS_BIND);
544         }
545
546         if (Config->ports.size() != (unsigned int)found_ports)
547         {
548                 printf("\nWARNING: Not all your client ports could be bound --\nstarting anyway with %d of %d client ports bound.\n\n", bounditems, found_ports);
549                 printf("The following port(s) failed to bind:\n");
550                 int j = 1;
551                 for (FailedPortList::iterator i = pl.begin(); i != pl.end(); i++, j++)
552                 {
553                         printf("%d.\tIP: %s\tPort: %lu\n", j, i->first.empty() ? "<all>" : i->first.c_str(), (unsigned long)i->second);
554                 }
555         }
556 #ifndef WINDOWS
557         if (!Config->nofork)
558         {
559                 if (kill(getppid(), SIGTERM) == -1)
560                 {
561                         printf("Error killing parent process: %s\n",strerror(errno));
562                         Logs->Log("STARTUP", DEFAULT, "Error killing parent process: %s",strerror(errno));
563                 }
564         }
565
566         if (isatty(0) && isatty(1) && isatty(2))
567         {
568                 /* We didn't start from a TTY, we must have started from a background process -
569                  * e.g. we are restarting, or being launched by cron. Dont kill parent, and dont
570                  * close stdin/stdout
571                  */
572                 if (!do_nofork)
573                 {
574                         fclose(stdin);
575                         fclose(stderr);
576                         fclose(stdout);
577                 }
578                 else
579                 {
580                         Logs->Log("STARTUP", DEFAULT,"Keeping pseudo-tty open as we are running in the foreground.");
581                 }
582         }
583 #else
584         WindowsIPC = new IPC(this);
585         if(!Config->nofork)
586         {
587                 WindowsForkKillOwner(this);
588                 FreeConsole();
589         }
590 #endif
591
592         printf("\nInspIRCd is now running as '%s'[%s]\n", Config->ServerName,Config->GetSID().c_str());
593         Logs->Log("STARTUP", DEFAULT, "Startup complete as '%s'[%s]", Config->ServerName,Config->GetSID().c_str());
594
595         this->WritePID(Config->PID);
596 }
597
598 /* moved to a function, as UID generation can call this also */
599 void InspIRCd::InitialiseUID()
600 {
601         int i = 3;
602
603         current_uid[0] = Config->sid[0];
604         current_uid[1] = Config->sid[1];
605         current_uid[2] = Config->sid[2];
606
607         /* Initialise UID */
608         for(i = 3; i < UUID_LENGTH - 1; i++)
609                 current_uid[i] = 'A';
610
611         current_uid[UUID_LENGTH] = '\0';
612 }
613
614 int InspIRCd::Run()
615 {
616         /* See if we're supposed to be running the test suite rather than entering the mainloop */
617         if (Config->TestSuite)
618         {
619                 TestSuite* ts = new TestSuite(this);
620                 delete ts;
621                 Exit(0);
622         }
623
624         while (true)
625         {
626 #ifndef WIN32
627                 static rusage ru;
628 #else
629                 static time_t uptime;
630                 static struct tm * stime;
631                 static char window_title[100];
632 #endif
633
634                 /* time() seems to be a pretty expensive syscall, so avoid calling it too much.
635                  * Once per loop iteration is pleanty.
636                  */
637                 OLDTIME = TIME;
638                 TIME = time(NULL);
639
640                 /* Run background module timers every few seconds
641                  * (the docs say modules shouldnt rely on accurate
642                  * timing using this event, so we dont have to
643                  * time this exactly).
644                  */
645                 if (TIME != OLDTIME)
646                 {
647                         if (TIME < OLDTIME)
648                         {
649                                 SNO->WriteToSnoMask('A', "\002EH?!\002 -- Time is flowing BACKWARDS in this dimension! Clock drifted backwards %d secs.",abs(OLDTIME-TIME));
650                         }
651
652                         if ((TIME % 3600) == 0)
653                         {
654                                 this->RehashUsersAndChans();
655                                 FOREACH_MOD_I(this, I_OnGarbageCollect, OnGarbageCollect());
656                         }
657
658                         Timers->TickTimers(TIME);
659                         this->DoBackgroundUserStuff();
660
661                         if ((TIME % 5) == 0)
662                         {
663                                 FOREACH_MOD_I(this,I_OnBackgroundTimer,OnBackgroundTimer(TIME));
664                                 SNO->FlushSnotices();
665                         }
666 #ifndef WIN32
667                         /* Same change as in cmd_stats.cpp, use RUSAGE_SELF rather than '0' -- Om */
668                         if (!getrusage(RUSAGE_SELF, &ru))
669                         {
670                                 gettimeofday(&this->stats->LastSampled, NULL);
671                                 this->stats->LastCPU = ru.ru_utime;
672                         }
673 #else
674                         WindowsIPC->Check();    
675 #endif
676                 }
677
678                 /* Call the socket engine to wait on the active
679                  * file descriptors. The socket engine has everything's
680                  * descriptors in its list... dns, modules, users,
681                  * servers... so its nice and easy, just one call.
682                  * This will cause any read or write events to be
683                  * dispatched to their handlers.
684                  */
685                 this->SE->DispatchEvents();
686
687                 /* if any users were quit, take them out */
688                 this->GlobalCulls.Apply();
689
690                 /* If any inspsockets closed, remove them */
691                 this->BufferedSocketCull();
692
693                 if (this->s_signal)
694                 {
695                         this->SignalHandler(s_signal);
696                         this->s_signal = 0;
697                 }
698         }
699
700         return 0;
701 }
702
703 void InspIRCd::BufferedSocketCull()
704 {
705         for (std::map<BufferedSocket*,BufferedSocket*>::iterator x = SocketCull.begin(); x != SocketCull.end(); ++x)
706         {
707                 this->Logs->Log("MISC",DEBUG,"Cull socket");
708                 SE->DelFd(x->second);
709                 x->second->Close();
710                 delete x->second;
711         }
712         SocketCull.clear();
713 }
714
715 /**********************************************************************************/
716
717 /**
718  * An ircd in five lines! bwahahaha. ahahahahaha. ahahah *cough*.
719  */
720
721 int main(int argc, char ** argv)
722 {
723         SI = new InspIRCd(argc, argv);
724         mysig = &SI->s_signal;
725         SI->Run();
726         delete SI;
727         return 0;
728 }
729
730 /* this returns true when all modules are satisfied that the user should be allowed onto the irc server
731  * (until this returns true, a user will block in the waiting state, waiting to connect up to the
732  * registration timeout maximum seconds)
733  */
734 bool InspIRCd::AllModulesReportReady(User* user)
735 {
736         for (EventHandlerIter i = Modules->EventHandlers[I_OnCheckReady].begin(); i != Modules->EventHandlers[I_OnCheckReady].end(); ++i)
737         {
738                 int res = (*i)->OnCheckReady(user);
739                 if (!res)
740                         return false;
741         }
742
743         return true;
744 }
745
746 time_t InspIRCd::Time()
747 {
748         return TIME;
749 }
750
751 void InspIRCd::SetSignal(int signal)
752 {
753         *mysig = signal;
754 }