Changeset eeb85a8 for conf.c


Ignore:
Timestamp:
2008-02-11T12:35:01Z (16 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
1ba7e8f, 2799ff9
Parents:
3038e47
Message:

Got rid of some noise at startup: complaining when the default configuration
file couldn't be found while the user specified an alternative location with
the -c option, and double complaints about /var/lib/bitlbee/ permissions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • conf.c

    r3038e47 reeb85a8  
    3636#include "proxy.h"
    3737
    38 char *CONF_FILE;
    39 
    4038static int conf_loadini( conf_t *conf, char *file );
    4139
     
    4341{
    4442        conf_t *conf;
    45         int opt, i;
     43        int opt, i, config_missing = 0;
    4644       
    4745        conf = g_new0( conf_t, 1 );
     
    6664        proxytype = 0;
    6765       
    68         i = conf_loadini( conf, CONF_FILE );
     66        i = conf_loadini( conf, global.conf_file );
    6967        if( i == 0 )
    7068        {
    71                 fprintf( stderr, "Error: Syntax error in configuration file `%s'.\n", CONF_FILE );
    72                 return( NULL );
     69                fprintf( stderr, "Error: Syntax error in configuration file `%s'.\n", global.conf_file );
     70                return NULL;
    7371        }
    7472        else if( i == -1 )
    7573        {
    76                 fprintf( stderr, "Warning: Unable to read configuration file `%s'.\n", CONF_FILE );
     74                config_missing ++;
     75                /* Whine after parsing the options if there was no -c pointing
     76                   at a *valid* configuration file. */
    7777        }
    7878       
     
    106106                else if( opt == 'c' )
    107107                {
    108                         if( strcmp( CONF_FILE, optarg ) != 0 )
    109                         {
    110                                 g_free( CONF_FILE );
    111                                 CONF_FILE = g_strdup( optarg );
     108                        if( strcmp( global.conf_file, optarg ) != 0 )
     109                        {
     110                                g_free( global.conf_file );
     111                                global.conf_file = g_strdup( optarg );
    112112                                g_free( conf );
    113113                                /* Re-evaluate arguments. Don't use this option twice,
     
    115115                                   works with all libcs BTW.. */
    116116                                optind = 1;
    117                                 return( conf_load( argc, argv ) );
     117                                return conf_load( argc, argv );
    118118                        }
    119119                }
     
    143143                                "  -d  Specify alternative user configuration directory\n"
    144144                                "  -h  Show this help page.\n" );
    145                         return( NULL );
     145                        return NULL;
    146146                }
    147147                else if( opt == 'R' )
     
    169169        }
    170170       
    171         return( conf );
     171        if( config_missing )
     172                fprintf( stderr, "Warning: Unable to read configuration file `%s'.\n", global.conf_file );
     173       
     174        return conf;
    172175}
    173176
     
    178181       
    179182        ini = ini_open( file );
    180         if( ini == NULL ) return( -1 );
     183        if( ini == NULL ) return -1;
    181184        while( ini_read( ini ) )
    182185        {
     
    256259                                {
    257260                                        fprintf( stderr, "Invalid %s value: %s\n", ini->key, ini->value );
    258                                         return( 0 );
     261                                        return 0;
    259262                                }
    260263                                conf->ping_interval = i;
     
    265268                                {
    266269                                        fprintf( stderr, "Invalid %s value: %s\n", ini->key, ini->value );
    267                                         return( 0 );
     270                                        return 0;
    268271                                }
    269272                                conf->ping_timeout = i;
     
    277280                                        fprintf( stderr, "Invalid %s value: %s\n", ini->key, ini->value );
    278281                                        g_free( url );
    279                                         return( 0 );
     282                                        return 0;
    280283                                }
    281284                               
     
    301304                        {
    302305                                fprintf( stderr, "Error: Unknown setting `%s` in configuration file.\n", ini->key );
    303                                 return( 0 );
     306                                return 0;
    304307                                /* For now just ignore unknown keys... */
    305308                        }
     
    309312                        fprintf( stderr, "Error: Unknown section [%s] in configuration file. "
    310313                                         "BitlBee configuration must be put in a [settings] section!\n", ini->section );
    311                         return( 0 );
     314                        return 0;
    312315                }
    313316        }
    314317        ini_close( ini );
    315318       
    316         return( 1 );
     319        return 1;
    317320}
    318321
     
    321324        ini_t *ini;
    322325       
    323         ini = ini_open( CONF_FILE );
     326        ini = ini_open( global.conf_file );
    324327        if( ini == NULL ) return;
    325328        while( ini_read( ini ) )
Note: See TracChangeset for help on using the changeset viewer.