Show
Ignore:
Timestamp:
04/20/04 20:03:24 (9 years ago)
Author:
aprilp
Message:

A lot of changes regarding debugging facilities and added logging to syslog

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog/src/conf.c

    r82 r90  
    2828 
    2929#define DEFAULT_CONFIGFILE "/etc/wifidog.conf" 
    30 #define DEFAULT_DEBUGLEVEL D_LOG_DEBUG 
     30#define DEFAULT_DAEMON 1 
     31#define DEFAULT_DEBUGLEVEL LOG_INFO 
    3132#define DEFAULT_HTTPDMAXCONN 10 
    3233#define DEFAULT_GATEWAYID "default" 
     
    3839#define DEFAULT_FWSCRIPTS_PATH "." 
    3940#define DEFAULT_FWTYPE "." 
     41#define DEFAULT_LOG_SYSLOG 0 
     42#define DEFAULT_SYSLOG_FACILITY LOG_DAEMON 
    4043 
    4144s_config config; 
     
    6164        oFWType, 
    6265        oUserClass, 
     66    oSyslogFacility, 
    6367} OpCodes; 
    6468 
     
    8488        { "fwscriptspath",      oFWScriptsPath }, 
    8589        { "fwtype",             oFWType }, 
    86         { "userclass",          oUserClass }, 
     90        { "userclass",                  oUserClass }, 
     91        { "syslogfacility",     oSyslogFacility }, 
    8792        { NULL,                 oBadOption }, 
    8893}; 
     
    9196config_init(void) 
    9297{ 
    93         debug(D_LOG_DEBUG, "Setting default config parameters"); 
     98        debug(LOG_DEBUG, "Setting default config parameters"); 
    9499        config.configfile = (char *)malloc(255); 
    95100        strcpy(config.configfile, DEFAULT_CONFIGFILE); 
    96         config.daemon = 1; 
    97101        config.debuglevel = DEFAULT_DEBUGLEVEL; 
    98102        config.httpdmaxconn = DEFAULT_HTTPDMAXCONN; 
     
    112116        config.userclasses = (char **)malloc(sizeof(char *) * 256); 
    113117        memset(config.userclasses, 0, sizeof(char *) * 256); 
     118        config.syslog_facility = DEFAULT_SYSLOG_FACILITY; 
     119    config.daemon = -1; 
     120    config.log_syslog = DEFAULT_LOG_SYSLOG; 
     121} 
     122 
     123/** 
     124 * @brief Initialize the variables we override with the command line 
     125 * 
     126 * 
     127 * Initialize the variables we override with the command line after the config has been read 
     128 * if they haven't been initialized by the configuration file 
     129 */ 
     130void 
     131config_init_override(void) 
     132{ 
     133    if (!config.daemon) config.daemon = DEFAULT_DAEMON; 
    114134} 
    115135 
     
    123143                        return keywords[i].opcode; 
    124144 
    125         debug(D_LOG_ERR, "%s: line %d: Bad configuration option: %s",  
     145        debug(LOG_ERR, "%s: line %d: Bad configuration option: %s",  
    126146                        filename, linenum, cp); 
    127147        return oBadOption; 
     
    135155        int linenum = 0, opcode, value; 
    136156 
    137         debug(D_LOG_INFO, "Reading configuration file '%s'", filename); 
     157        debug(LOG_INFO, "Reading configuration file '%s'", filename); 
    138158 
    139159        if (!(fd = fopen(filename, "r"))) { 
    140                 debug(D_LOG_ERR, "Could not open configuration file '%s', " 
     160                debug(LOG_ERR, "Could not open configuration file '%s', " 
    141161                                "exiting...", filename); 
    142162                exit(1); 
     
    172192 
    173193                        if ((strncmp(s, "#", 1)) != 0) { 
    174                                 debug(D_LOG_DEBUG, "Parsing token: %s, " 
     194                                debug(LOG_DEBUG, "Parsing token: %s, " 
    175195                                                "value: %s", s, p1); 
    176196                                opcode = parse_token(s, filename, linenum); 
     
    182202                                        break; 
    183203                                case oDaemon: 
    184                                         if (((value = parse_value(p1)) != -1)) { 
     204                                        if (config.daemon == -1 && ((value = parse_value(p1)) != -1)) { 
    185205                                                config.daemon = value; 
    186206                                        } 
     
    216236                                        break; 
    217237                                case oBadOption: 
     238                    debug(LOG_ERR, "Exiting..."); 
    218239                                        exit(-1); 
    219240                                        break; 
     
    229250                case oFWType: 
    230251                                        config.fwtype = get_string(p1); 
     252                                        break; 
     253                case oSyslogFacility: 
     254                                        sscanf(p1, "%d", &config.syslog_facility); 
    231255                                        break; 
    232256                                } 
     
    295319 
    296320        if (missing_parms) { 
    297                 debug(D_LOG_ERR, "Configuration is not complete, exiting..."); 
     321                debug(LOG_ERR, "Configuration is not complete, exiting..."); 
    298322                exit(-1); 
    299323        } 
     
    304328{ 
    305329        if (parm == NULL) { 
    306                 debug(D_LOG_ERR, "%s is not set", parmname); 
     330                debug(LOG_ERR, "%s is not set", parmname); 
    307331                missing_parms = 1; 
    308332        }