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