Skip to content

Commit 66776a2

Browse files
committed
Remove debug.c/h dependency on conf.c/h
1 parent 8f5757b commit 66776a2

File tree

5 files changed

+45
-25
lines changed

5 files changed

+45
-25
lines changed

src/commandline.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,17 @@ parse_commandline(int argc, char **argv)
120120
case 'f':
121121
skiponrestart = 1;
122122
config->daemon = 0;
123+
debugconf.log_stderr = 1;
123124
break;
124125

125126
case 'd':
126127
if (optarg) {
127-
config->debuglevel = atoi(optarg);
128+
debugconf.debuglevel = atoi(optarg);
128129
}
129130
break;
130131

131132
case 's':
132-
config->log_syslog = 1;
133+
debugconf.log_syslog = 1;
133134
break;
134135

135136
case 'v':

src/conf.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ config_init(void)
171171
debug(LOG_DEBUG, "Setting default config parameters");
172172
config.configfile = safe_strdup(DEFAULT_CONFIGFILE);
173173
config.htmlmsgfile = safe_strdup(DEFAULT_HTMLMSGFILE);
174-
config.debuglevel = DEFAULT_DEBUGLEVEL;
175174
config.httpdmaxconn = DEFAULT_HTTPDMAXCONN;
176175
config.external_interface = NULL;
177176
config.gw_id = DEFAULT_GATEWAYID;
@@ -185,9 +184,7 @@ config_init(void)
185184
config.httpdpassword = NULL;
186185
config.clienttimeout = DEFAULT_CLIENTTIMEOUT;
187186
config.checkinterval = DEFAULT_CHECKINTERVAL;
188-
config.syslog_facility = DEFAULT_SYSLOG_FACILITY;
189187
config.daemon = -1;
190-
config.log_syslog = DEFAULT_LOG_SYSLOG;
191188
config.wdctl_sock = safe_strdup(DEFAULT_WDCTL_SOCK);
192189
config.internal_sock = safe_strdup(DEFAULT_INTERNAL_SOCK);
193190
config.rulesets = NULL;
@@ -197,6 +194,11 @@ config_init(void)
197194
config.ssl_verify = DEFAULT_AUTHSERVSSLPEERVER;
198195
config.ssl_cipher_list = NULL;
199196
config.arp_table_path = safe_strdup(DEFAULT_ARPTABLE);
197+
198+
debugconf.log_stderr = 1;
199+
debugconf.debuglevel = DEFAULT_DEBUGLEVEL;
200+
debugconf.syslog_facility = DEFAULT_SYSLOG_FACILITY;
201+
debugconf.log_syslog = DEFAULT_LOG_SYSLOG;
200202
}
201203

202204
/**
@@ -205,8 +207,12 @@ config_init(void)
205207
void
206208
config_init_override(void)
207209
{
208-
if (config.daemon == -1)
210+
if (config.daemon == -1) {
209211
config.daemon = DEFAULT_DAEMON;
212+
if (config.daemon > 0) {
213+
debugconf.log_stderr = 0;
214+
}
215+
}
210216
}
211217

212218
/** @internal
@@ -681,6 +687,11 @@ config_read(const char *filename)
681687
case oDaemon:
682688
if (config.daemon == -1 && ((value = parse_boolean_value(p1)) != -1)) {
683689
config.daemon = value;
690+
if (config.daemon > 0) {
691+
debugconf.log_stderr = 0;
692+
} else {
693+
debugconf.log_stderr = 1;
694+
}
684695
}
685696
break;
686697
case oExternalInterface:
@@ -733,7 +744,7 @@ config_read(const char *filename)
733744
sscanf(p1, "%d", &config.clienttimeout);
734745
break;
735746
case oSyslogFacility:
736-
sscanf(p1, "%d", &config.syslog_facility);
747+
sscanf(p1, "%d", &debugconf.syslog_facility);
737748
break;
738749
case oHtmlMessageFile:
739750
config.htmlmsgfile = safe_strdup(p1);

src/conf.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ typedef struct {
158158
char *wdctl_sock; /**< @brief wdctl path to socket */
159159
char *internal_sock; /**< @brief internal path to socket */
160160
int daemon; /**< @brief if daemon > 0, use daemon mode */
161-
int debuglevel; /**< @brief Debug information verbosity */
162161
char *external_interface; /**< @brief External network interface name for
163162
firewall rules */
164163
char *gw_id; /**< @brief ID of the Gateway, sent to central
@@ -180,9 +179,6 @@ typedef struct {
180179
must be re-authenticated */
181180
int checkinterval; /**< @brief Frequency the the client timeout check
182181
thread will run. */
183-
int log_syslog; /**< @brief boolean, wether to log to syslog */
184-
int syslog_facility; /**< @brief facility to use when using syslog for
185-
logging */
186182
int proxy_port; /**< @brief Transparent proxy port (0 to disable) */
187183
char *ssl_certs; /**< @brief Path to SSL certs for auth server
188184
verification */

src/debug.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* vim: set et ts=4 sts=4 sw=4 : */
12
/********************************************************************\
23
* This program is free software; you can redistribute it and/or *
34
* modify it under the terms of the GNU General Public License as *
@@ -18,7 +19,6 @@
1819
* *
1920
\********************************************************************/
2021

21-
/* $Id$ */
2222
/** @file debug.c
2323
@brief Debug output routines
2424
@author Copyright (C) 2004 Philippe April <[email protected]>
@@ -32,7 +32,9 @@
3232
#include <unistd.h>
3333
#include <signal.h>
3434

35-
#include "conf.h"
35+
#include "debug.h"
36+
37+
debugconf_t debugconf = {0, 0, 0, 0};
3638

3739
/** @internal
3840
Do not use directly, use the debug macro */
@@ -41,40 +43,39 @@ _debug(const char *filename, int line, int level, const char *format, ...)
4143
{
4244
char buf[28];
4345
va_list vlist;
44-
s_config *config = config_get_config();
4546
time_t ts;
4647
sigset_t block_chld;
4748

4849
time(&ts);
4950

50-
if (config->debuglevel >= level) {
51+
if (debugconf.debuglevel >= level) {
5152
sigemptyset(&block_chld);
5253
sigaddset(&block_chld, SIGCHLD);
5354
sigprocmask(SIG_BLOCK, &block_chld, NULL);
5455

5556
if (level <= LOG_WARNING) {
5657
fprintf(stderr, "[%d][%.24s][%u](%s:%d) ", level, ctime_r(&ts, buf), getpid(),
57-
filename, line);
58+
filename, line);
5859
va_start(vlist, format);
5960
vfprintf(stderr, format, vlist);
6061
va_end(vlist);
6162
fputc('\n', stderr);
62-
} else if (!config->daemon) {
63+
} else if (debugconf.log_stderr) {
6364
fprintf(stderr, "[%d][%.24s][%u](%s:%d) ", level, ctime_r(&ts, buf), getpid(),
64-
filename, line);
65+
filename, line);
6566
va_start(vlist, format);
6667
vfprintf(stderr, format, vlist);
6768
va_end(vlist);
6869
fputc('\n', stderr);
6970
}
7071

71-
if (config->log_syslog) {
72-
openlog("wifidog", LOG_PID, config->syslog_facility);
72+
if (debugconf.log_syslog) {
73+
openlog("wifidog", LOG_PID, debugconf.syslog_facility);
7374
va_start(vlist, format);
7475
vsyslog(level, format, vlist);
7576
va_end(vlist);
7677
closelog();
77-
}
78+
}
7879

7980
sigprocmask(SIG_UNBLOCK, &block_chld, NULL);
8081
}

src/debug.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* vim: set et ts=4 sts=4 sw=4 : */
12
/********************************************************************\
23
* This program is free software; you can redistribute it and/or *
34
* modify it under the terms of the GNU General Public License as *
@@ -18,7 +19,6 @@
1819
* *
1920
\********************************************************************/
2021

21-
/* $Id$ */
2222
/** @file debug.h
2323
@brief Debug output routines
2424
@author Copyright (C) 2004 Philippe April <[email protected]>
@@ -27,12 +27,23 @@
2727
#ifndef _DEBUG_H_
2828
#define _DEBUG_H_
2929

30-
/** @brief Used to output messages.
31-
*The messages will include the finlname and line number, and will be sent to syslog if so configured in the config file
30+
typedef struct _debug_conf {
31+
int debuglevel; /**< @brief Debug information verbosity */
32+
int log_stderr; /**< @brief Output log to stdout */
33+
int log_syslog; /**< @brief Output log to syslog */
34+
int syslog_facility; /**< @brief facility to use when using syslog for logging */
35+
} debugconf_t;
36+
37+
extern debugconf_t debugconf;
38+
39+
/** Used to output messages.
40+
* The messages will include the filename and line number, and will be sent to syslog if so configured in the config file
41+
* @param level Debug level
42+
* @param format... sprintf like format string
3243
*/
3344
#define debug(level, format...) _debug(__FILE__, __LINE__, level, format)
3445

3546
/** @internal */
36-
void _debug(const char *filename, int line, int level, const char *format, ...);
47+
void _debug(const char *, int, int, const char *, ...);
3748

3849
#endif /* _DEBUG_H_ */

0 commit comments

Comments
 (0)