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