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