]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/conf.c
Do not exit unconditionally if config file cannot be opened
[ngircd-alex.git] / src / ngircd / conf.c
index c55aaf53a775f8945706a73305d3157ed277b623..0f6686221696f463eccd11097aa488fd8121bcbc 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: conf.c,v 1.102 2007/11/21 12:16:36 alex Exp $";
+static char UNUSED id[] = "$Id: conf.c,v 1.105 2008/03/18 20:12:47 fw Exp $";
 
 #include "imp.h"
 #include <assert.h>
@@ -57,7 +57,7 @@ static int New_Server_Idx;
 
 
 static void Set_Defaults PARAMS(( bool InitServers ));
-static void Read_Config PARAMS(( void ));
+static bool Read_Config PARAMS(( bool ngircd_starting ));
 static void Validate_Config PARAMS(( bool TestOnly, bool Rehash ));
 
 static void Handle_GLOBAL PARAMS(( int Line, char *Var, char *Arg ));
@@ -134,21 +134,21 @@ ports_parse(array *a, int Line, char *Arg)
 GLOBAL void
 Conf_Init( void )
 {
-       Set_Defaults( true );
-       Read_Config( );
+       Read_Config( true );
        Validate_Config(false, false);
 } /* Config_Init */
 
 
-GLOBAL void
+GLOBAL bool
 Conf_Rehash( void )
 {
-       Set_Defaults( false );
-       Read_Config( );
+       if (!Read_Config(false))
+               return false;
        Validate_Config(false, true);
 
        /* Update CLIENT structure of local server */
        Client_SetInfo(Client_ThisServer(), Conf_ServerInfo);
+       return true;
 } /* Config_Rehash */
 
 
@@ -163,9 +163,8 @@ Conf_Test( void )
        char *topic;
 
        Use_Log = false;
-       Set_Defaults( true );
 
-       Read_Config( );
+       Read_Config( true );
        Validate_Config(true, false);
 
        /* If stdin and stdout ("you can read our nice message and we can
@@ -460,8 +459,8 @@ Set_Defaults( bool InitServers )
 } /* Set_Defaults */
 
 
-static void
-Read_Config( void )
+static bool
+Read_Config( bool ngircd_starting )
 {
        /* Read configuration file. */
 
@@ -476,10 +475,14 @@ Read_Config( void )
                /* No configuration file found! */
                Config_Error( LOG_ALERT, "Can't read configuration \"%s\": %s",
                                        NGIRCd_ConfFile, strerror( errno ));
+               if (!ngircd_starting)
+                       return false;
                Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
                exit( 1 );
        }
 
+       Set_Defaults( ngircd_starting );
+
        Config_Error( LOG_INFO, "Reading configuration from \"%s\" ...", NGIRCd_ConfFile );
 
        /* Clean up server configuration structure: mark all already
@@ -626,6 +629,7 @@ Read_Config( void )
                        exit( 1 );
                }
        }
+       return true;
 } /* Read_Config */
 
 
@@ -937,6 +941,14 @@ Handle_SERVER( int Line, char *Var, char *Arg )
                        Config_Error_TooLong( Line, Var );
                return;
        }
+       if (strcasecmp(Var, "Bind") == 0) {
+               if (ng_ipaddr_init(&New_Server.bind_addr, Arg, 0))
+                       return;
+
+               Config_Error(LOG_ERR, "%s, line %d (section \"Server\"): Can't parse IP address \"%s\"",
+                               NGIRCd_ConfFile, Line, Arg);
+               return;
+       }
        if( strcasecmp( Var, "MyPassword" ) == 0 ) {
                /* Password of this server which is sent to the peer */
                if (*Arg == ':') {
@@ -1205,6 +1217,7 @@ Init_Server_Struct( CONF_SERVER *Server )
 
        Resolve_Init(&Server->res_stat);
        Server->conn_id = NONE;
+       memset(&Server->bind_addr, 0, sizeof(&Server->bind_addr));
 } /* Init_Server_Struct */