Add new feature FEAT_HIS_WHOIS_LOCALCHAN.
[ircu2.10.12-pk.git] / ircd / ircd.c
index 33dbfaf73d776dbfd9d6ec2be7066f97a6fa95df..7cb126ec83d18f9a9a6ce8569369887de57e4fe6 100644 (file)
@@ -85,7 +85,8 @@ extern void mem_dbg_initialise(void);
  *--------------------------------------------------------------------------*/
 enum {
   BOOT_DEBUG = 1,
-  BOOT_TTY   = 2
+  BOOT_TTY   = 2,
+  BOOT_CHKCONF = 4
 };
 
 
@@ -159,7 +160,7 @@ void server_restart(const char *message)
 
   log_close();
 
-  close_connections(!(thisServer.bootopt & (BOOT_TTY | BOOT_DEBUG)));
+  close_connections(!(thisServer.bootopt & (BOOT_TTY | BOOT_DEBUG | BOOT_CHKCONF)));
 
   execv(SPATH, thisServer.argv);
 
@@ -256,7 +257,7 @@ static void try_connections(struct Event* ev) {
   Debug((DEBUG_NOTICE, "Connection check at   : %s", myctime(CurrentTime)));
   for (aconf = GlobalConfList; aconf; aconf = aconf->next) {
     /* Also when already connecting! (update holdtimes) --SRB */
-    if (!(aconf->status & CONF_SERVER) || aconf->port == 0 || aconf->hold == 0)
+    if (!(aconf->status & CONF_SERVER) || aconf->address.port == 0 || aconf->hold == 0)
       continue;
 
     /* Also skip juped servers */
@@ -464,7 +465,7 @@ static void check_pings(struct Event* ev) {
  * debugmode
  *--------------------------------------------------------------------------*/
 static void parse_command_line(int argc, char** argv) {
-  const char *options = "d:f:h:ntvx:";
+  const char *options = "d:f:h:nktvx:";
   int opt;
 
   if (thisServer.euid != thisServer.uid)
@@ -475,6 +476,7 @@ static void parse_command_line(int argc, char** argv) {
    */
   while ((opt = getopt(argc, argv, options)) != EOF)
     switch (opt) {
+    case 'k':  thisServer.bootopt |= BOOT_CHKCONF;     break;
     case 'n':
     case 't':  thisServer.bootopt |= BOOT_TTY;         break;
     case 'd':  dpath      = optarg;                    break;
@@ -509,8 +511,8 @@ static void parse_command_line(int argc, char** argv) {
       break;
       
     default:
-      printf("Usage: ircd [-f config] [-h servername] [-x loglevel] [-ntv]\n");
-      printf("\n -n -t\t Don't detach\n -v\t display version\n\n");
+      printf("Usage: ircd [-f config] [-h servername] [-x loglevel] [-ntvk]\n");
+      printf("\n -n -t\t Don't detach\n -v\t display version\n -k\t exit after checking config\n\n");
       printf("Server not started.\n");
       exit(1);
     }
@@ -521,11 +523,6 @@ static void parse_command_line(int argc, char** argv) {
  * daemon_init
  *--------------------------------------------------------------------------*/
 static void daemon_init(int no_fork) {
-  if (!init_connection_limits())
-    exit(9);
-
-  close_connections(!(thisServer.bootopt & (BOOT_DEBUG | BOOT_TTY)));
-
   if (no_fork)
     return;
 
@@ -641,15 +638,18 @@ int main(int argc, char **argv) {
       !check_file_access(configfile, 'C', R_OK))
     return 4;
 
-  debug_init(thisServer.bootopt & BOOT_TTY);
-  daemon_init(thisServer.bootopt & BOOT_TTY);
+  if (!init_connection_limits())
+    return 9;
+
+  close_connections(!(thisServer.bootopt & (BOOT_DEBUG | BOOT_TTY | BOOT_CHKCONF)));
+
   event_init(MAXCONNECTIONS);
 
   setup_signals();
   feature_init(); /* initialize features... */
   log_init(*argv);
   set_nomem_handler(outofmemory);
-  
+
   if (!init_string()) {
     log_write(LS_SYSTEM, L_CRIT, 0, "Failed to initialize string module");
     return 6;
@@ -677,6 +677,13 @@ int main(int argc, char **argv) {
     return 7;
   }
 
+  if(thisServer.bootopt & BOOT_CHKCONF) {
+    fprintf(stderr, "Configuration file checked okay.\n");
+    return 0;
+  }
+
+  debug_init(thisServer.bootopt & BOOT_TTY);
+  daemon_init(thisServer.bootopt & BOOT_TTY);
   if (check_pid()) {
     Debug((DEBUG_FATAL, "Failed to acquire PID file lock after fork"));
     exit(2);