97ff9f1f8f11c41b93e320e4cab8229b40bde258
[ircu2.10.12-pk.git] / ircd / ircd.c
1 /*
2  * IRC - Internet Relay Chat, ircd/ircd.c
3  * Copyright (C) 1990 Jarkko Oikarinen and
4  *                    University of Oulu, Computing Center
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
8  * the Free Software Foundation; either version 1, or (at your option)
9  * any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  * $Id$
21  */
22 #include "config.h"
23
24 #include "ircd.h"
25 #include "IPcheck.h"
26 #include "class.h"
27 #include "client.h"
28 #include "crule.h"
29 #include "hash.h"
30 #include "ircd_alloc.h"
31 #include "ircd_features.h"
32 #include "ircd_log.h"
33 #include "ircd_reply.h"
34 #include "ircd_signal.h"
35 #include "ircd_string.h"
36 #include "jupe.h"
37 #include "list.h"
38 #include "match.h"
39 #include "motd.h"
40 #include "msg.h"
41 #include "numeric.h"
42 #include "numnicks.h"
43 #include "parse.h"
44 #include "res.h"
45 #include "s_auth.h"
46 #include "s_bsd.h"
47 #include "s_conf.h"
48 #include "s_debug.h"
49 #include "s_misc.h"
50 #include "send.h"
51 #include "sys.h"
52 #include "uping.h"
53 #include "userload.h"
54 #include "version.h"
55 #include "whowas.h"
56
57 #include <assert.h>
58 #include <errno.h>
59 #include <fcntl.h>
60 #include <netdb.h>
61 #include <pwd.h>
62 #include <stdio.h>
63 #include <stdlib.h>
64 #include <string.h>
65 #include <sys/socket.h>
66 #include <sys/stat.h>
67 #include <sys/types.h>
68 #include <unistd.h>
69
70
71
72 /*----------------------------------------------------------------------------
73  * External stuff
74  *--------------------------------------------------------------------------*/
75 extern void init_counters(void);
76
77 /*----------------------------------------------------------------------------
78  * Constants / Enums
79  *--------------------------------------------------------------------------*/
80 enum {
81   BOOT_DEBUG = 1,
82   BOOT_TTY   = 2
83 };
84
85
86 /*----------------------------------------------------------------------------
87  * Global data (YUCK!)
88  *--------------------------------------------------------------------------*/
89 struct Client  me;                      /* That's me */
90 struct Connection me_con;               /* That's me too */
91 struct Client *GlobalClientList  = &me; /* Pointer to beginning of
92                                            Client list */
93 time_t         TSoffset          = 0;/* Offset of timestamps to system clock */
94 int            GlobalRehashFlag  = 0;   /* do a rehash if set */
95 int            GlobalRestartFlag = 0;   /* do a restart if set */
96 time_t         CurrentTime;          /* Updated every time we leave select() */
97
98 char          *configfile        = CPATH; /* Server configuration file */
99 int            debuglevel        = -1;    /* Server debug level  */
100 char          *debugmode         = "";    /* Server debug level */
101 static char   *dpath             = DPATH;
102
103 time_t         nextconnect       = 1; /* time for next try_connections call */
104 time_t         nextping          = 1; /* same as above for check_pings() */
105
106 static struct Daemon thisServer  = { 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0 };
107
108
109
110 /*----------------------------------------------------------------------------
111  * API: server_die
112  *--------------------------------------------------------------------------*/
113 void server_die(const char* message) {
114   /* log_write will send out message to both log file and as server notice */
115   log_write(LS_SYSTEM, L_CRIT, 0, "Server terminating: %s", message);
116   flush_connections(0);
117   close_connections(1);
118   thisServer.running = 0;
119 }
120
121
122 /*----------------------------------------------------------------------------
123  * API: server_restart
124  *--------------------------------------------------------------------------*/
125 void server_restart(const char* message) {
126   static int restarting = 0;
127
128   /* inhibit sending any server notices; we may be in a loop */
129   log_write(LS_SYSTEM, L_WARNING, LOG_NOSNOTICE, "Restarting Server: %s",
130             message);
131   if (restarting++) /* increment restarting to prevent looping */
132     return;
133
134   sendto_opmask_butone(0, SNO_OLDSNO, "Restarting server: %s", message);
135   Debug((DEBUG_NOTICE, "Restarting server..."));
136   flush_connections(0);
137
138   log_close();
139
140   close_connections(!(thisServer.bootopt & (BOOT_TTY | BOOT_DEBUG)));
141
142   execv(SPATH, thisServer.argv);
143
144   /* Have to reopen since it has been closed above */
145   log_reopen();
146
147   log_write(LS_SYSTEM, L_CRIT, 0, "execv(%s,%s) failed: %m", SPATH,
148             *thisServer.argv);
149
150   Debug((DEBUG_FATAL, "Couldn't restart server \"%s\": %s",
151          SPATH, (strerror(errno)) ? strerror(errno) : ""));
152   exit(8);
153 }
154
155
156 /*----------------------------------------------------------------------------
157  * outofmemory:  Handler for out of memory conditions...
158  *--------------------------------------------------------------------------*/
159 static void outofmemory(void) {
160   Debug((DEBUG_FATAL, "Out of memory: restarting server..."));
161   server_restart("Out of Memory");
162
163
164
165 /*----------------------------------------------------------------------------
166  * write_pidfile
167  *--------------------------------------------------------------------------*/
168 static void write_pidfile(void) {
169   char buff[20];
170
171   if (thisServer.pid_fd >= 0) {
172     memset(buff, 0, sizeof(buff));
173     sprintf(buff, "%5d\n", (int)getpid());
174     if (write(thisServer.pid_fd, buff, strlen(buff)) == -1)
175       Debug((DEBUG_NOTICE, "Error writing to pid file %s: %m",
176              feature_str(FEAT_PPATH)));
177     return;
178   }
179   Debug((DEBUG_NOTICE, "Error opening pid file %s: %m",
180          feature_str(FEAT_PPATH)));
181 }
182
183 /* check_pid
184  * 
185  * inputs: 
186  *   none
187  * returns:
188  *   true - if the pid file exists (and is readable), and the pid refered
189  *          to in the file is still running.
190  *   false - otherwise.
191  */
192 static int check_pid(void)
193 {
194   struct flock lock;
195
196   lock.l_type = F_WRLCK;
197   lock.l_start = 0;
198   lock.l_whence = SEEK_SET;
199   lock.l_len = 0;
200
201   if ((thisServer.pid_fd = open(feature_str(FEAT_PPATH), O_CREAT | O_RDWR,
202                                 0600)) >= 0)
203     return fcntl(thisServer.pid_fd, F_SETLK, &lock);
204
205   return 0;
206 }
207   
208
209 /*----------------------------------------------------------------------------
210  * try_connections
211  *
212  * Scan through configuration and try new connections.
213  *
214  * Returns the calendar time when the next call to this
215  * function should be made latest. (No harm done if this
216  * is called earlier or later...)
217  *--------------------------------------------------------------------------*/
218 static time_t try_connections(void) {
219   struct ConfItem*  aconf;
220   struct Client*    cptr;
221   struct ConfItem** pconf;
222   int               connecting;
223   int               confrq;
224   time_t            next        = 0;
225   struct ConnectionClass* cltmp;
226   struct ConfItem*  con_conf    = 0;
227   struct Jupe*      ajupe;
228   unsigned int      con_class   = 0;
229
230   connecting = FALSE;
231   Debug((DEBUG_NOTICE, "Connection check at   : %s", myctime(CurrentTime)));
232   for (aconf = GlobalConfList; aconf; aconf = aconf->next) {
233     /* Also when already connecting! (update holdtimes) --SRB */
234     if (!(aconf->status & CONF_SERVER) || aconf->port == 0)
235       continue;
236
237     /* Also skip juped servers */
238     if ((ajupe = jupe_find(aconf->name)) && JupeIsActive(ajupe))
239       continue;
240
241     /* Skip this entry if the use of it is still on hold until
242      * future. Otherwise handle this entry (and set it on hold until next
243      * time). Will reset only hold times, if already made one successfull
244      * connection... [this algorithm is a bit fuzzy... -- msa >;) ]
245      */
246     if (aconf->hold > CurrentTime && (next > aconf->hold || next == 0)) {
247       next = aconf->hold;
248       continue;
249     }
250
251     cltmp = aconf->conn_class;
252     confrq = get_con_freq(cltmp);
253     aconf->hold = CurrentTime + confrq;
254
255     /* Found a CONNECT config with port specified, scan clients and see if
256      * this server is already connected?
257      */
258     cptr = FindServer(aconf->name);
259
260     if (!cptr && (Links(cltmp) < MaxLinks(cltmp)) &&
261         (!connecting || (ConClass(cltmp) > con_class))) {
262       /*
263        * Check connect rules to see if we're allowed to try
264        */
265       if (0 == conf_eval_crule(aconf->name, CRULE_MASK)) {
266         con_class = ConClass(cltmp);
267         con_conf = aconf;
268         /* We connect only one at time... */
269         connecting = TRUE;
270       }
271     }
272     if ((next > aconf->hold) || (next == 0))
273       next = aconf->hold;
274   }
275   if (connecting) {
276     if (con_conf->next) { /* are we already last? */
277       /* Put the current one at the end and make sure we try all connections */
278       for (pconf = &GlobalConfList; (aconf = *pconf); pconf = &(aconf->next))
279         if (aconf == con_conf)
280           *pconf = aconf->next;
281       (*pconf = con_conf)->next = 0;
282     }
283
284     if (connect_server(con_conf, 0, 0))
285       sendto_opmask_butone(0, SNO_OLDSNO, "Connection to %s activated.",
286                            con_conf->name);
287   }
288
289   Debug((DEBUG_NOTICE, "Next connection check : %s", myctime(next)));
290   return(next);
291 }
292
293
294 /*----------------------------------------------------------------------------
295  * check_pings
296  *
297  * TODO: This should be moved out of ircd.c.  It's protocol-specific when you
298  *       get right down to it.  Can't really be done until the server is more
299  *       modular, however...
300  *--------------------------------------------------------------------------*/
301 static time_t check_pings(void) {
302   int expire     = 0; 
303   int next_check = CurrentTime;
304   int max_ping   = 0;
305   int i;
306
307   next_check += feature_int(FEAT_PINGFREQUENCY);
308   
309   /* Scan through the client table */
310   for (i=0; i <= HighestFd; i++) {
311     struct Client *cptr = LocalClientArray[i];
312    
313     if (!cptr)
314       continue;
315      
316     assert(&me != cptr);  /* I should never be in the local client array! */
317    
318
319     /* Remove dead clients. */
320     if (IsDead(cptr)) {
321       exit_client(cptr, cptr, &me, cli_info(cptr));
322       continue;
323     }
324
325     max_ping = IsRegistered(cptr) ? client_get_ping(cptr) :
326       feature_int(FEAT_CONNECTTIMEOUT);
327    
328     Debug((DEBUG_DEBUG, "check_pings(%s)=status:%s limit: %d current: %d",
329            cli_name(cptr), (cli_flags(cptr) & FLAGS_PINGSENT) ? "[Ping Sent]" : "[]", 
330            max_ping, (int)(CurrentTime - cli_lasttime(cptr))));
331           
332
333     /* Ok, the thing that will happen most frequently, is that someone will
334      * have sent something recently.  Cover this first for speed.
335      */
336     if (CurrentTime-cli_lasttime(cptr) < max_ping) {
337       expire = cli_lasttime(cptr) + max_ping;
338       if (expire < next_check) 
339         next_check = expire;
340       continue;
341     }
342
343     /* Quit the client after max_ping*2 - they should have answered by now */
344     if (CurrentTime-cli_lasttime(cptr) >= (max_ping*2) ) {
345       /* If it was a server, then tell ops about it. */
346       if (IsServer(cptr) || IsConnecting(cptr) || IsHandshake(cptr))
347         sendto_opmask_butone(0, SNO_OLDSNO,
348                              "No response from %s, closing link", cli_name(cptr));
349       exit_client_msg(cptr, cptr, &me, "Ping timeout");
350       continue;
351     }
352     
353     /* Unregistered clients pingout after max_ping seconds, they don't
354      * get given a second chance - if they were then people could not quite
355      * finish registration and hold resources without being subject to k/g
356      * lines
357      */
358     if (!IsRegistered(cptr)) {
359       /* Display message if they have sent a NICK and a USER but no
360        * nospoof PONG.
361        */
362       if (*(cli_name(cptr)) && cli_user(cptr) && *(cli_user(cptr))->username) {
363         send_reply(cptr, SND_EXPLICIT | ERR_BADPING,
364                    ":Your client may not be compatible with this server.");
365         send_reply(cptr, SND_EXPLICIT | ERR_BADPING,
366                    ":Compatible clients are available at "
367                    "ftp://ftp.undernet.org/pub/irc/clients");
368       }    
369       exit_client_msg(cptr,cptr,&me, "Ping Timeout");
370       continue;
371     }
372     
373     if (!(cli_flags(cptr) & FLAGS_PINGSENT)) {
374       /* If we havent PINGed the connection and we havent heard from it in a
375        * while, PING it to make sure it is still alive.
376        */
377       cli_flags(cptr) |= FLAGS_PINGSENT;
378
379       /* If we're late in noticing don't hold it against them :) */
380       cli_lasttime(cptr) = CurrentTime - max_ping;
381       
382       if (IsUser(cptr))
383         sendrawto_one(cptr, MSG_PING " :%s", cli_name(&me));
384       else
385         sendcmdto_one(&me, CMD_PING, cptr, ":%s", cli_name(&me));
386     }
387     
388     expire = cli_lasttime(cptr) + max_ping * 2;
389     if (expire < next_check)
390       next_check=expire;
391   }
392   
393   assert(next_check >= CurrentTime);
394   
395   Debug((DEBUG_DEBUG, "[%i] check_pings() again in %is",
396          CurrentTime, next_check-CurrentTime));
397   
398   return next_check;
399 }
400
401
402 /*----------------------------------------------------------------------------
403  * parse_command_line
404  * Side Effects: changes GLOBALS me, thisServer, dpath, configfile, debuglevel
405  * debugmode
406  *--------------------------------------------------------------------------*/
407 static void parse_command_line(int argc, char** argv) {
408   const char *options = "d:f:h:ntvx:";
409   int opt;
410
411   if (thisServer.euid != thisServer.uid)
412     setuid(thisServer.uid);
413
414   /* Do we really need to santiy check the non-NULLness of optarg?  That's
415    * getopt()'s job...  Removing those... -zs
416    */
417   while ((opt = getopt(argc, argv, options)) != EOF)
418     switch (opt) {
419     case 'n':
420     case 't':  thisServer.bootopt |= BOOT_TTY;         break;
421     case 'd':  dpath      = optarg;                    break;
422     case 'f':  configfile = optarg;                    break;
423     case 'h':  ircd_strncpy(cli_name(&me), optarg, HOSTLEN); break;
424     case 'v':  printf("ircd %s\n", version);           exit(0);
425       
426     case 'x':
427       debuglevel = atoi(optarg);
428       if (debuglevel < 0)
429         debuglevel = 0;
430       debugmode = optarg;
431       thisServer.bootopt |= BOOT_DEBUG;
432       break;
433       
434     default:
435       printf("Usage: ircd [-f config] [-h servername] [-x loglevel] [-ntv]\n");
436       printf("\n -n -t\t Don't detach\n -v\t display version\n\n");
437       printf("Server not started.\n");
438       exit(1);
439     }
440 }
441
442
443 /*----------------------------------------------------------------------------
444  * daemon_init
445  *--------------------------------------------------------------------------*/
446 static void daemon_init(int no_fork) {
447   if (!init_connection_limits())
448     exit(9);
449
450   close_connections(!(thisServer.bootopt & (BOOT_DEBUG | BOOT_TTY)));
451
452   if (no_fork)
453     return;
454
455   if (fork())
456     exit(0);
457
458 #ifdef TIOCNOTTY
459   {
460     int fd;
461     if ((fd = open("/dev/tty", O_RDWR)) > -1) {
462       ioctl(fd, TIOCNOTTY, 0);
463       close(fd);
464     }
465   }
466 #endif
467
468   setsid();
469 }
470
471
472 /*----------------------------------------------------------------------------
473  * event_loop
474  *--------------------------------------------------------------------------*/
475 static void event_loop(void) {
476   time_t nextdnscheck = 0;
477   time_t delay        = 0;
478
479   thisServer.running = 1;
480   while (thisServer.running) {
481     /* We only want to connect if a connection is due, not every time through.
482      * Note, if there are no active C lines, this call to Tryconnections is
483      * made once only; it will return 0. - avalon
484      */
485     if (nextconnect && CurrentTime >= nextconnect)
486       nextconnect = try_connections();
487
488     /* DNS checks. One to timeout queries, one for cache expiries. */
489     nextdnscheck = timeout_resolver(CurrentTime);
490
491     /* Take the smaller of the two 'timed' event times as the time of next
492      * event (stops us being late :) - avalon
493      * WARNING - nextconnect can return 0!
494      */
495     if (nextconnect)
496       delay = IRCD_MIN(nextping, nextconnect);
497     else
498       delay = nextping;
499
500     delay = IRCD_MIN(nextdnscheck, delay) - CurrentTime;
501
502     /* Adjust delay to something reasonable [ad hoc values] (one might think
503      * something more clever here... --msa) We don't really need to check that
504      * often and as long as we don't delay too long, everything should be ok.
505      * waiting too long can cause things to timeout...  i.e. PINGS -> a
506      * disconnection :( - avalon
507      */
508     if (delay < 1)
509       read_message(1);
510     else
511       read_message(IRCD_MIN(delay, feature_int(FEAT_TIMESEC)));
512
513     /* ...perhaps should not do these loops every time, but only if there is
514      * some chance of something happening (but, note that conf->hold times may
515      * be changed elsewhere--so precomputed next event time might be too far
516      * away... (similarly with ping times) --msa
517      */
518     if (CurrentTime >= nextping)
519       nextping = check_pings();
520     
521     /* timeout pending queries that haven't been responded to */
522     timeout_auth_queries(CurrentTime);
523
524     IPcheck_expire();
525
526     if (GlobalRehashFlag) {
527       rehash(&me, 1);
528       GlobalRehashFlag = 0;
529     }
530
531     if (GlobalRestartFlag)
532       server_restart("caught signal: SIGINT");
533   }
534 }
535
536 /*----------------------------------------------------------------------------
537  * check_file_access:  random helper function to make sure that a file is
538  *                     accessible in a certain way, and complain if not.
539  *--------------------------------------------------------------------------*/
540 static char check_file_access(const char *path, char which, int mode) {
541   if (!access(path, mode))
542     return 1;
543
544   fprintf(stderr, 
545           "Check on %cPATH (%s) failed: %s\n"
546           "Please create file and/or rerun `make config' and "
547           "recompile to correct this.\n",
548           which, path, strerror(errno));
549
550 #ifdef CHROOTDIR
551   fprintf(stderr, "Keep in mind that paths are relative to CHROOTDIR.\n");
552 #endif
553
554   return 0;
555 }
556
557
558 /*----------------------------------------------------------------------------
559  * set_core_limit
560  *--------------------------------------------------------------------------*/
561 #if defined(HAVE_SETRLIMIT) && defined(RLIMIT_CORE)
562 static void set_core_limit(void) {
563   struct rlimit corelim;
564
565   if (getrlimit(RLIMIT_CORE, &corelim)) {
566     fprintf(stderr, "Read of rlimit core size failed: %s\n", strerror(errno));
567     corelim.rlim_max = RLIM_INFINITY;   /* Try to recover */
568   }
569
570   corelim.rlim_cur = corelim.rlim_max;
571   if (setrlimit(RLIMIT_CORE, &corelim))
572     fprintf(stderr, "Setting rlimit core size failed: %s\n", strerror(errno));
573 }
574 #endif
575
576
577
578 /*----------------------------------------------------------------------------
579  * set_chroot_environment
580  *--------------------------------------------------------------------------*/
581 #ifdef CHROOTDIR
582 static char set_chroot_environment(void) {
583   /* Must be root to chroot! Silly if you ask me... */
584   if (geteuid())
585     seteuid(0);
586
587   if (chdir(dpath)) {
588     fprintf(stderr, "Fail: Cannot chdir(%s): %s\n", dpath, strerror(errno));
589     return 0;
590   }
591   if (chroot(dpath)) {
592     fprintf(stderr, "Fail: Cannot chroot(%s): %s\n", dpath, strerror(errno));
593     return 0;
594   }
595   dpath = "/";
596   return 1;
597 }
598 #endif
599
600
601 /*----------------------------------------------------------------------------
602  * set_userid_if_needed()
603  *--------------------------------------------------------------------------*/
604 static int set_userid_if_needed(void) {
605   /* TODO: Drop privs correctly! */
606 #if defined(IRC_GID) && defined(IRC_UID)
607   setgid (IRC_GID);
608   setegid(IRC_GID);
609   setuid (IRC_UID);
610   seteuid(IRC_UID);
611 #endif
612
613   if (getuid() == 0 || geteuid() == 0 ||
614       getgid() == 0 || getegid() == 0) {
615     fprintf(stderr, "ERROR:  This server will not run as superuser.\n");
616     return 0;
617   }
618
619   return 1;
620 }
621
622
623 /*----------------------------------------------------------------------------
624  * main - entrypoint
625  *
626  * TODO:  This should set the basic environment up and start the main loop.
627  *        we're doing waaaaaaaaay too much server initialization here.  I hate
628  *        long and ugly control paths...  -smd
629  *--------------------------------------------------------------------------*/
630 int main(int argc, char **argv) {
631   CurrentTime = time(NULL);
632
633   thisServer.argc = argc;
634   thisServer.argv = argv;
635   thisServer.uid  = getuid();
636   thisServer.euid = geteuid();
637
638 #ifdef CHROOTDIR
639   if (!set_chroot_environment())
640     return 1;
641 #endif
642
643 #if defined(HAVE_SETRLIMIT) && defined(RLIMIT_CORE)
644   set_core_limit();
645 #endif
646
647   umask(077);                   /* better safe than sorry --SRB */
648   memset(&me, 0, sizeof(me));
649   memset(&me_con, 0, sizeof(me_con));
650   cli_connect(&me) = &me_con;
651   cli_fd(&me) = -1;
652
653   parse_command_line(argc, argv);
654
655   if (chdir(dpath)) {
656     fprintf(stderr, "Fail: Cannot chdir(%s): %s, check DPATH\n", dpath, strerror(errno));
657     return 2;
658   }
659
660   if (!set_userid_if_needed())
661     return 3;
662
663   /* Check paths for accessibility */
664   if (!check_file_access(SPATH, 'S', X_OK) ||
665       !check_file_access(configfile, 'C', R_OK))
666     return 4;
667       
668 #ifdef DEBUG
669   if (!check_file_access(LPATH, 'L', W_OK))
670     return 5;
671 #endif
672
673   debug_init(thisServer.bootopt & BOOT_TTY);
674   daemon_init(thisServer.bootopt & BOOT_TTY);
675
676   setup_signals();
677   feature_init(); /* initialize features... */
678   log_init(*argv);
679   if (check_pid()) {
680     Debug((DEBUG_FATAL, "Failed to acquire PID file lock after fork"));
681     exit(2);
682   }
683   set_nomem_handler(outofmemory);
684   
685   if (!init_string()) {
686     log_write(LS_SYSTEM, L_CRIT, 0, "Failed to initialize string module");
687     return 6;
688   }
689
690   initload();
691   init_list();
692   init_hash();
693   init_class();
694   initwhowas();
695   initmsgtree();
696   initstats();
697
698   init_resolver();
699
700   motd_init();
701
702   if (!init_conf()) {
703     log_write(LS_SYSTEM, L_CRIT, 0, "Failed to read configuration file %s",
704               configfile);
705     return 7;
706   }
707
708   init_server_identity();
709
710   uping_init();
711
712   CurrentTime = time(NULL);
713
714   SetMe(&me);
715   cli_from(&me) = &me;
716   make_server(&me);
717
718   cli_serv(&me)->timestamp = TStime();  /* Abuse own link timestamp as start TS */
719   cli_serv(&me)->prot      = atoi(MAJOR_PROTOCOL);
720   cli_serv(&me)->up        = &me;
721   cli_serv(&me)->down      = NULL;
722   cli_handler(&me)         = SERVER_HANDLER;
723
724   SetYXXCapacity(&me, MAXCLIENTS);
725
726   cli_lasttime(&me) = cli_since(&me) = cli_firsttime(&me) = CurrentTime;
727
728   hAddClient(&me);
729
730   write_pidfile();
731   init_counters();
732
733   Debug((DEBUG_NOTICE, "Server ready..."));
734   log_write(LS_SYSTEM, L_NOTICE, 0, "Server Ready");
735
736   event_loop();
737
738   return 0;
739 }
740
741