Skip to content

Commit b1a85f6

Browse files
committed
Merge pull request #183 from acv/isolate-debug
Isolate debug from rest of gateway
2 parents b9eb8b3 + 47ce7cc commit b1a85f6

File tree

5 files changed

+50
-25
lines changed

5 files changed

+50
-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
@@ -152,7 +152,6 @@ typedef struct {
152152
char *wdctl_sock; /**< @brief wdctl path to socket */
153153
char *internal_sock; /**< @brief internal path to socket */
154154
int daemon; /**< @brief if daemon > 0, use daemon mode */
155-
int debuglevel; /**< @brief Debug information verbosity */
156155
char *external_interface; /**< @brief External network interface name for
157156
firewall rules */
158157
char *gw_id; /**< @brief ID of the Gateway, sent to central
@@ -174,9 +173,6 @@ typedef struct {
174173
must be re-authenticated */
175174
int checkinterval; /**< @brief Frequency the the client timeout check
176175
thread will run. */
177-
int log_syslog; /**< @brief boolean, wether to log to syslog */
178-
int syslog_facility; /**< @brief facility to use when using syslog for
179-
logging */
180176
int proxy_port; /**< @brief Transparent proxy port (0 to disable) */
181177
char *ssl_certs; /**< @brief Path to SSL certs for auth server
182178
verification */

src/debug.c

Lines changed: 16 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,14 @@
3232
#include <unistd.h>
3333
#include <signal.h>
3434

35-
#include "conf.h"
35+
#include "debug.h"
36+
37+
debugconf_t debugconf = {
38+
.debuglevel = LOG_INFO,
39+
.log_stderr = 1,
40+
.log_syslog = 0,
41+
.syslog_facility = 0
42+
};
3643

3744
/** @internal
3845
Do not use directly, use the debug macro */
@@ -41,40 +48,39 @@ _debug(const char *filename, int line, int level, const char *format, ...)
4148
{
4249
char buf[28];
4350
va_list vlist;
44-
s_config *config = config_get_config();
4551
time_t ts;
4652
sigset_t block_chld;
4753

4854
time(&ts);
4955

50-
if (config->debuglevel >= level) {
56+
if (debugconf.debuglevel >= level) {
5157
sigemptyset(&block_chld);
5258
sigaddset(&block_chld, SIGCHLD);
5359
sigprocmask(SIG_BLOCK, &block_chld, NULL);
5460

5561
if (level <= LOG_WARNING) {
5662
fprintf(stderr, "[%d][%.24s][%u](%s:%d) ", level, ctime_r(&ts, buf), getpid(),
57-
filename, line);
63+
filename, line);
5864
va_start(vlist, format);
5965
vfprintf(stderr, format, vlist);
6066
va_end(vlist);
6167
fputc('\n', stderr);
62-
} else if (!config->daemon) {
68+
} else if (debugconf.log_stderr) {
6369
fprintf(stderr, "[%d][%.24s][%u](%s:%d) ", level, ctime_r(&ts, buf), getpid(),
64-
filename, line);
70+
filename, line);
6571
va_start(vlist, format);
6672
vfprintf(stderr, format, vlist);
6773
va_end(vlist);
6874
fputc('\n', stderr);
6975
}
7076

71-
if (config->log_syslog) {
72-
openlog("wifidog", LOG_PID, config->syslog_facility);
77+
if (debugconf.log_syslog) {
78+
openlog("wifidog", LOG_PID, debugconf.syslog_facility);
7379
va_start(vlist, format);
7480
vsyslog(level, format, vlist);
7581
va_end(vlist);
7682
closelog();
77-
}
83+
}
7884

7985
sigprocmask(SIG_UNBLOCK, &block_chld, NULL);
8086
}

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)