[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
tinc/src logger.c,NONE,1.1.2.1 logger.h,NONE,1.1.2.1 Makefile.am,1.4.4.29,1.4.4.30 conf.c,1.9.4.61,1.9.4.62 conf.h,1.6.4.35,1.6.4.36 connection.c,1.1.2.36,1.1.2.37 edge.c,1.1.2.18,1.1.2.19 graph.c,1.1.2.22,1.1.2.23 meta.c,1.1.2.33,1.1.2.34 net.c,1.35.4.187,1.35.4.188 net_packet.c,1.1.2.30,1.1.2.31 net_setup.c,1.1.2.32,1.1.2.33 net_socket.c,1.1.2.24,1.1.2.25 netutl.c,1.12.4.44,1.12.4.45 node.c,1.1.2.19,1.1.2.20 process.c,1.1.2.50,1.1.2.51 protocol.c,1.28.4.137,1.28.4.138 protocol_auth.c,1.1.4.20,1.1.4.21 protocol_edge.c,1.1.4.15,1.1.4.16 protocol_key.c,1.1.4.16,1.1.4.17 protocol_misc.c,1.1.4.7,1.1.4.8 protocol_subnet.c,1.1.4.9,1.1.4.10 route.c,1.1.2.53,1.1.2.54 subnet.c,1.1.2.43,1.1.2.44 tincd.c,1.10.4.69,1.10.4.70
- To: tinc-cvs@nl.linux.org
- Subject: tinc/src logger.c,NONE,1.1.2.1 logger.h,NONE,1.1.2.1 Makefile.am,1.4.4.29,1.4.4.30 conf.c,1.9.4.61,1.9.4.62 conf.h,1.6.4.35,1.6.4.36 connection.c,1.1.2.36,1.1.2.37 edge.c,1.1.2.18,1.1.2.19 graph.c,1.1.2.22,1.1.2.23 meta.c,1.1.2.33,1.1.2.34 net.c,1.35.4.187,1.35.4.188 net_packet.c,1.1.2.30,1.1.2.31 net_setup.c,1.1.2.32,1.1.2.33 net_socket.c,1.1.2.24,1.1.2.25 netutl.c,1.12.4.44,1.12.4.45 node.c,1.1.2.19,1.1.2.20 process.c,1.1.2.50,1.1.2.51 protocol.c,1.28.4.137,1.28.4.138 protocol_auth.c,1.1.4.20,1.1.4.21 protocol_edge.c,1.1.4.15,1.1.4.16 protocol_key.c,1.1.4.16,1.1.4.17 protocol_misc.c,1.1.4.7,1.1.4.8 protocol_subnet.c,1.1.4.9,1.1.4.10 route.c,1.1.2.53,1.1.2.54 subnet.c,1.1.2.43,1.1.2.44 tincd.c,1.10.4.69,1.10.4.70
- From: Guus Sliepen <guus@nl.linux.org>
- Date: Mon, 7 Jul 2003 00:12:07 +0200
- List-archive: <http://mail.nl.linux.org/tinc-cvs/>
- List-help: <mailto:listar@nl.linux.org?Subject=help>
- List-owner: <mailto:riel@nl.linux.org>
- List-post: <mailto:tinc-cvs@nl.linux.org>
- List-software: Listar version 1.0.0
- List-subscribe: <mailto:tinc-cvs-request@nl.linux.org?Subject=subscribe>
- List-unsubscribe: <mailto:tinc-cvs-request@nl.linux.org?Subject=unsubscribe>
- Original-Recipient: rfc822;tinc-cvs-archive@nl.linux.org
- Reply-to: tinc@nl.linux.org
- Sender: tinc-cvs-bounce@nl.linux.org
Update of /home/CVS/tinc/src
In directory humbolt:/tmp/cvs-serv26197/src
Modified Files:
Tag: CABAL
Makefile.am conf.c conf.h connection.c edge.c graph.c meta.c
net.c net_packet.c net_setup.c net_socket.c netutl.c node.c
process.c protocol.c protocol_auth.c protocol_edge.c
protocol_key.c protocol_misc.c protocol_subnet.c route.c
subnet.c tincd.c
Added Files:
Tag: CABAL
logger.c logger.h
Log Message:
Define logger(), cleans up source code and allows us to write log entries
to a separate file.
***** Error reading new file: [Errno 2] No such file or directory: 'logger.c'
--- NEW FILE logger.h ---
#ifndef __TINC_LOGGER_H__
#include <syslog.h>
#include <stdarg.h>
enum {
DEBUG_NOTHING = 0, /* Quiet mode, only show starting/stopping of the daemon */
DEBUG_ALWAYS = 0,
DEBUG_CONNECTIONS = 1, /* Show (dis)connects of other tinc daemons via TCP */
DEBUG_ERROR = 2, /* Show error messages received from other hosts */
DEBUG_STATUS = 2, /* Show status messages received from other hosts */
DEBUG_PROTOCOL = 3, /* Show the requests that are sent/received */
DEBUG_META = 4, /* Show contents of every request that is sent/received */
DEBUG_TRAFFIC = 5, /* Show network traffic information */
DEBUG_PACKET = 6, /* Show contents of each packet that is being sent/received */
DEBUG_SCARY_THINGS = 10 /* You have been warned */
};
enum {
LOGMODE_NULL,
LOGMODE_STDERR,
LOGMODE_FILE,
LOGMODE_SYSLOG
};
extern volatile int debug_level;
extern void openlogger(const char *, int);
extern void vlogger(int, const char *, va_list ap);
extern void closelogger(void);
/* Inline logger function because it's used quite often */
static inline void logger(int level, int priority, const char *format, ...) {
va_list ap;
if(level == DEBUG_ALWAYS || debug_level >= level) {
va_start(ap, format);
vlogger(priority, format, ap);
va_end(ap);
}
}
#endif /* __TINC_LOGGER_H__ */
Index: Makefile.am
===================================================================
RCS file: /home/CVS/tinc/src/Makefile.am,v
retrieving revision 1.4.4.29
retrieving revision 1.4.4.30
diff -u -r1.4.4.29 -r1.4.4.30
--- Makefile.am 2003/06/07 13:18:31 1.4.4.29
+++ Makefile.am 2003/07/06 22:11:31 1.4.4.30
@@ -5,13 +5,13 @@
EXTRA_DIST = linux/device.c freebsd/device.c openbsd/device.c solaris/device.c netbsd/device.c darwin/device.c cygwin/device.c
-tincd_SOURCES = conf.c connection.c device.c edge.c event.c graph.c meta.c net.c net_packet.c net_setup.c \
+tincd_SOURCES = conf.c connection.c device.c edge.c event.c graph.c logger.c meta.c net.c net_packet.c net_setup.c \
net_socket.c netutl.c node.c process.c protocol.c protocol_auth.c protocol_edge.c protocol_misc.c \
protocol_key.c protocol_subnet.c route.c subnet.c tincd.c
INCLUDES = @INCLUDES@ -I$(top_builddir) -I$(top_srcdir)/lib
-noinst_HEADERS = conf.h connection.h device.h edge.h event.h graph.h meta.h net.h netutl.h node.h process.h \
+noinst_HEADERS = conf.h connection.h device.h edge.h event.h graph.h logger.h meta.h net.h netutl.h node.h process.h \
protocol.h route.h subnet.h
LIBS = @LIBS@ @LIBINTL@
Index: conf.c
===================================================================
RCS file: /home/CVS/tinc/src/Attic/conf.c,v
retrieving revision 1.9.4.61
retrieving revision 1.9.4.62
diff -u -r1.9.4.61 -r1.9.4.62
--- conf.c 2002/09/15 12:26:24 1.9.4.61
+++ conf.c 2003/07/06 22:11:31 1.9.4.62
@@ -30,11 +30,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
-#include <syslog.h>
#include <string.h>
#include <xalloc.h>
@@ -43,12 +41,12 @@
#include "conf.h"
#include "netutl.h" /* for str2address */
+#include "logger.h"
#include "system.h"
avl_tree_t *config_tree;
-int debug_lvl = 0;
int pingtimeout = 0; /* seconds before timeout */
char *confbase = NULL; /* directory in which all config files are */
char *netname = NULL; /* name of the vpn network */
@@ -172,7 +170,7 @@
return 1;
}
- syslog(LOG_ERR, _("\"yes\" or \"no\" expected for configuration variable %s in %s line %d"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("\"yes\" or \"no\" expected for configuration variable %s in %s line %d"),
cfg->variable, cfg->file, cfg->line);
return 0;
@@ -188,7 +186,7 @@
if(sscanf(cfg->value, "%d", result) == 1)
return 1;
- syslog(LOG_ERR, _("Integer expected for configuration variable %s in %s line %d"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Integer expected for configuration variable %s in %s line %d"),
cfg->variable, cfg->file, cfg->line);
return 0;
@@ -222,7 +220,7 @@
return 1;
}
- syslog(LOG_ERR, _("Hostname or IP address expected for configuration variable %s in %s line %d"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Hostname or IP address expected for configuration variable %s in %s line %d"),
cfg->variable, cfg->file, cfg->line);
return 0;
@@ -240,7 +238,7 @@
subnet = str2net(cfg->value);
if(!subnet) {
- syslog(LOG_ERR, _("Subnet expected for configuration variable %s in %s line %d"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Subnet expected for configuration variable %s in %s line %d"),
cfg->variable, cfg->file, cfg->line);
return 0;
}
@@ -251,7 +249,7 @@
&& maskcheck(&subnet->net.ipv4.address, subnet->net.ipv4.prefixlength, sizeof(ipv4_t)))
|| ((subnet->type == SUBNET_IPV6)
&& maskcheck(&subnet->net.ipv6.address, subnet->net.ipv6.prefixlength, sizeof(ipv6_t)))) {
- syslog(LOG_ERR, _ ("Network address and prefix length do not match for configuration variable %s in %s line %d"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _ ("Network address and prefix length do not match for configuration variable %s in %s line %d"),
cfg->variable, cfg->file, cfg->line);
free(subnet);
return 0;
@@ -350,7 +348,7 @@
fp = fopen(fname, "r");
if(!fp) {
- syslog(LOG_ERR, _("Cannot open config file %s: %s"), fname,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Cannot open config file %s: %s"), fname,
strerror(errno));
return -3;
}
@@ -388,7 +386,7 @@
value = strtok(NULL, "\t\n\r =");
if(!value || value[0] == '#') {
- syslog(LOG_ERR, _("No value for variable `%s' on line %d while reading config file %s"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("No value for variable `%s' on line %d while reading config file %s"),
variable, lineno, fname);
break;
}
@@ -423,7 +421,7 @@
x = read_config_file(config_tree, fname);
if(x == -1) { /* System error: complain */
- syslog(LOG_ERR, _("Failed to read `%s': %s"), fname, strerror(errno));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Failed to read `%s': %s"), fname, strerror(errno));
}
free(fname);
@@ -450,7 +448,7 @@
char l[MAXBUFSIZE];
if(*file != '/') {
- syslog(LOG_ERR, _("`%s' is not an absolute path"), file);
+ logger(DEBUG_ALWAYS, LOG_ERR, _("`%s' is not an absolute path"), file);
return 0;
}
@@ -466,21 +464,21 @@
check1:
if(lstat(f, &s) < 0) {
- syslog(LOG_ERR, _("Couldn't stat `%s': %s"), f, strerror(errno));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Couldn't stat `%s': %s"), f, strerror(errno));
return 0;
}
if(s.st_uid != geteuid()) {
- syslog(LOG_ERR, _("`%s' is owned by UID %d instead of %d"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("`%s' is owned by UID %d instead of %d"),
f, s.st_uid, geteuid());
return 0;
}
if(S_ISLNK(s.st_mode)) {
- syslog(LOG_WARNING, _("Warning: `%s' is a symlink"), f);
+ logger(DEBUG_ALWAYS, LOG_WARNING, _("Warning: `%s' is a symlink"), f);
if(readlink(f, l, MAXBUFSIZE) < 0) {
- syslog(LOG_ERR, _("Unable to read symbolic link `%s': %s"), f,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Unable to read symbolic link `%s': %s"), f,
strerror(errno));
return 0;
}
@@ -494,7 +492,7 @@
check2:
if(lstat(f, &s) < 0 && errno != ENOENT) {
- syslog(LOG_ERR, _("Couldn't stat `%s': %s"), f, strerror(errno));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Couldn't stat `%s': %s"), f, strerror(errno));
return 0;
}
@@ -502,16 +500,16 @@
return 1;
if(s.st_uid != geteuid()) {
- syslog(LOG_ERR, _("`%s' is owned by UID %d instead of %d"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("`%s' is owned by UID %d instead of %d"),
f, s.st_uid, geteuid());
return 0;
}
if(S_ISLNK(s.st_mode)) {
- syslog(LOG_WARNING, _("Warning: `%s' is a symlink"), f);
+ logger(DEBUG_ALWAYS, LOG_WARNING, _("Warning: `%s' is a symlink"), f);
if(readlink(f, l, MAXBUFSIZE) < 0) {
- syslog(LOG_ERR, _("Unable to read symbolic link `%s': %s"), f,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Unable to read symbolic link `%s': %s"), f,
strerror(errno));
return 0;
}
@@ -522,7 +520,7 @@
if(s.st_mode & 0007) {
/* Accessible by others */
- syslog(LOG_ERR, _("`%s' has unsecure permissions"), f);
+ logger(DEBUG_ALWAYS, LOG_ERR, _("`%s' has unsecure permissions"), f);
return 0;
}
Index: conf.h
===================================================================
RCS file: /home/CVS/tinc/src/Attic/conf.h,v
retrieving revision 1.6.4.35
retrieving revision 1.6.4.36
diff -u -r1.6.4.35 -r1.6.4.36
--- conf.h 2002/09/15 12:26:24 1.6.4.35
+++ conf.h 2003/07/06 22:11:31 1.6.4.36
@@ -40,7 +40,6 @@
extern avl_tree_t *config_tree;
-extern int debug_lvl;
extern int pingtimeout;
extern int maxtimeout;
extern int bypass_security;
Index: connection.c
===================================================================
RCS file: /home/CVS/tinc/src/Attic/connection.c,v
retrieving revision 1.1.2.36
retrieving revision 1.1.2.37
diff -u -r1.1.2.36 -r1.1.2.37
--- connection.c 2003/06/25 20:55:05 1.1.2.36
+++ connection.c 2003/07/06 22:11:31 1.1.2.37
@@ -23,7 +23,6 @@
#include "config.h"
#include <stdio.h>
-#include <syslog.h>
#include <string.h>
#include <sys/time.h>
@@ -35,6 +34,7 @@
#include "conf.h"
#include <utils.h>
#include "subnet.h"
+#include "logger.h"
#include "xalloc.h"
#include "system.h"
@@ -124,15 +124,15 @@
cp();
- syslog(LOG_DEBUG, _("Connections:"));
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Connections:"));
for(node = connection_tree->head; node; node = node->next) {
c = (connection_t *) node->data;
- syslog(LOG_DEBUG, _(" %s at %s options %lx socket %d status %04x"),
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _(" %s at %s options %lx socket %d status %04x"),
c->name, c->hostname, c->options, c->socket, c->status);
}
- syslog(LOG_DEBUG, _("End of connections."));
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("End of connections."));
}
int read_connection_config(connection_t *c)
Index: edge.c
===================================================================
RCS file: /home/CVS/tinc/src/Attic/edge.c,v
retrieving revision 1.1.2.18
retrieving revision 1.1.2.19
diff -u -r1.1.2.18 -r1.1.2.19
--- edge.c 2002/09/10 22:12:33 1.1.2.18
+++ edge.c 2003/07/06 22:11:31 1.1.2.19
@@ -23,7 +23,6 @@
#include "config.h"
#include <stdio.h>
-#include <syslog.h>
#include <string.h>
#include <avl_tree.h>
@@ -36,6 +35,7 @@
#include "subnet.h"
#include "edge.h"
#include "node.h"
+#include "logger.h"
#include "xalloc.h"
#include "system.h"
@@ -154,18 +154,18 @@
cp();
- syslog(LOG_DEBUG, _("Edges:"));
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Edges:"));
for(node = node_tree->head; node; node = node->next) {
n = (node_t *) node->data;
for(node2 = n->edge_tree->head; node2; node2 = node2->next) {
e = (edge_t *) node2->data;
address = sockaddr2hostname(&e->address);
- syslog(LOG_DEBUG, _(" %s to %s at %s options %lx weight %d"),
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _(" %s to %s at %s options %lx weight %d"),
e->from->name, e->to->name, address, e->options, e->weight);
free(address);
}
}
- syslog(LOG_DEBUG, _("End of edges."));
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("End of edges."));
}
Index: graph.c
===================================================================
RCS file: /home/CVS/tinc/src/Attic/graph.c,v
retrieving revision 1.1.2.22
retrieving revision 1.1.2.23
diff -u -r1.1.2.22 -r1.1.2.23
--- graph.c 2003/01/17 00:37:17 1.1.2.22
+++ graph.c 2003/07/06 22:11:31 1.1.2.23
@@ -47,7 +47,6 @@
#include "config.h"
#include <stdio.h>
-#include <syslog.h>
#include <string.h>
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
@@ -63,6 +62,7 @@
#include "connection.h"
#include "process.h"
#include "device.h"
+#include "logger.h"
#include "system.h"
@@ -95,8 +95,7 @@
if(!edge_weight_tree->head)
return;
- if(debug_lvl >= DEBUG_SCARY_THINGS)
- syslog(LOG_DEBUG, "Running Kruskal's algorithm:");
+ logger(DEBUG_SCARY_THINGS, LOG_DEBUG, "Running Kruskal's algorithm:");
/* Clear visited status on nodes */
@@ -132,8 +131,7 @@
safe_edges++;
- if(debug_lvl >= DEBUG_SCARY_THINGS)
- syslog(LOG_DEBUG, " Adding edge %s - %s weight %d", e->from->name,
+ logger(DEBUG_SCARY_THINGS, LOG_DEBUG, " Adding edge %s - %s weight %d", e->from->name,
e->to->name, e->weight);
if(skipped) {
@@ -143,8 +141,7 @@
}
}
- if(debug_lvl >= DEBUG_SCARY_THINGS)
- syslog(LOG_DEBUG, "Done, counted %d nodes and %d safe edges.", nodes,
+ logger(DEBUG_SCARY_THINGS, LOG_DEBUG, "Done, counted %d nodes and %d safe edges.", nodes,
safe_edges);
}
@@ -262,14 +259,12 @@
if(n->status.visited != n->status.reachable) {
n->status.reachable = !n->status.reachable;
- if(debug_lvl >= DEBUG_TRAFFIC) {
- if(n->status.reachable)
- syslog(LOG_DEBUG, _("Node %s (%s) became reachable"),
- n->name, n->hostname);
- else
- syslog(LOG_DEBUG, _("Node %s (%s) became unreachable"),
- n->name, n->hostname);
- }
+ if(n->status.reachable)
+ logger(DEBUG_TRAFFIC, LOG_DEBUG, _("Node %s (%s) became reachable"),
+ n->name, n->hostname);
+ else
+ logger(DEBUG_TRAFFIC, LOG_DEBUG, _("Node %s (%s) became unreachable"),
+ n->name, n->hostname);
n->status.validkey = 0;
n->status.waitingforkey = 0;
Index: meta.c
===================================================================
RCS file: /home/CVS/tinc/src/meta.c,v
retrieving revision 1.1.2.33
retrieving revision 1.1.2.34
diff -u -r1.1.2.33 -r1.1.2.34
--- meta.c 2003/03/19 11:45:05 1.1.2.33
+++ meta.c 2003/07/06 22:11:31 1.1.2.34
@@ -25,7 +25,6 @@
#include <avl_tree.h>
#include <errno.h>
-#include <syslog.h>
#include <unistd.h>
#include <string.h>
/* This line must be below the rest for FreeBSD */
@@ -38,6 +37,7 @@
#include "connection.h"
#include "system.h"
#include "protocol.h"
+#include "logger.h"
int send_meta(connection_t *c, char *buffer, int length)
{
@@ -48,8 +48,7 @@
cp();
- if(debug_lvl >= DEBUG_META)
- syslog(LOG_DEBUG, _("Sending %d bytes of metadata to %s (%s)"), length,
+ logger(DEBUG_META, LOG_DEBUG, _("Sending %d bytes of metadata to %s (%s)"), length,
c->name, c->hostname);
if(c->status.encryptout) {
@@ -64,7 +63,7 @@
if(result <= 0) {
if(errno == EINTR)
continue;
- syslog(LOG_ERR, _("Sending meta data to %s (%s) failed: %s"), c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Sending meta data to %s (%s) failed: %s"), c->name,
c->hostname, strerror(errno));
return -1;
}
@@ -102,13 +101,13 @@
cp();
if(getsockopt(c->socket, SOL_SOCKET, SO_ERROR, &x, &l) < 0) {
- syslog(LOG_ERR, _("This is a bug: %s:%d: %d:%s %s (%s)"), __FILE__,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("This is a bug: %s:%d: %d:%s %s (%s)"), __FILE__,
__LINE__, c->socket, strerror(errno), c->name, c->hostname);
return -1;
}
if(x) {
- syslog(LOG_ERR, _("Metadata socket error for %s (%s): %s"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Metadata socket error for %s (%s): %s"),
c->name, c->hostname, strerror(x));
return -1;
}
@@ -126,13 +125,12 @@
if(lenin <= 0) {
if(lenin == 0) {
- if(debug_lvl >= DEBUG_CONNECTIONS)
- syslog(LOG_NOTICE, _("Connection closed by %s (%s)"),
+ logger(DEBUG_CONNECTIONS, LOG_NOTICE, _("Connection closed by %s (%s)"),
c->name, c->hostname);
} else if(errno == EINTR)
return 0;
else
- syslog(LOG_ERR, _("Metadata socket read error for %s (%s): %s"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Metadata socket read error for %s (%s): %s"),
c->name, c->hostname, strerror(errno));
return -1;
@@ -195,7 +193,7 @@
}
if(c->buflen >= MAXBUFSIZE) {
- syslog(LOG_ERR, _("Metadata read buffer overflow for %s (%s)"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Metadata read buffer overflow for %s (%s)"),
c->name, c->hostname);
return -1;
}
Index: net.c
===================================================================
RCS file: /home/CVS/tinc/src/net.c,v
retrieving revision 1.35.4.187
retrieving revision 1.35.4.188
diff -u -r1.35.4.187 -r1.35.4.188
--- net.c 2003/07/06 17:15:25 1.35.4.187
+++ net.c 2003/07/06 22:11:32 1.35.4.188
@@ -32,7 +32,6 @@
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
-#include <syslog.h>
#include <unistd.h>
#include <sys/ioctl.h>
/* SunOS really wants sys/socket.h BEFORE net/if.h,
@@ -71,6 +70,7 @@
#include "route.h"
#include "device.h"
#include "event.h"
+#include "logger.h"
#include "system.h"
@@ -91,16 +91,14 @@
cp();
- if(debug_lvl >= DEBUG_PROTOCOL)
- syslog(LOG_DEBUG, _("Purging unreachable nodes"));
+ logger(DEBUG_PROTOCOL, LOG_DEBUG, _("Purging unreachable nodes"));
for(nnode = node_tree->head; nnode; nnode = nnext) {
nnext = nnode->next;
n = (node_t *) nnode->data;
if(!n->status.reachable) {
- if(debug_lvl >= DEBUG_SCARY_THINGS)
- syslog(LOG_DEBUG, _("Purging node %s (%s)"), n->name,
+ logger(DEBUG_SCARY_THINGS, LOG_DEBUG, _("Purging node %s (%s)"), n->name,
n->hostname);
for(snode = n->subnet_tree->head; snode; snode = snext) {
@@ -181,8 +179,7 @@
if(c->status.remove)
return;
- if(debug_lvl >= DEBUG_CONNECTIONS)
- syslog(LOG_NOTICE, _("Closing connection with %s (%s)"),
+ logger(DEBUG_CONNECTIONS, LOG_NOTICE, _("Closing connection with %s (%s)"),
c->name, c->hostname);
c->status.remove = 1;
@@ -235,8 +232,7 @@
if(c->last_ping_time + pingtimeout < now) {
if(c->status.active) {
if(c->status.pinged) {
- if(debug_lvl >= DEBUG_PROTOCOL)
- syslog(LOG_INFO, _("%s (%s) didn't respond to PING"),
+ logger(DEBUG_CONNECTIONS, LOG_INFO, _("%s (%s) didn't respond to PING"),
c->name, c->hostname);
c->status.timeout = 1;
terminate_connection(c, 1);
@@ -245,13 +241,12 @@
}
} else {
if(c->status.remove) {
- syslog(LOG_WARNING, _("Old connection_t for %s (%s) status %04x still lingering, deleting..."),
+ logger(DEBUG_ALWAYS, LOG_WARNING, _("Old connection_t for %s (%s) status %04x still lingering, deleting..."),
c->name, c->hostname, c->status);
connection_del(c);
continue;
}
- if(debug_lvl >= DEBUG_CONNECTIONS)
- syslog(LOG_WARNING, _("Timeout from %s (%s) during authentication"),
+ logger(DEBUG_CONNECTIONS, LOG_WARNING, _("Timeout from %s (%s) during authentication"),
c->name, c->hostname);
terminate_connection(c, 0);
}
@@ -292,8 +287,7 @@
if(!result)
finish_connecting(c);
else {
- if(debug_lvl >= DEBUG_CONNECTIONS)
- syslog(LOG_DEBUG,
+ logger(DEBUG_CONNECTIONS, LOG_DEBUG,
_("Error while connecting to %s (%s): %s"),
c->name, c->hostname, strerror(result));
close(c->socket);
@@ -347,7 +341,7 @@
if(r < 0) {
if(errno != EINTR && errno != EAGAIN) {
- syslog(LOG_ERR, _("Error while waiting for input: %s"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error while waiting for input: %s"),
strerror(errno));
cp_trace();
dump_connections();
@@ -378,8 +372,7 @@
/* Should we regenerate our key? */
if(keyexpires < now) {
- if(debug_lvl >= DEBUG_STATUS)
- syslog(LOG_INFO, _("Regenerating symmetric key"));
+ logger(DEBUG_STATUS, LOG_INFO, _("Regenerating symmetric key"));
RAND_pseudo_bytes(myself->key, myself->keylength);
EVP_DecryptInit_ex(&packet_ctx, myself->cipher, NULL, myself->key, myself->key + myself->cipher->key_len);
@@ -395,7 +388,7 @@
}
if(sigalrm) {
- syslog(LOG_INFO, _("Flushing event queue"));
+ logger(DEBUG_ALWAYS, LOG_INFO, _("Flushing event queue"));
while(event_tree->head) {
event = (event_t *) event_tree->head->data;
@@ -419,7 +412,7 @@
init_configuration(&config_tree);
if(read_server_config()) {
- syslog(LOG_ERR, _("Unable to reread configuration file, exitting."));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Unable to reread configuration file, exitting."));
exit(1);
}
Index: net_packet.c
===================================================================
RCS file: /home/CVS/tinc/src/net_packet.c,v
retrieving revision 1.1.2.30
retrieving revision 1.1.2.31
diff -u -r1.1.2.30 -r1.1.2.31
--- net_packet.c 2003/05/07 11:21:58 1.1.2.30
+++ net_packet.c 2003/07/06 22:11:32 1.1.2.31
@@ -32,7 +32,6 @@
#include <signal.h>
#include <sys/time.h>
#include <sys/types.h>
-#include <syslog.h>
#include <unistd.h>
#include <sys/ioctl.h>
/* SunOS really wants sys/socket.h BEFORE net/if.h,
@@ -76,6 +75,7 @@
#include "route.h"
#include "device.h"
#include "event.h"
+#include "logger.h"
#include "system.h"
@@ -149,8 +149,7 @@
(char *) &inpkt->seqno, inpkt->len, hmac, NULL);
if(memcmp(hmac, (char *) &inpkt->seqno + inpkt->len, myself->maclength)) {
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_DEBUG, _("Got unauthenticated packet from %s (%s)"),
+ logger(DEBUG_TRAFFIC, LOG_DEBUG, _("Got unauthenticated packet from %s (%s)"),
n->name, n->hostname);
return;
}
@@ -179,14 +178,13 @@
if(inpkt->seqno != n->received_seqno + 1) {
if(inpkt->seqno >= n->received_seqno + sizeof(n->late) * 8) {
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_WARNING, _("Lost %d packets from %s (%s)"),
+ logger(DEBUG_ALWAYS, LOG_WARNING, _("Lost %d packets from %s (%s)"),
inpkt->seqno - n->received_seqno - 1, n->name, n->hostname);
memset(n->late, 0, sizeof(n->late));
} else if (inpkt->seqno <= n->received_seqno) {
if(inpkt->seqno <= n->received_seqno - sizeof(n->late) * 8 || !(n->late[(inpkt->seqno / 8) % sizeof(n->late)] & (1 << inpkt->seqno % 8))) {
- syslog(LOG_WARNING, _("Got late or replayed packet from %s (%s), seqno %d, last received %d"),
+ logger(DEBUG_ALWAYS, LOG_WARNING, _("Got late or replayed packet from %s (%s), seqno %d, last received %d"),
n->name, n->hostname, inpkt->seqno, n->received_seqno);
} else
for(i = n->received_seqno + 1; i < inpkt->seqno; i++)
@@ -206,7 +204,7 @@
outpkt = pkt[nextpkt++];
if((outpkt->len = uncompress_packet(outpkt->data, inpkt->data, inpkt->len, myself->compression)) < 0) {
- syslog(LOG_ERR, _("Error while uncompressing packet from %s (%s)"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error while uncompressing packet from %s (%s)"),
n->name, n->hostname);
return;
}
@@ -233,8 +231,7 @@
{
cp();
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_DEBUG, _("Received packet of %d bytes from %s (%s)"),
+ logger(DEBUG_TRAFFIC, LOG_DEBUG, _("Received packet of %d bytes from %s (%s)"),
packet->len, n->name, n->hostname);
route_incoming(n, packet);
@@ -258,8 +255,7 @@
/* Make sure we have a valid key */
if(!n->status.validkey) {
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_INFO,
+ logger(DEBUG_TRAFFIC, LOG_INFO,
_("No valid key known yet for %s (%s), queueing packet"),
n->name, n->hostname);
@@ -290,7 +286,7 @@
outpkt = pkt[nextpkt++];
if((outpkt->len = compress_packet(outpkt->data, inpkt->data, inpkt->len, n->compression)) < 0) {
- syslog(LOG_ERR, _("Error while compressing packet to %s (%s)"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error while compressing packet to %s (%s)"),
n->name, n->hostname);
return;
}
@@ -341,17 +337,15 @@
if(priorityinheritance && origpriority != priority
&& listen_socket[sock].sa.sa.sa_family == AF_INET) {
priority = origpriority;
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_DEBUG, _("Setting outgoing packet priority to %d"),
- priority);
+ logger(DEBUG_TRAFFIC, LOG_DEBUG, _("Setting outgoing packet priority to %d"), priority);
if(setsockopt(listen_socket[sock].udp, SOL_IP, IP_TOS, &priority, sizeof(priority))) /* SO_PRIORITY doesn't seem to work */
- syslog(LOG_ERR, _("System call `%s' failed: %s"), "setsockopt",
+ logger(DEBUG_ALWAYS, LOG_ERR, _("System call `%s' failed: %s"), "setsockopt",
strerror(errno));
}
#endif
if((sendto(listen_socket[sock].udp, (char *) &inpkt->seqno, inpkt->len, 0, &(n->address.sa), SALEN(n->address.sa))) < 0) {
- syslog(LOG_ERR, _("Error sending packet to %s (%s): %s"), n->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error sending packet to %s (%s): %s"), n->name,
n->hostname, strerror(errno));
return;
}
@@ -368,29 +362,24 @@
cp();
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_ERR, _("Sending packet of %d bytes to %s (%s)"),
+ logger(DEBUG_TRAFFIC, LOG_ERR, _("Sending packet of %d bytes to %s (%s)"),
packet->len, n->name, n->hostname);
if(n == myself) {
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_NOTICE, _("Packet is looping back to us!"));
-
+ logger(DEBUG_TRAFFIC, LOG_NOTICE, _("Packet is looping back to us!"));
return;
}
if(!n->status.reachable) {
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_INFO, _("Node %s (%s) is not reachable"),
+ logger(DEBUG_TRAFFIC, LOG_INFO, _("Node %s (%s) is not reachable"),
n->name, n->hostname);
-
return;
}
via = (n->via == myself) ? n->nexthop : n->via;
- if(via != n && debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_ERR, _("Sending packet to %s via %s (%s)"),
+ if(via != n)
+ logger(DEBUG_TRAFFIC, LOG_ERR, _("Sending packet to %s via %s (%s)"),
n->name, via->name, n->via->hostname);
if((myself->options | via->options) & OPTION_TCPONLY) {
@@ -409,8 +398,7 @@
cp();
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_INFO, _("Broadcasting packet of %d bytes from %s (%s)"),
+ logger(DEBUG_TRAFFIC, LOG_INFO, _("Broadcasting packet of %d bytes from %s (%s)"),
packet->len, from->name, from->hostname);
for(node = connection_tree->head; node; node = node->next) {
@@ -427,8 +415,7 @@
cp();
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_INFO, _("Flushing queue for %s (%s)"), n->name, n->hostname);
+ logger(DEBUG_TRAFFIC, LOG_INFO, _("Flushing queue for %s (%s)"), n->name, n->hostname);
for(node = n->queue->head; node; node = next) {
next = node->next;
@@ -449,21 +436,21 @@
cp();
if(getsockopt(sock, SOL_SOCKET, SO_ERROR, &x, &l) < 0) {
- syslog(LOG_ERR, _("This is a bug: %s:%d: %d:%s"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("This is a bug: %s:%d: %d:%s"),
__FILE__, __LINE__, sock, strerror(errno));
cp_trace();
exit(1);
}
if(x) {
- syslog(LOG_ERR, _("Incoming data socket error: %s"), strerror(x));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Incoming data socket error: %s"), strerror(x));
return;
}
pkt.len = recvfrom(sock, (char *) &pkt.seqno, MAXSIZE, 0, &from.sa, &fromlen);
if(pkt.len <= 0) {
- syslog(LOG_ERR, _("Receiving packet failed: %s"), strerror(errno));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Receiving packet failed: %s"), strerror(errno));
return;
}
@@ -473,7 +460,7 @@
if(!n) {
hostname = sockaddr2hostname(&from);
- syslog(LOG_WARNING, _("Received UDP packet from unknown source %s"),
+ logger(DEBUG_ALWAYS, LOG_WARNING, _("Received UDP packet from unknown source %s"),
hostname);
free(hostname);
return;
Index: net_setup.c
===================================================================
RCS file: /home/CVS/tinc/src/net_setup.c,v
retrieving revision 1.1.2.32
retrieving revision 1.1.2.33
diff -u -r1.1.2.32 -r1.1.2.33
--- net_setup.c 2003/06/25 20:52:59 1.1.2.32
+++ net_setup.c 2003/07/06 22:11:32 1.1.2.33
@@ -32,7 +32,6 @@
#include <signal.h>
#include <sys/time.h>
#include <sys/types.h>
-#include <syslog.h>
#include <unistd.h>
#include <sys/ioctl.h>
/* SunOS really wants sys/socket.h BEFORE net/if.h,
@@ -72,6 +71,7 @@
#include "route.h"
#include "device.h"
#include "event.h"
+#include "logger.h"
#include "system.h"
@@ -107,7 +107,7 @@
fp = fopen(fname, "r");
if(!fp) {
- syslog(LOG_ERR, _("Error reading RSA public key file `%s': %s"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error reading RSA public key file `%s': %s"),
fname, strerror(errno));
free(fname);
return -1;
@@ -124,7 +124,7 @@
fp = fopen(fname, "r");
if(!fp) {
- syslog(LOG_ERR, _("Error reading RSA public key file `%s': %s"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error reading RSA public key file `%s': %s"),
fname, strerror(errno));
free(fname);
return -1;
@@ -139,7 +139,7 @@
return 0;
}
- syslog(LOG_ERR, _("Reading RSA public key file `%s' failed: %s"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Reading RSA public key file `%s' failed: %s"),
fname, strerror(errno));
return -1;
} else {
@@ -179,7 +179,7 @@
if(c->rsa_key)
return 0;
- syslog(LOG_ERR, _("No public key for %s specified!"), c->name);
+ logger(DEBUG_ALWAYS, LOG_ERR, _("No public key for %s specified!"), c->name);
return -1;
}
@@ -207,7 +207,7 @@
fp = fopen(fname, "r");
if(!fp) {
- syslog(LOG_ERR, _("Error reading RSA private key file `%s': %s"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error reading RSA private key file `%s': %s"),
fname, strerror(errno));
free(fname);
return -1;
@@ -219,7 +219,7 @@
fclose(fp);
if(!myself->connection->rsa_key) {
- syslog(LOG_ERR, _("Reading RSA private key file `%s' failed: %s"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Reading RSA private key file `%s' failed: %s"),
fname, strerror(errno));
return -1;
}
@@ -256,12 +256,12 @@
myself->connection->protocol_version = PROT_CURRENT;
if(!get_config_string(lookup_config(config_tree, "Name"), &name)) { /* Not acceptable */
- syslog(LOG_ERR, _("Name for tinc daemon required!"));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Name for tinc daemon required!"));
return -1;
}
if(check_id(name)) {
- syslog(LOG_ERR, _("Invalid name for myself!"));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Invalid name for myself!"));
free(name);
return -1;
}
@@ -273,7 +273,7 @@
return -1;
if(read_connection_config(myself->connection)) {
- syslog(LOG_ERR, _("Cannot open host configuration file for myself!"));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Cannot open host configuration file for myself!"));
return -1;
}
@@ -329,7 +329,7 @@
else if(!strcasecmp(mode, "hub"))
routing_mode = RMODE_HUB;
else {
- syslog(LOG_ERR, _("Invalid routing mode!"));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Invalid routing mode!"));
return -1;
}
free(mode);
@@ -340,7 +340,7 @@
&priorityinheritance);
#if !defined(SOL_IP) || !defined(IP_TOS)
if(priorityinheritance)
- syslog(LOG_WARNING, _("PriorityInheritance not supported on this platform"));
+ logger(DEBUG_ALWAYS, LOG_WARNING, _("PriorityInheritance not supported on this platform"));
#endif
if(!get_config_int(lookup_config(config_tree, "MACExpire"), &macexpire))
@@ -350,7 +350,7 @@
(lookup_config(myself->connection->config_tree, "MaxTimeout"),
&maxtimeout)) {
if(maxtimeout <= 0) {
- syslog(LOG_ERR, _("Bogus maximum timeout!"));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Bogus maximum timeout!"));
return -1;
}
} else
@@ -364,7 +364,7 @@
else if(!strcasecmp(afname, "any"))
addressfamily = AF_UNSPEC;
else {
- syslog(LOG_ERR, _("Invalid address family!"));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Invalid address family!"));
return -1;
}
free(afname);
@@ -382,7 +382,7 @@
myself->cipher = EVP_get_cipherbyname(cipher);
if(!myself->cipher) {
- syslog(LOG_ERR, _("Unrecognized cipher type!"));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Unrecognized cipher type!"));
return -1;
}
}
@@ -417,7 +417,7 @@
myself->digest = EVP_get_digestbyname(digest);
if(!myself->digest) {
- syslog(LOG_ERR, _("Unrecognized digest type!"));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Unrecognized digest type!"));
return -1;
}
}
@@ -431,10 +431,10 @@
&myself->maclength)) {
if(myself->digest) {
if(myself->maclength > myself->digest->md_size) {
- syslog(LOG_ERR, _("MAC length exceeds size of digest!"));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("MAC length exceeds size of digest!"));
return -1;
} else if(myself->maclength < 0) {
- syslog(LOG_ERR, _("Bogus MAC length!"));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Bogus MAC length!"));
return -1;
}
}
@@ -449,7 +449,7 @@
(lookup_config(myself->connection->config_tree, "Compression"),
&myself->compression)) {
if(myself->compression < 0 || myself->compression > 11) {
- syslog(LOG_ERR, _("Bogus compression level!"));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Bogus compression level!"));
return -1;
}
} else
@@ -481,7 +481,7 @@
err = getaddrinfo(address, myport, &hint, &ai);
if(err || !ai) {
- syslog(LOG_ERR, _("System call `%s' failed: %s"), "getaddrinfo",
+ logger(DEBUG_ALWAYS, LOG_ERR, _("System call `%s' failed: %s"), "getaddrinfo",
gai_strerror(err));
return -1;
}
@@ -501,9 +501,9 @@
if(listen_socket[listen_sockets].udp < 0)
continue;
- if(debug_lvl >= DEBUG_CONNECTIONS) {
+ if(debug_level >= DEBUG_CONNECTIONS) {
hostname = sockaddr2hostname((sockaddr_t *) aip->ai_addr);
- syslog(LOG_NOTICE, _("Listening on %s"), hostname);
+ logger(DEBUG_ALWAYS, LOG_NOTICE, _("Listening on %s"), hostname);
free(hostname);
}
@@ -514,9 +514,9 @@
freeaddrinfo(ai);
if(listen_sockets)
- syslog(LOG_NOTICE, _("Ready"));
+ logger(DEBUG_ALWAYS, LOG_NOTICE, _("Ready"));
else {
- syslog(LOG_ERR, _("Unable to create any listening socket!"));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Unable to create any listening socket!"));
return -1;
}
Index: net_socket.c
===================================================================
RCS file: /home/CVS/tinc/src/net_socket.c,v
retrieving revision 1.1.2.24
retrieving revision 1.1.2.25
diff -u -r1.1.2.24 -r1.1.2.25
--- net_socket.c 2003/06/11 19:27:35 1.1.2.24
+++ net_socket.c 2003/07/06 22:11:32 1.1.2.25
@@ -32,7 +32,6 @@
#include <signal.h>
#include <sys/time.h>
#include <sys/types.h>
-#include <syslog.h>
#include <unistd.h>
#include <sys/ioctl.h>
/* SunOS really wants sys/socket.h BEFORE net/if.h,
@@ -68,6 +67,7 @@
#include "route.h"
#include "device.h"
#include "event.h"
+#include "logger.h"
#include "system.h"
@@ -99,7 +99,7 @@
nfd = socket(sa->sa.sa_family, SOCK_STREAM, IPPROTO_TCP);
if(nfd < 0) {
- syslog(LOG_ERR, _("Creating metasocket failed: %s"), strerror(errno));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Creating metasocket failed: %s"), strerror(errno));
return -1;
}
@@ -107,7 +107,7 @@
if(fcntl(nfd, F_SETFL, flags | O_NONBLOCK) < 0) {
close(nfd);
- syslog(LOG_ERR, _("System call `%s' failed: %s"), "fcntl",
+ logger(DEBUG_ALWAYS, LOG_ERR, _("System call `%s' failed: %s"), "fcntl",
strerror(errno));
return -1;
}
@@ -134,19 +134,19 @@
if(setsockopt(nfd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr))) {
close(nfd);
- syslog(LOG_ERR, _("Can't bind to interface %s: %s"), interface,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Can't bind to interface %s: %s"), interface,
strerror(errno));
return -1;
}
#else
- syslog(LOG_WARNING, _("BindToInterface not supported on this platform"));
+ logger(DEBUG_ALWAYS, LOG_WARNING, _("BindToInterface not supported on this platform"));
#endif
}
if(bind(nfd, &sa->sa, SALEN(sa->sa))) {
close(nfd);
addrstr = sockaddr2hostname(sa);
- syslog(LOG_ERR, _("Can't bind to %s/tcp: %s"), addrstr,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Can't bind to %s/tcp: %s"), addrstr,
strerror(errno));
free(addrstr);
return -1;
@@ -154,7 +154,7 @@
if(listen(nfd, 3)) {
close(nfd);
- syslog(LOG_ERR, _("System call `%s' failed: %s"), "listen",
+ logger(DEBUG_ALWAYS, LOG_ERR, _("System call `%s' failed: %s"), "listen",
strerror(errno));
return -1;
}
@@ -177,14 +177,14 @@
nfd = socket(sa->sa.sa_family, SOCK_DGRAM, IPPROTO_UDP);
if(nfd < 0) {
- syslog(LOG_ERR, _("Creating UDP socket failed: %s"), strerror(errno));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Creating UDP socket failed: %s"), strerror(errno));
return -1;
}
flags = fcntl(nfd, F_GETFL);
if(fcntl(nfd, F_SETFL, flags | O_NONBLOCK) < 0) {
close(nfd);
- syslog(LOG_ERR, _("System call `%s' failed: %s"), "fcntl",
+ logger(DEBUG_ALWAYS, LOG_ERR, _("System call `%s' failed: %s"), "fcntl",
strerror(errno));
return -1;
}
@@ -200,7 +200,7 @@
if(setsockopt(nfd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr))) {
close(nfd);
- syslog(LOG_ERR, _("Can't bind to interface %s: %s"), interface,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Can't bind to interface %s: %s"), interface,
strerror(errno));
return -1;
}
@@ -210,7 +210,7 @@
if(bind(nfd, &sa->sa, SALEN(sa->sa))) {
close(nfd);
addrstr = sockaddr2hostname(sa);
- syslog(LOG_ERR, _("Can't bind to %s/udp: %s"), addrstr,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Can't bind to %s/udp: %s"), addrstr,
strerror(errno));
free(addrstr);
return -1;
@@ -236,8 +236,7 @@
event->data = outgoing;
event_add(event);
- if(debug_lvl >= DEBUG_CONNECTIONS)
- syslog(LOG_NOTICE,
+ logger(DEBUG_CONNECTIONS, LOG_NOTICE,
_("Trying to re-establish outgoing connection in %d seconds"),
outgoing->timeout);
}
@@ -246,8 +245,7 @@
{
cp();
- if(debug_lvl >= DEBUG_CONNECTIONS)
- syslog(LOG_INFO, _("Connected to %s (%s)"), c->name, c->hostname);
+ logger(DEBUG_CONNECTIONS, LOG_INFO, _("Connected to %s (%s)"), c->name, c->hostname);
c->last_ping_time = now;
@@ -264,8 +262,7 @@
begin:
if(!c->outgoing->ai) {
if(!c->outgoing->cfg) {
- if(debug_lvl >= DEBUG_CONNECTIONS)
- syslog(LOG_ERR, _("Could not set up a meta connection to %s"),
+ logger(DEBUG_CONNECTIONS, LOG_ERR, _("Could not set up a meta connection to %s"),
c->name);
c->status.remove = 1;
retry_outgoing(c->outgoing);
@@ -300,15 +297,13 @@
c->hostname = sockaddr2hostname(&c->address);
- if(debug_lvl >= DEBUG_CONNECTIONS)
- syslog(LOG_INFO, _("Trying to connect to %s (%s)"), c->name,
+ logger(DEBUG_CONNECTIONS, LOG_INFO, _("Trying to connect to %s (%s)"), c->name,
c->hostname);
c->socket = socket(c->address.sa.sa_family, SOCK_STREAM, IPPROTO_TCP);
if(c->socket == -1) {
- if(debug_lvl >= DEBUG_CONNECTIONS)
- syslog(LOG_ERR, _("Creating socket for %s failed: %s"), c->hostname,
+ logger(DEBUG_CONNECTIONS, LOG_ERR, _("Creating socket for %s failed: %s"), c->hostname,
strerror(errno));
goto begin;
@@ -331,7 +326,7 @@
flags = fcntl(c->socket, F_GETFL);
if(fcntl(c->socket, F_SETFL, flags | O_NONBLOCK) < 0) {
- syslog(LOG_ERR, _("fcntl for %s: %s"), c->hostname, strerror(errno));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("fcntl for %s: %s"), c->hostname, strerror(errno));
}
/* Connect */
@@ -346,8 +341,7 @@
close(c->socket);
- if(debug_lvl >= DEBUG_CONNECTIONS)
- syslog(LOG_ERR, _("%s: %s"), c->hostname, strerror(errno));
+ logger(DEBUG_CONNECTIONS, LOG_ERR, _("%s: %s"), c->hostname, strerror(errno));
goto begin;
}
@@ -368,8 +362,7 @@
if(n)
if(n->connection) {
- if(debug_lvl >= DEBUG_CONNECTIONS)
- syslog(LOG_INFO, _("Already connected to %s"), outgoing->name);
+ logger(DEBUG_CONNECTIONS, LOG_INFO, _("Already connected to %s"), outgoing->name);
n->connection->outgoing = outgoing;
return;
@@ -388,7 +381,7 @@
outgoing->cfg = lookup_config(c->config_tree, "Address");
if(!outgoing->cfg) {
- syslog(LOG_ERR, _("No address specified for %s"), c->name);
+ logger(DEBUG_ALWAYS, LOG_ERR, _("No address specified for %s"), c->name);
free_connection(c);
free(outgoing->name);
free(outgoing);
@@ -418,7 +411,7 @@
fd = accept(sock, &sa.sa, &len);
if(fd < 0) {
- syslog(LOG_ERR, _("Accepting a new connection failed: %s"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Accepting a new connection failed: %s"),
strerror(errno));
return -1;
}
@@ -436,8 +429,7 @@
c->socket = fd;
c->last_ping_time = now;
- if(debug_lvl >= DEBUG_CONNECTIONS)
- syslog(LOG_NOTICE, _("Connection from %s"), c->hostname);
+ logger(DEBUG_CONNECTIONS, LOG_NOTICE, _("Connection from %s"), c->hostname);
connection_add(c);
@@ -460,7 +452,7 @@
get_config_string(cfg, &name);
if(check_id(name)) {
- syslog(LOG_ERR,
+ logger(DEBUG_ALWAYS, LOG_ERR,
_("Invalid name for outgoing connection in %s line %d"),
cfg->file, cfg->line);
free(name);
Index: netutl.c
===================================================================
RCS file: /home/CVS/tinc/src/Attic/netutl.c,v
retrieving revision 1.12.4.44
retrieving revision 1.12.4.45
diff -u -r1.12.4.44 -r1.12.4.45
--- netutl.c 2002/09/09 22:32:44 1.12.4.44
+++ netutl.c 2003/07/06 22:11:32 1.12.4.45
@@ -33,7 +33,6 @@
#include <string.h>
#include <signal.h>
#include <sys/socket.h>
-#include <syslog.h>
#include <arpa/inet.h>
#include <utils.h>
@@ -43,6 +42,7 @@
#include "conf.h"
#include "net.h"
#include "netutl.h"
+#include "logger.h"
#include "system.h"
@@ -67,10 +67,8 @@
err = getaddrinfo(address, service, &hint, &ai);
if(err) {
- if(debug_lvl >= DEBUG_ERROR)
- syslog(LOG_WARNING, _("Error looking up %s port %s: %s\n"), address,
+ logger(DEBUG_ALWAYS, LOG_WARNING, _("Error looking up %s port %s: %s\n"), address,
service, gai_strerror(err));
- cp_trace();
return NULL;
}
@@ -94,7 +92,7 @@
err = getaddrinfo(address, port, &hint, &ai);
if(err || !ai) {
- syslog(LOG_ERR, _("Error looking up %s port %s: %s\n"), address, port,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error looking up %s port %s: %s\n"), address, port,
gai_strerror(err));
cp_trace();
raise(SIGFPE);
@@ -119,7 +117,7 @@
err = getnameinfo(&sa->sa, SALEN(sa->sa), address, sizeof(address), port, sizeof(port), NI_NUMERICHOST | NI_NUMERICSERV);
if(err) {
- syslog(LOG_ERR, _("Error while translating addresses: %s"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error while translating addresses: %s"),
gai_strerror(err));
cp_trace();
raise(SIGFPE);
@@ -147,7 +145,7 @@
err = getnameinfo(&sa->sa, SALEN(sa->sa), address, sizeof(address), port, sizeof(port),
hostnames ? 0 : (NI_NUMERICHOST | NI_NUMERICSERV));
if(err) {
- syslog(LOG_ERR, _("Error while looking up hostname: %s"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error while looking up hostname: %s"),
gai_strerror(err));
}
@@ -188,7 +186,7 @@
return memcmp(&a->in6.sin6_port, &b->in6.sin6_port, sizeof(a->in6.sin6_port));
default:
- syslog(LOG_ERR, _("sockaddrcmp() was called with unknown address family %d, exitting!"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("sockaddrcmp() was called with unknown address family %d, exitting!"),
a->sa.sa_family);
cp_trace();
raise(SIGFPE);
Index: node.c
===================================================================
RCS file: /home/CVS/tinc/src/Attic/node.c,v
retrieving revision 1.1.2.19
retrieving revision 1.1.2.20
diff -u -r1.1.2.19 -r1.1.2.20
--- node.c 2003/05/06 21:13:17 1.1.2.19
+++ node.c 2003/07/06 22:11:32 1.1.2.20
@@ -23,12 +23,13 @@
#include "config.h"
#include <string.h>
-#include <syslog.h>
#include <avl_tree.h>
#include "node.h"
#include "netutl.h"
#include "net.h"
+#include "logger.h"
+
#include <utils.h>
#include <xalloc.h>
@@ -172,16 +173,16 @@
cp();
- syslog(LOG_DEBUG, _("Nodes:"));
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Nodes:"));
for(node = node_tree->head; node; node = node->next) {
n = (node_t *) node->data;
- syslog(LOG_DEBUG, _(" %s at %s cipher %d digest %d maclength %d compression %d options %lx status %04x nexthop %s via %s"),
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _(" %s at %s cipher %d digest %d maclength %d compression %d options %lx status %04x nexthop %s via %s"),
n->name, n->hostname, n->cipher ? n->cipher->nid : 0,
n->digest ? n->digest->type : 0, n->maclength, n->compression,
n->options, n->status, n->nexthop ? n->nexthop->name : "-",
n->via ? n->via->name : "-");
}
- syslog(LOG_DEBUG, _("End of nodes."));
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("End of nodes."));
}
Index: process.c
===================================================================
RCS file: /home/CVS/tinc/src/process.c,v
retrieving revision 1.1.2.50
retrieving revision 1.1.2.51
diff -u -r1.1.2.50 -r1.1.2.51
--- process.c 2002/09/30 19:04:37 1.1.2.50
+++ process.c 2003/07/06 22:11:32 1.1.2.51
@@ -27,7 +27,6 @@
#include <signal.h>
#include <stdio.h>
#include <string.h>
-#include <syslog.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -46,6 +45,7 @@
#include "device.h"
#include "connection.h"
#include "device.h"
+#include "logger.h"
#include "system.h"
@@ -55,10 +55,11 @@
extern char *identname;
extern char *pidfilename;
extern char **g_argv;
+extern int use_logfile;
sigset_t emptysigset;
-static int saved_debug_lvl = -1;
+static int saved_debug_level = -1;
extern int sighup;
extern int sigalrm;
@@ -66,7 +67,7 @@
void memory_full(int size)
{
- syslog(LOG_ERR, _("Memory exhausted (couldn't allocate %d bytes), exitting."), size);
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Memory exhausted (couldn't allocate %d bytes), exitting."), size);
cp_trace();
exit(1);
}
@@ -95,10 +96,10 @@
close_network_connections();
- if(debug_lvl > DEBUG_NOTHING)
+ if(debug_level > DEBUG_NOTHING)
dump_device_stats();
- syslog(LOG_NOTICE, _("Terminating"));
+ logger(DEBUG_ALWAYS, LOG_NOTICE, _("Terminating"));
closelog();
exit(c);
@@ -199,13 +200,10 @@
return -1;
}
- openlog(identname, LOG_CONS | LOG_PID, LOG_DAEMON);
+ openlogger(identname, use_logfile?LOGMODE_FILE:(do_detach?LOGMODE_SYSLOG:LOGMODE_STDERR));
- if(debug_lvl > DEBUG_NOTHING)
- syslog(LOG_NOTICE, _("tincd %s (%s %s) starting, debug level %d"),
- VERSION, __DATE__, __TIME__, debug_lvl);
- else
- syslog(LOG_NOTICE, _("tincd %s starting"), VERSION);
+ logger(DEBUG_ALWAYS, LOG_NOTICE, _("tincd %s (%s %s) starting, debug level %d"),
+ VERSION, __DATE__, __TIME__, debug_level);
xalloc_fail_func = memory_full;
@@ -213,8 +211,7 @@
}
/*
- Execute the program name, with sane environment. All output will be
- redirected to syslog.
+ Execute the program name, with sane environment.
*/
void _execute_script(const char *scriptname, char **envp)
__attribute__ ((noreturn));
@@ -227,15 +224,16 @@
chdir("/");
+ closelogger();
+
/* Close all file descriptors */
- closelog(); /* <- this means we cannot use syslog() here anymore! */
fcloseall();
execl(scriptname, NULL);
/* No return on success */
- openlog("tinc", LOG_CONS | LOG_PID, LOG_DAEMON);
- syslog(LOG_ERR, _("Could not execute `%s': %s"), scriptname,
+ openlogger(identname, use_logfile?LOGMODE_FILE:(do_detach?LOGMODE_SYSLOG:LOGMODE_STDERR));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Could not execute `%s': %s"), scriptname,
strerror(errno));
exit(errno);
}
@@ -262,37 +260,35 @@
pid = fork();
if(pid < 0) {
- syslog(LOG_ERR, _("System call `%s' failed: %s"), "fork",
+ logger(DEBUG_ALWAYS, LOG_ERR, _("System call `%s' failed: %s"), "fork",
strerror(errno));
return -1;
}
if(pid) {
- if(debug_lvl >= DEBUG_STATUS)
- syslog(LOG_INFO, _("Executing script %s"), name);
+ logger(DEBUG_STATUS, LOG_INFO, _("Executing script %s"), name);
free(scriptname);
if(waitpid(pid, &status, 0) == pid) {
if(WIFEXITED(status)) { /* Child exited by itself */
if(WEXITSTATUS(status)) {
- syslog(LOG_ERR, _("Process %d (%s) exited with non-zero status %d"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Process %d (%s) exited with non-zero status %d"),
pid, name, WEXITSTATUS(status));
return -1;
} else
return 0;
} else if(WIFSIGNALED(status)) { /* Child was killed by a signal */
- syslog(LOG_ERR, _("Process %d (%s) was killed by signal %d (%s)"), pid,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Process %d (%s) was killed by signal %d (%s)"), pid,
name, WTERMSIG(status), strsignal(WTERMSIG(status)));
return -1;
} else { /* Something strange happened */
-
- syslog(LOG_ERR, _("Process %d (%s) terminated abnormally"), pid,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Process %d (%s) terminated abnormally"), pid,
name);
return -1;
}
} else {
- syslog(LOG_ERR, _("System call `%s' failed: %s"), "waitpid",
+ logger(DEBUG_ALWAYS, LOG_ERR, _("System call `%s' failed: %s"), "waitpid",
strerror(errno));
return -1;
}
@@ -310,22 +306,20 @@
RETSIGTYPE sigterm_handler(int a)
{
- if(debug_lvl > DEBUG_NOTHING)
- syslog(LOG_NOTICE, _("Got TERM signal"));
+ logger(DEBUG_ALWAYS, LOG_NOTICE, _("Got TERM signal"));
cleanup_and_exit(0);
}
RETSIGTYPE sigquit_handler(int a)
{
- if(debug_lvl > DEBUG_NOTHING)
- syslog(LOG_NOTICE, _("Got QUIT signal"));
+ logger(DEBUG_ALWAYS, LOG_NOTICE, _("Got QUIT signal"));
cleanup_and_exit(0);
}
RETSIGTYPE fatal_signal_square(int a)
{
- syslog(LOG_ERR, _("Got another fatal signal %d (%s): not restarting."), a,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got another fatal signal %d (%s): not restarting."), a,
strsignal(a));
cp_trace();
exit(1);
@@ -334,11 +328,11 @@
RETSIGTYPE fatal_signal_handler(int a)
{
struct sigaction act;
- syslog(LOG_ERR, _("Got fatal signal %d (%s)"), a, strsignal(a));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got fatal signal %d (%s)"), a, strsignal(a));
cp_trace();
if(do_detach) {
- syslog(LOG_NOTICE, _("Trying to re-execute in 5 seconds..."));
+ logger(DEBUG_ALWAYS, LOG_NOTICE, _("Trying to re-execute in 5 seconds..."));
act.sa_handler = fatal_signal_square;
act.sa_mask = emptysigset;
@@ -350,37 +344,36 @@
remove_pid(pidfilename);
execvp(g_argv[0], g_argv);
} else {
- syslog(LOG_NOTICE, _("Not restarting."));
+ logger(DEBUG_ALWAYS, LOG_NOTICE, _("Not restarting."));
exit(1);
}
}
RETSIGTYPE sighup_handler(int a)
{
- if(debug_lvl > DEBUG_NOTHING)
- syslog(LOG_NOTICE, _("Got HUP signal"));
+ logger(DEBUG_ALWAYS, LOG_NOTICE, _("Got HUP signal"));
sighup = 1;
}
RETSIGTYPE sigint_handler(int a)
{
- if(saved_debug_lvl != -1) {
- syslog(LOG_NOTICE, _("Reverting to old debug level (%d)"),
- saved_debug_lvl);
- debug_lvl = saved_debug_lvl;
- saved_debug_lvl = -1;
+ if(saved_debug_level != -1) {
+ logger(DEBUG_ALWAYS, LOG_NOTICE, _("Reverting to old debug level (%d)"),
+ saved_debug_level);
+ debug_level = saved_debug_level;
+ saved_debug_level = -1;
} else {
- syslog(LOG_NOTICE, _("Temporarily setting debug level to 5. Kill me with SIGINT again to go back to level %d."),
- debug_lvl);
- saved_debug_lvl = debug_lvl;
- debug_lvl = 5;
+ logger(DEBUG_ALWAYS, LOG_NOTICE,
+ _("Temporarily setting debug level to 5. Kill me with SIGINT again to go back to level %d."),
+ debug_level);
+ saved_debug_level = debug_level;
+ debug_level = 5;
}
}
RETSIGTYPE sigalrm_handler(int a)
{
- if(debug_lvl > DEBUG_NOTHING)
- syslog(LOG_NOTICE, _("Got ALRM signal"));
+ logger(DEBUG_ALWAYS, LOG_NOTICE, _("Got ALRM signal"));
sigalrm = 1;
}
@@ -405,16 +398,13 @@
RETSIGTYPE unexpected_signal_handler(int a)
{
- syslog(LOG_WARNING, _("Got unexpected signal %d (%s)"), a, strsignal(a));
+ logger(DEBUG_ALWAYS, LOG_WARNING, _("Got unexpected signal %d (%s)"), a, strsignal(a));
cp_trace();
}
RETSIGTYPE ignore_signal_handler(int a)
{
- if(debug_lvl >= DEBUG_SCARY_THINGS) {
- syslog(LOG_DEBUG, _("Ignored signal %d (%s)"), a, strsignal(a));
- cp_trace();
- }
+ logger(DEBUG_SCARY_THINGS, LOG_DEBUG, _("Ignored signal %d (%s)"), a, strsignal(a));
}
struct {
Index: protocol.c
===================================================================
RCS file: /home/CVS/tinc/src/protocol.c,v
retrieving revision 1.28.4.137
retrieving revision 1.28.4.138
diff -u -r1.28.4.137 -r1.28.4.138
--- protocol.c 2002/09/09 22:32:49 1.28.4.137
+++ protocol.c 2003/07/06 22:11:32 1.28.4.138
@@ -26,7 +26,6 @@
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <stdio.h>
#include <stdarg.h>
#include <errno.h>
@@ -38,6 +37,7 @@
#include "protocol.h"
#include "meta.h"
#include "connection.h"
+#include "logger.h"
#include "system.h"
@@ -74,18 +74,18 @@
va_end(args);
if(len < 0 || len > MAXBUFSIZE - 1) {
- syslog(LOG_ERR, _("Output buffer overflow while sending request to %s (%s)"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Output buffer overflow while sending request to %s (%s)"),
c->name, c->hostname);
return -1;
}
- if(debug_lvl >= DEBUG_PROTOCOL) {
+ if(debug_level >= DEBUG_PROTOCOL) {
sscanf(buffer, "%d", &request);
- if(debug_lvl >= DEBUG_META)
- syslog(LOG_DEBUG, _("Sending %s to %s (%s): %s"),
+ if(debug_level >= DEBUG_META)
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Sending %s to %s (%s): %s"),
request_name[request], c->name, c->hostname, buffer);
else
- syslog(LOG_DEBUG, _("Sending %s to %s (%s)"), request_name[request],
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Sending %s to %s (%s)"), request_name[request],
c->name, c->hostname);
}
@@ -104,14 +104,14 @@
cp();
- if(debug_lvl >= DEBUG_PROTOCOL) {
+ if(debug_level >= DEBUG_PROTOCOL) {
sscanf(from->buffer, "%d", &request);
- if(debug_lvl >= DEBUG_META)
- syslog(LOG_DEBUG, _("Forwarding %s from %s (%s): %s"),
+ if(debug_level >= DEBUG_META)
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Forwarding %s from %s (%s): %s"),
request_name[request], from->name, from->hostname,
from->buffer);
else
- syslog(LOG_DEBUG, _("Forwarding %s from %s (%s)"),
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Forwarding %s from %s (%s)"),
request_name[request], from->name, from->hostname);
}
@@ -128,28 +128,28 @@
if(sscanf(c->buffer, "%d", &request) == 1) {
if((request < 0) || (request >= LAST) || !request_handlers[request]) {
- if(debug_lvl >= DEBUG_META)
- syslog(LOG_DEBUG, _("Unknown request from %s (%s): %s"),
+ if(debug_level >= DEBUG_META)
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Unknown request from %s (%s): %s"),
c->name, c->hostname, c->buffer);
else
- syslog(LOG_ERR, _("Unknown request from %s (%s)"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Unknown request from %s (%s)"),
c->name, c->hostname);
return -1;
} else {
- if(debug_lvl >= DEBUG_PROTOCOL) {
- if(debug_lvl >= DEBUG_META)
- syslog(LOG_DEBUG, _("Got %s from %s (%s): %s"),
+ if(debug_level >= DEBUG_PROTOCOL) {
+ if(debug_level >= DEBUG_META)
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Got %s from %s (%s): %s"),
request_name[request], c->name, c->hostname,
c->buffer);
else
- syslog(LOG_DEBUG, _("Got %s from %s (%s)"),
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Got %s from %s (%s)"),
request_name[request], c->name, c->hostname);
}
}
if((c->allow_request != ALL) && (c->allow_request != request)) {
- syslog(LOG_ERR, _("Unauthorized request from %s (%s)"), c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Unauthorized request from %s (%s)"), c->name,
c->hostname);
return -1;
}
@@ -157,12 +157,12 @@
if(request_handlers[request] (c))
/* Something went wrong. Probably scriptkiddies. Terminate. */
{
- syslog(LOG_ERR, _("Error while processing %s from %s (%s)"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error while processing %s from %s (%s)"),
request_name[request], c->name, c->hostname);
return -1;
}
} else {
- syslog(LOG_ERR, _("Bogus data received from %s (%s)"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Bogus data received from %s (%s)"),
c->name, c->hostname);
return -1;
}
@@ -208,8 +208,7 @@
p.request = request;
if(avl_search(past_request_tree, &p)) {
- if(debug_lvl >= DEBUG_SCARY_THINGS)
- syslog(LOG_DEBUG, _("Already seen request"));
+ logger(DEBUG_SCARY_THINGS, LOG_DEBUG, _("Already seen request"));
return 1;
} else {
new = (past_request_t *) xmalloc(sizeof(*new));
@@ -238,8 +237,8 @@
left++;
}
- if(debug_lvl >= DEBUG_SCARY_THINGS && left + deleted)
- syslog(LOG_DEBUG, _("Aging past requests: deleted %d, left %d\n"),
+ if(left || deleted)
+ logger(DEBUG_SCARY_THINGS, LOG_DEBUG, _("Aging past requests: deleted %d, left %d\n"),
deleted, left);
}
Index: protocol_auth.c
===================================================================
RCS file: /home/CVS/tinc/src/protocol_auth.c,v
retrieving revision 1.1.4.20
retrieving revision 1.1.4.21
diff -u -r1.1.4.20 -r1.1.4.21
--- protocol_auth.c 2003/07/06 17:15:25 1.1.4.20
+++ protocol_auth.c 2003/07/06 22:11:32 1.1.4.21
@@ -24,7 +24,6 @@
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <stdio.h>
#include <stdarg.h>
#include <errno.h>
@@ -46,6 +45,7 @@
#include "node.h"
#include "edge.h"
#include "graph.h"
+#include "logger.h"
#include "system.h"
@@ -65,7 +65,7 @@
cp();
if(sscanf(c->buffer, "%*d " MAX_STRING " %d", name, &c->protocol_version) != 2) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "ID", c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s)"), "ID", c->name,
c->hostname);
return -1;
}
@@ -73,7 +73,7 @@
/* Check if identity is a valid name */
if(check_id(name)) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s): %s"), "ID", c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s): %s"), "ID", c->name,
c->hostname, "invalid name");
return -1;
}
@@ -82,7 +82,7 @@
if(c->name) {
if(strcmp(c->name, name)) {
- syslog(LOG_ERR, _("Peer %s is %s instead of %s"), c->hostname, name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Peer %s is %s instead of %s"), c->hostname, name,
c->name);
return -1;
}
@@ -92,7 +92,7 @@
/* Check if version matches */
if(c->protocol_version != myself->connection->protocol_version) {
- syslog(LOG_ERR, _("Peer %s (%s) uses incompatible version %d"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Peer %s (%s) uses incompatible version %d"),
c->name, c->hostname, c->protocol_version);
return -1;
}
@@ -110,7 +110,7 @@
bla = read_connection_config(c);
if(bla) {
- syslog(LOG_ERR, _("Peer %s had unknown identity (%s)"), c->hostname,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Peer %s had unknown identity (%s)"), c->hostname,
c->name);
return -1;
}
@@ -166,10 +166,10 @@
c->outkey[0] &= 0x7F;
- if(debug_lvl >= DEBUG_SCARY_THINGS) {
+ if(debug_level >= DEBUG_SCARY_THINGS) {
bin2hex(c->outkey, buffer, len);
buffer[len * 2] = '\0';
- syslog(LOG_DEBUG, _("Generated random meta key (unencrypted): %s"),
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Generated random meta key (unencrypted): %s"),
buffer);
}
@@ -181,7 +181,7 @@
*/
if(RSA_public_encrypt(len, c->outkey, buffer, c->rsa_key, RSA_NO_PADDING) != len) {
- syslog(LOG_ERR, _("Error during encryption of meta key for %s (%s)"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error during encryption of meta key for %s (%s)"),
c->name, c->hostname);
return -1;
}
@@ -221,7 +221,7 @@
cp();
if(sscanf(c->buffer, "%*d %d %d %d %d " MAX_STRING, &cipher, &digest, &maclength, &compression, buffer) != 5) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "METAKEY", c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s)"), "METAKEY", c->name,
c->hostname);
return -1;
}
@@ -231,7 +231,7 @@
/* Check if the length of the meta key is all right */
if(strlen(buffer) != len * 2) {
- syslog(LOG_ERR, _("Possible intruder %s (%s): %s"), c->name, c->hostname, "wrong keylength");
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Possible intruder %s (%s): %s"), c->name, c->hostname, "wrong keylength");
return -1;
}
@@ -250,15 +250,15 @@
/* Decrypt the meta key */
if(RSA_private_decrypt(len, buffer, c->inkey, myself->connection->rsa_key, RSA_NO_PADDING) != len) { /* See challenge() */
- syslog(LOG_ERR, _("Error during encryption of meta key for %s (%s)"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error during encryption of meta key for %s (%s)"),
c->name, c->hostname);
return -1;
}
- if(debug_lvl >= DEBUG_SCARY_THINGS) {
+ if(debug_level >= DEBUG_SCARY_THINGS) {
bin2hex(c->inkey, buffer, len);
buffer[len * 2] = '\0';
- syslog(LOG_DEBUG, _("Received random meta key (unencrypted): %s"), buffer);
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Received random meta key (unencrypted): %s"), buffer);
}
/* All incoming requests will now be encrypted. */
@@ -269,7 +269,7 @@
c->incipher = EVP_get_cipherbynid(cipher);
if(!c->incipher) {
- syslog(LOG_ERR, _("%s (%s) uses unknown cipher!"), c->name, c->hostname);
+ logger(DEBUG_ALWAYS, LOG_ERR, _("%s (%s) uses unknown cipher!"), c->name, c->hostname);
return -1;
}
@@ -289,12 +289,12 @@
c->indigest = EVP_get_digestbynid(digest);
if(!c->indigest) {
- syslog(LOG_ERR, _("Node %s (%s) uses unknown digest!"), c->name, c->hostname);
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Node %s (%s) uses unknown digest!"), c->name, c->hostname);
return -1;
}
if(c->inmaclength > c->indigest->md_size || c->inmaclength < 0) {
- syslog(LOG_ERR, _("%s (%s) uses bogus MAC length!"), c->name, c->hostname);
+ logger(DEBUG_ALWAYS, LOG_ERR, _("%s (%s) uses bogus MAC length!"), c->name, c->hostname);
return -1;
}
} else {
@@ -348,7 +348,7 @@
cp();
if(sscanf(c->buffer, "%*d " MAX_STRING, buffer) != 1) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "CHALLENGE", c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s)"), "CHALLENGE", c->name,
c->hostname);
return -1;
}
@@ -358,7 +358,7 @@
/* Check if the length of the challenge is all right */
if(strlen(buffer) != len * 2) {
- syslog(LOG_ERR, _("Possible intruder %s (%s): %s"), c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Possible intruder %s (%s): %s"), c->name,
c->hostname, "wrong challenge length");
return -1;
}
@@ -412,7 +412,7 @@
cp();
if(sscanf(c->buffer, "%*d " MAX_STRING, hishash) != 1) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "CHAL_REPLY", c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s)"), "CHAL_REPLY", c->name,
c->hostname);
return -1;
}
@@ -420,7 +420,7 @@
/* Check if the length of the hash is all right */
if(strlen(hishash) != c->outdigest->md_size * 2) {
- syslog(LOG_ERR, _("Possible intruder %s (%s): %s"), c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Possible intruder %s (%s): %s"), c->name,
c->hostname, _("wrong challenge reply length"));
return -1;
}
@@ -438,13 +438,13 @@
/* Verify the incoming hash with the calculated hash */
if(memcmp(hishash, myhash, c->outdigest->md_size)) {
- syslog(LOG_ERR, _("Possible intruder %s (%s): %s"), c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Possible intruder %s (%s): %s"), c->name,
c->hostname, _("wrong challenge reply"));
- if(debug_lvl >= DEBUG_SCARY_THINGS) {
+ if(debug_level >= DEBUG_SCARY_THINGS) {
bin2hex(myhash, hishash, SHA_DIGEST_LENGTH);
hishash[SHA_DIGEST_LENGTH * 2] = '\0';
- syslog(LOG_DEBUG, _("Expected challenge reply: %s"), hishash);
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Expected challenge reply: %s"), hishash);
}
return -1;
@@ -515,9 +515,8 @@
cp();
- if(sscanf
- (c->buffer, "%*d " MAX_STRING " %d %lx", hisport, &weight, &options) != 3) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "ACK", c->name,
+ if(sscanf(c->buffer, "%*d " MAX_STRING " %d %lx", hisport, &weight, &options) != 3) {
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s)"), "ACK", c->name,
c->hostname);
return -1;
}
@@ -533,8 +532,7 @@
} else {
if(n->connection) {
/* Oh dear, we already have a connection to this node. */
- if(debug_lvl >= DEBUG_CONNECTIONS)
- syslog(LOG_DEBUG, _("Established a second connection with %s (%s), closing old connection"),
+ logger(DEBUG_CONNECTIONS, LOG_DEBUG, _("Established a second connection with %s (%s), closing old connection"),
n->name, n->hostname);
terminate_connection(n->connection, 0);
/* Run graph algorithm to purge key and make sure up/down scripts are rerun with new IP addresses and stuff */
@@ -551,8 +549,7 @@
c->allow_request = ALL;
c->status.active = 1;
- if(debug_lvl >= DEBUG_CONNECTIONS)
- syslog(LOG_NOTICE, _("Connection with %s (%s) activated"), c->name,
+ logger(DEBUG_CONNECTIONS, LOG_NOTICE, _("Connection with %s (%s) activated"), c->name,
c->hostname);
/* Send him everything we know */
Index: protocol_edge.c
===================================================================
RCS file: /home/CVS/tinc/src/protocol_edge.c,v
retrieving revision 1.1.4.15
retrieving revision 1.1.4.16
diff -u -r1.1.4.15 -r1.1.4.16
--- protocol_edge.c 2002/09/24 11:43:34 1.1.4.15
+++ protocol_edge.c 2003/07/06 22:11:32 1.1.4.16
@@ -24,7 +24,6 @@
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <stdio.h>
#include <stdarg.h>
#include <errno.h>
@@ -42,6 +41,7 @@
#include "node.h"
#include "edge.h"
#include "graph.h"
+#include "logger.h"
#include "system.h"
@@ -79,7 +79,7 @@
if(sscanf(c->buffer, "%*d %*x "MAX_STRING" "MAX_STRING" "MAX_STRING" "MAX_STRING" %lx %d",
from_name, to_name, to_address, to_port, &options, &weight) != 6) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "ADD_EDGE", c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s)"), "ADD_EDGE", c->name,
c->hostname);
return -1;
}
@@ -87,13 +87,13 @@
/* Check if names are valid */
if(check_id(from_name)) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s): %s"), "ADD_EDGE", c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s): %s"), "ADD_EDGE", c->name,
c->hostname, _("invalid name"));
return -1;
}
if(check_id(to_name)) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s): %s"), "ADD_EDGE", c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s): %s"), "ADD_EDGE", c->name,
c->hostname, _("invalid name"));
return -1;
}
@@ -130,14 +130,12 @@
if(e) {
if(e->weight != weight || e->options != options || sockaddrcmp(&e->address, &address)) {
if(from == myself) {
- if(debug_lvl >= DEBUG_PROTOCOL)
- syslog(LOG_WARNING, _("Got %s from %s (%s) for ourself which does not match existing entry"),
+ logger(DEBUG_PROTOCOL, LOG_WARNING, _("Got %s from %s (%s) for ourself which does not match existing entry"),
"ADD_EDGE", c->name, c->hostname);
send_add_edge(c, e);
return 0;
} else {
- if(debug_lvl >= DEBUG_PROTOCOL)
- syslog(LOG_WARNING, _("Got %s from %s (%s) which does not match existing entry"),
+ logger(DEBUG_PROTOCOL, LOG_WARNING, _("Got %s from %s (%s) which does not match existing entry"),
"ADD_EDGE", c->name, c->hostname);
edge_del(e);
graph();
@@ -145,8 +143,7 @@
} else
return 0;
} else if(from == myself) {
- if(debug_lvl >= DEBUG_PROTOCOL)
- syslog(LOG_WARNING, _("Got %s from %s (%s) for ourself which does not exist"),
+ logger(DEBUG_PROTOCOL, LOG_WARNING, _("Got %s from %s (%s) for ourself which does not exist"),
"ADD_EDGE", c->name, c->hostname);
e = new_edge();
e->from = from;
@@ -193,7 +190,7 @@
cp();
if(sscanf(c->buffer, "%*d %*x "MAX_STRING" "MAX_STRING, from_name, to_name) != 2) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "DEL_EDGE", c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s)"), "DEL_EDGE", c->name,
c->hostname);
return -1;
}
@@ -201,13 +198,13 @@
/* Check if names are valid */
if(check_id(from_name)) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s): %s"), "DEL_EDGE", c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s): %s"), "DEL_EDGE", c->name,
c->hostname, _("invalid name"));
return -1;
}
if(check_id(to_name)) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s): %s"), "DEL_EDGE", c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s): %s"), "DEL_EDGE", c->name,
c->hostname, _("invalid name"));
return -1;
}
@@ -220,8 +217,7 @@
from = lookup_node(from_name);
if(!from) {
- if(debug_lvl >= DEBUG_PROTOCOL)
- syslog(LOG_ERR, _("Got %s from %s (%s) which does not appear in the edge tree"),
+ logger(DEBUG_PROTOCOL, LOG_ERR, _("Got %s from %s (%s) which does not appear in the edge tree"),
"DEL_EDGE", c->name, c->hostname);
return 0;
}
@@ -229,8 +225,7 @@
to = lookup_node(to_name);
if(!to) {
- if(debug_lvl >= DEBUG_PROTOCOL)
- syslog(LOG_ERR, _("Got %s from %s (%s) which does not appear in the edge tree"),
+ logger(DEBUG_PROTOCOL, LOG_ERR, _("Got %s from %s (%s) which does not appear in the edge tree"),
"DEL_EDGE", c->name, c->hostname);
return 0;
}
@@ -240,15 +235,13 @@
e = lookup_edge(from, to);
if(!e) {
- if(debug_lvl >= DEBUG_PROTOCOL)
- syslog(LOG_WARNING, _("Got %s from %s (%s) which does not appear in the edge tree"),
+ logger(DEBUG_PROTOCOL, LOG_WARNING, _("Got %s from %s (%s) which does not appear in the edge tree"),
"DEL_EDGE", c->name, c->hostname);
return 0;
}
if(e->from == myself) {
- if(debug_lvl >= DEBUG_PROTOCOL)
- syslog(LOG_WARNING, _("Got %s from %s (%s) for ourself"),
+ logger(DEBUG_PROTOCOL, LOG_WARNING, _("Got %s from %s (%s) for ourself"),
"DEL_EDGE", c->name, c->hostname);
send_add_edge(c, e); /* Send back a correction */
return 0;
Index: protocol_key.c
===================================================================
RCS file: /home/CVS/tinc/src/protocol_key.c,v
retrieving revision 1.1.4.16
retrieving revision 1.1.4.17
diff -u -r1.1.4.16 -r1.1.4.17
--- protocol_key.c 2003/05/06 21:13:18 1.1.4.16
+++ protocol_key.c 2003/07/06 22:11:32 1.1.4.17
@@ -24,7 +24,6 @@
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <stdio.h>
#include <stdarg.h>
#include <errno.h>
@@ -40,6 +39,7 @@
#include "meta.h"
#include "connection.h"
#include "node.h"
+#include "logger.h"
#include "system.h"
@@ -67,7 +67,7 @@
cp();
if(sscanf(c->buffer, "%*d %*x " MAX_STRING, name) != 1) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "KEY_CHANGED",
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s)"), "KEY_CHANGED",
c->name, c->hostname);
return -1;
}
@@ -78,7 +78,7 @@
n = lookup_node(name);
if(!n) {
- syslog(LOG_ERR, _("Got %s from %s (%s) origin %s which does not exist"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got %s from %s (%s) origin %s which does not exist"),
"KEY_CHANGED", c->name, c->hostname, name);
return -1;
}
@@ -109,7 +109,7 @@
cp();
if(sscanf(c->buffer, "%*d " MAX_STRING " " MAX_STRING, from_name, to_name) != 2) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "REQ_KEY", c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s)"), "REQ_KEY", c->name,
c->hostname);
return -1;
}
@@ -117,7 +117,7 @@
from = lookup_node(from_name);
if(!from) {
- syslog(LOG_ERR, _("Got %s from %s (%s) origin %s which does not exist in our connection list"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got %s from %s (%s) origin %s which does not exist in our connection list"),
"REQ_KEY", c->name, c->hostname, from_name);
return -1;
}
@@ -125,7 +125,7 @@
to = lookup_node(to_name);
if(!to) {
- syslog(LOG_ERR, _("Got %s from %s (%s) destination %s which does not exist in our connection list"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got %s from %s (%s) destination %s which does not exist in our connection list"),
"REQ_KEY", c->name, c->hostname, to_name);
return -1;
}
@@ -173,7 +173,7 @@
if(sscanf(c->buffer, "%*d "MAX_STRING" "MAX_STRING" "MAX_STRING" %d %d %d %d",
from_name, to_name, key, &cipher, &digest, &maclength,
&compression) != 7) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "ANS_KEY", c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s)"), "ANS_KEY", c->name,
c->hostname);
return -1;
}
@@ -181,7 +181,7 @@
from = lookup_node(from_name);
if(!from) {
- syslog(LOG_ERR, _("Got %s from %s (%s) origin %s which does not exist in our connection list"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got %s from %s (%s) origin %s which does not exist in our connection list"),
"ANS_KEY", c->name, c->hostname, from_name);
return -1;
}
@@ -189,7 +189,7 @@
to = lookup_node(to_name);
if(!to) {
- syslog(LOG_ERR, _("Got %s from %s (%s) destination %s which does not exist in our connection list"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got %s from %s (%s) destination %s which does not exist in our connection list"),
"ANS_KEY", c->name, c->hostname, to_name);
return -1;
}
@@ -220,13 +220,13 @@
from->cipher = EVP_get_cipherbynid(cipher);
if(!from->cipher) {
- syslog(LOG_ERR, _("Node %s (%s) uses unknown cipher!"), from->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Node %s (%s) uses unknown cipher!"), from->name,
from->hostname);
return -1;
}
if(from->keylength != from->cipher->key_len + from->cipher->iv_len) {
- syslog(LOG_ERR, _("Node %s (%s) uses wrong keylength!"), from->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Node %s (%s) uses wrong keylength!"), from->name,
from->hostname);
return -1;
}
@@ -240,13 +240,13 @@
from->digest = EVP_get_digestbynid(digest);
if(!from->digest) {
- syslog(LOG_ERR, _("Node %s (%s) uses unknown digest!"), from->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Node %s (%s) uses unknown digest!"), from->name,
from->hostname);
return -1;
}
if(from->maclength > from->digest->md_size || from->maclength < 0) {
- syslog(LOG_ERR, _("Node %s (%s) uses bogus MAC length!"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Node %s (%s) uses bogus MAC length!"),
from->name, from->hostname);
return -1;
}
@@ -255,7 +255,7 @@
}
if(compression < 0 || compression > 11) {
- syslog(LOG_ERR, _("Node %s (%s) uses bogus compression level!"), from->name, from->hostname);
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Node %s (%s) uses bogus compression level!"), from->name, from->hostname);
return -1;
}
Index: protocol_misc.c
===================================================================
RCS file: /home/CVS/tinc/src/protocol_misc.c,v
retrieving revision 1.1.4.7
retrieving revision 1.1.4.8
diff -u -r1.1.4.7 -r1.1.4.8
--- protocol_misc.c 2002/09/09 22:33:04 1.1.4.7
+++ protocol_misc.c 2003/07/06 22:11:33 1.1.4.8
@@ -24,7 +24,6 @@
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <stdio.h>
#include <stdarg.h>
#include <errno.h>
@@ -37,6 +36,7 @@
#include "protocol.h"
#include "meta.h"
#include "connection.h"
+#include "logger.h"
#include "system.h"
@@ -60,15 +60,13 @@
cp();
if(sscanf(c->buffer, "%*d %d " MAX_STRING, &statusno, statusstring) != 2) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "STATUS",
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s)"), "STATUS",
c->name, c->hostname);
return -1;
}
- if(debug_lvl >= DEBUG_STATUS) {
- syslog(LOG_NOTICE, _("Status message from %s (%s): %s: %s"),
+ logger(DEBUG_STATUS, LOG_NOTICE, _("Status message from %s (%s): %s: %s"),
c->name, c->hostname, status_text[statusno], statusstring);
- }
return 0;
}
@@ -91,15 +89,13 @@
cp();
if(sscanf(c->buffer, "%*d %d " MAX_STRING, &err, errorstring) != 2) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "ERROR",
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s)"), "ERROR",
c->name, c->hostname);
return -1;
}
- if(debug_lvl >= DEBUG_ERROR) {
- syslog(LOG_NOTICE, _("Error message from %s (%s): %s: %s"),
+ logger(DEBUG_ERROR, LOG_NOTICE, _("Error message from %s (%s): %s: %s"),
c->name, c->hostname, strerror(err), errorstring);
- }
terminate_connection(c, c->status.active);
@@ -185,7 +181,7 @@
cp();
if(sscanf(c->buffer, "%*d %hd", &len) != 1) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "PACKET", c->name,
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s)"), "PACKET", c->name,
c->hostname);
return -1;
}
Index: protocol_subnet.c
===================================================================
RCS file: /home/CVS/tinc/src/protocol_subnet.c,v
retrieving revision 1.1.4.9
retrieving revision 1.1.4.10
diff -u -r1.1.4.9 -r1.1.4.10
--- protocol_subnet.c 2002/09/09 22:33:13 1.1.4.9
+++ protocol_subnet.c 2003/07/06 22:11:33 1.1.4.10
@@ -24,7 +24,6 @@
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <stdio.h>
#include <stdarg.h>
#include <errno.h>
@@ -40,6 +39,7 @@
#include "meta.h"
#include "connection.h"
#include "node.h"
+#include "logger.h"
#include "system.h"
@@ -114,8 +114,7 @@
/* If we don't know this subnet, but we are the owner, retaliate with a DEL_SUBNET */
if(owner == myself) {
- if(debug_lvl >= DEBUG_PROTOCOL)
- syslog(LOG_WARNING, _("Got %s from %s (%s) for ourself"),
+ logger(DEBUG_PROTOCOL, LOG_WARNING, _("Got %s from %s (%s) for ourself"),
"ADD_SUBNET", c->name, c->hostname);
s->owner = myself;
send_del_subnet(c, s);
@@ -177,8 +176,7 @@
owner = lookup_node(name);
if(!owner) {
- if(debug_lvl >= DEBUG_PROTOCOL)
- syslog(LOG_WARNING, _("Got %s from %s (%s) for %s which is not in our node tree"),
+ logger(DEBUG_PROTOCOL, LOG_WARNING, _("Got %s from %s (%s) for %s which is not in our node tree"),
"DEL_SUBNET", c->name, c->hostname, name);
return 0;
}
@@ -205,8 +203,7 @@
free_subnet(s);
if(!find) {
- if(debug_lvl >= DEBUG_PROTOCOL)
- syslog(LOG_WARNING, _("Got %s from %s (%s) for %s which does not appear in his subnet tree"),
+ logger(DEBUG_PROTOCOL, LOG_WARNING, _("Got %s from %s (%s) for %s which does not appear in his subnet tree"),
"DEL_SUBNET", c->name, c->hostname, name);
return 0;
}
@@ -214,8 +211,7 @@
/* If we are the owner of this subnet, retaliate with an ADD_SUBNET */
if(owner == myself) {
- if(debug_lvl >= DEBUG_PROTOCOL)
- syslog(LOG_WARNING, _("Got %s from %s (%s) for ourself"),
+ logger(DEBUG_PROTOCOL, LOG_WARNING, _("Got %s from %s (%s) for ourself"),
"DEL_SUBNET", c->name, c->hostname);
send_add_subnet(c, find);
return 0;
Index: route.c
===================================================================
RCS file: /home/CVS/tinc/src/route.c,v
retrieving revision 1.1.2.53
retrieving revision 1.1.2.54
diff -u -r1.1.2.53 -r1.1.2.54
--- route.c 2003/07/06 17:49:49 1.1.2.53
+++ route.c 2003/07/06 22:11:33 1.1.2.54
@@ -45,7 +45,6 @@
#include <netinet/if_ether.h>
#include <utils.h>
#include <xalloc.h>
-#include <syslog.h>
#include <string.h>
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
@@ -59,6 +58,7 @@
#include "route.h"
#include "protocol.h"
#include "device.h"
+#include "logger.h"
#include "system.h"
@@ -130,8 +130,7 @@
/* If we don't know this MAC address yet, store it */
if(!subnet || subnet->owner != myself) {
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_INFO, _("Learned new MAC address %hx:%hx:%hx:%hx:%hx:%hx"),
+ logger(DEBUG_TRAFFIC, LOG_INFO, _("Learned new MAC address %hx:%hx:%hx:%hx:%hx:%hx"),
address->x[0], address->x[1], address->x[2], address->x[3],
address->x[4], address->x[5]);
@@ -164,8 +163,7 @@
next = node->next;
s = (subnet_t *) node->data;
if(s->type == SUBNET_MAC && s->net.mac.lastseen && s->net.mac.lastseen + macexpire < now) {
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_INFO, _("MAC address %hx:%hx:%hx:%hx:%hx:%hx expired"),
+ logger(DEBUG_TRAFFIC, LOG_INFO, _("MAC address %hx:%hx:%hx:%hx:%hx:%hx expired"),
s->net.mac.address.x[0], s->net.mac.address.x[1],
s->net.mac.address.x[2], s->net.mac.address.x[3],
s->net.mac.address.x[4], s->net.mac.address.x[5]);
@@ -274,11 +272,9 @@
subnet = lookup_subnet_ipv4((ipv4_t *) & packet->data[30]);
if(!subnet) {
- if(debug_lvl >= DEBUG_TRAFFIC) {
- syslog(LOG_WARNING, _("Cannot route packet: unknown IPv4 destination address %d.%d.%d.%d"),
+ logger(DEBUG_TRAFFIC, LOG_WARNING, _("Cannot route packet: unknown IPv4 destination address %d.%d.%d.%d"),
packet->data[30], packet->data[31], packet->data[32],
packet->data[33]);
- }
route_ipv4_unreachable(packet, ICMP_NET_UNKNOWN);
return NULL;
@@ -371,8 +367,7 @@
subnet = lookup_subnet_ipv6((ipv6_t *) & packet->data[38]);
if(!subnet) {
- if(debug_lvl >= DEBUG_TRAFFIC) {
- syslog(LOG_WARNING, _("Cannot route packet: unknown IPv6 destination address %hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx"),
+ logger(DEBUG_TRAFFIC, LOG_WARNING, _("Cannot route packet: unknown IPv6 destination address %hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx"),
ntohs(*(uint16_t *) & packet->data[38]),
ntohs(*(uint16_t *) & packet->data[40]),
ntohs(*(uint16_t *) & packet->data[42]),
@@ -381,7 +376,6 @@
ntohs(*(uint16_t *) & packet->data[48]),
ntohs(*(uint16_t *) & packet->data[50]),
ntohs(*(uint16_t *) & packet->data[52]));
- }
#ifdef HAVE_NETINET_IP6_H
route_ipv6_unreachable(packet, ICMP6_DST_UNREACH_ADDR);
#endif
@@ -431,9 +425,7 @@
if(ns->nd_ns_hdr.icmp6_type != ND_NEIGHBOR_SOLICIT ||
opt->nd_opt_type != ND_OPT_SOURCE_LINKADDR) {
- if(debug_lvl > DEBUG_TRAFFIC) {
- syslog(LOG_WARNING, _("Cannot route packet: received unknown type neighbor solicitation request"));
- }
+ logger(DEBUG_TRAFFIC, LOG_WARNING, _("Cannot route packet: received unknown type neighbor solicitation request"));
return;
}
@@ -450,8 +442,7 @@
checksum = inet_checksum(ns, sizeof(*ns) + 8, checksum);
if(checksum) {
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_WARNING, _("Cannot route packet: checksum error for neighbor solicitation request"));
+ logger(DEBUG_TRAFFIC, LOG_WARNING, _("Cannot route packet: checksum error for neighbor solicitation request"));
return;
}
@@ -460,8 +451,7 @@
subnet = lookup_subnet_ipv6((ipv6_t *) & ns->nd_ns_target);
if(!subnet) {
- if(debug_lvl >= DEBUG_TRAFFIC) {
- syslog(LOG_WARNING, _("Cannot route packet: neighbor solicitation request for unknown address %hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx"),
+ logger(DEBUG_TRAFFIC, LOG_WARNING, _("Cannot route packet: neighbor solicitation request for unknown address %hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx"),
ntohs(((uint16_t *) & ns->nd_ns_target)[0]),
ntohs(((uint16_t *) & ns->nd_ns_target)[1]),
ntohs(((uint16_t *) & ns->nd_ns_target)[2]),
@@ -470,7 +460,6 @@
ntohs(((uint16_t *) & ns->nd_ns_target)[5]),
ntohs(((uint16_t *) & ns->nd_ns_target)[6]),
ntohs(((uint16_t *) & ns->nd_ns_target)[7]));
- }
return;
}
@@ -543,9 +532,7 @@
if(ntohs(arp->arp_hrd) != ARPHRD_ETHER || ntohs(arp->arp_pro) != ETHERTYPE_IP ||
arp->arp_hln != ETHER_ADDR_LEN || arp->arp_pln != 4 || ntohs(arp->arp_op) != ARPOP_REQUEST) {
- if(debug_lvl > DEBUG_TRAFFIC) {
- syslog(LOG_WARNING, _("Cannot route packet: received unknown type ARP request"));
- }
+ logger(DEBUG_TRAFFIC, LOG_WARNING, _("Cannot route packet: received unknown type ARP request"));
return;
}
@@ -554,12 +541,9 @@
subnet = lookup_subnet_ipv4((ipv4_t *) arp->arp_tpa);
if(!subnet) {
- if(debug_lvl >= DEBUG_TRAFFIC) {
- syslog(LOG_WARNING, _("Cannot route packet: ARP request for unknown address %d.%d.%d.%d"),
+ logger(DEBUG_TRAFFIC, LOG_WARNING, _("Cannot route packet: ARP request for unknown address %d.%d.%d.%d"),
arp->arp_tpa[0], arp->arp_tpa[1], arp->arp_tpa[2],
arp->arp_tpa[3]);
- }
-
return;
}
@@ -614,8 +598,7 @@
return;
default:
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_WARNING, _("Cannot route packet: unknown type %hx"), type);
+ logger(DEBUG_TRAFFIC, LOG_WARNING, _("Cannot route packet: unknown type %hx"), type);
return;
}
if(n)
Index: subnet.c
===================================================================
RCS file: /home/CVS/tinc/src/Attic/subnet.c,v
retrieving revision 1.1.2.43
retrieving revision 1.1.2.44
diff -u -r1.1.2.43 -r1.1.2.44
--- subnet.c 2002/09/15 14:55:54 1.1.2.43
+++ subnet.c 2003/07/06 22:11:33 1.1.2.44
@@ -23,7 +23,6 @@
#include "config.h"
#include <stdio.h>
-#include <syslog.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
@@ -39,6 +38,7 @@
#include "node.h"
#include "subnet.h"
#include "netutl.h"
+#include "logger.h"
#include "system.h"
@@ -111,7 +111,7 @@
case SUBNET_IPV6:
return subnet_compare_ipv6(a, b);
default:
- syslog(LOG_ERR, _("subnet_compare() was called with unknown subnet type %d, exitting!"),
+ logger(DEBUG_ALWAYS, LOG_ERR, _("subnet_compare() was called with unknown subnet type %d, exitting!"),
a->type);
cp_trace();
exit(0);
@@ -295,7 +295,7 @@
break;
default:
- syslog(LOG_ERR,
+ logger(DEBUG_ALWAYS, LOG_ERR,
_("net2str() was called with unknown subnet type %d, exiting!"),
subnet->type);
cp_trace();
@@ -411,14 +411,14 @@
cp();
- syslog(LOG_DEBUG, _("Subnet list:"));
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("Subnet list:"));
for(node = subnet_tree->head; node; node = node->next) {
subnet = (subnet_t *) node->data;
netstr = net2str(subnet);
- syslog(LOG_DEBUG, _(" %s owner %s"), netstr, subnet->owner->name);
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _(" %s owner %s"), netstr, subnet->owner->name);
free(netstr);
}
- syslog(LOG_DEBUG, _("End of subnet list."));
+ logger(DEBUG_ALWAYS, LOG_DEBUG, _("End of subnet list."));
}
Index: tincd.c
===================================================================
RCS file: /home/CVS/tinc/src/tincd.c,v
retrieving revision 1.10.4.69
retrieving revision 1.10.4.70
diff -u -r1.10.4.69 -r1.10.4.70
--- tincd.c 2003/07/06 17:15:25 1.10.4.69
+++ tincd.c 2003/07/06 22:11:33 1.10.4.70
@@ -28,7 +28,6 @@
#include <signal.h>
#include <stdio.h>
#include <sys/types.h>
-#include <syslog.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
@@ -61,6 +60,7 @@
#include "process.h"
#include "protocol.h"
#include "subnet.h"
+#include "logger.h"
#include "system.h"
@@ -85,8 +85,12 @@
/* If nonzero, disable swapping for this process. */
int do_mlock = 0;
+/* If nonzero, write log entries to a separate file. */
+int use_logfile = 0;
+
char *identname = NULL; /* program name for syslog */
char *pidfilename = NULL; /* pid file location */
+char *logfilename = NULL; /* log file location */
char **g_argv; /* a copy of the cmdline arguments */
char **environment; /* A pointer to the environment on
startup */
@@ -102,6 +106,7 @@
{"debug", optional_argument, NULL, 'd'},
{"bypass-security", no_argument, &bypass_security, 1},
{"mlock", no_argument, &do_mlock, 1},
+ {"logfile", optional_argument, NULL, 'F'},
{NULL, 0, NULL, 0}
};
@@ -119,6 +124,7 @@
" -n, --net=NETNAME Connect to net NETNAME.\n"
" -K, --generate-keys[=BITS] Generate public/private RSA keypair.\n"
" -L, --mlock Lock tinc into main memory.\n"
+ " -F, --logfile[=FILENAME] Write log entries to a logfile.\n"
" --help Display this help and exit.\n"
" --version Output version information and exit.\n\n"));
printf(_("Report bugs to tinc@nl.linux.org.\n"));
@@ -132,7 +138,7 @@
int r;
int option_index = 0;
- while((r = getopt_long(argc, argv, "c:DLd::k::n:K::", long_options, &option_index)) != EOF) {
+ while((r = getopt_long(argc, argv, "c:DLd::k::n:K::F::", long_options, &option_index)) != EOF) {
switch (r) {
case 0: /* long option */
break;
@@ -152,9 +158,9 @@
case 'd': /* inc debug level */
if(optarg)
- debug_lvl = atoi(optarg);
+ debug_level = atoi(optarg);
else
- debug_lvl++;
+ debug_level++;
break;
case 'k': /* kill old tincds */
@@ -189,8 +195,7 @@
break;
case 'n': /* net name given */
- netname = xmalloc(strlen(optarg) + 1);
- strcpy(netname, optarg);
+ netname = xstrdup(optarg);
break;
case 'K': /* generate public/private keypair */
@@ -208,6 +213,12 @@
generate_keys = 1024;
break;
+ case 'F': /* write log entries to a file */
+ use_logfile = 1;
+ if(optarg)
+ logfilename = xstrdup(optarg);
+ break;
+
case '?':
usage(1);
@@ -317,17 +328,21 @@
if(netname) {
if(!pidfilename)
asprintf(&pidfilename, LOCALSTATEDIR "/run/tinc.%s.pid", netname);
+ if(!logfilename)
+ asprintf(&logfilename, LOCALSTATEDIR "/log/tinc.%s.log", netname);
if(!confbase)
asprintf(&confbase, "%s/tinc/%s", CONFDIR, netname);
else
- syslog(LOG_INFO, _("Both netname and configuration directory given, using the latter..."));
+ logger(DEBUG_ALWAYS, LOG_INFO, _("Both netname and configuration directory given, using the latter..."));
if(!identname)
asprintf(&identname, "tinc.%s", netname);
} else {
if(!pidfilename)
pidfilename = LOCALSTATEDIR "/run/tinc.pid";
+ if(!logfilename)
+ logfilename = LOCALSTATEDIR "/log/tinc.log";
if(!confbase)
asprintf(&confbase, "%s/tinc", CONFDIR);
@@ -367,22 +382,18 @@
if(kill_tincd)
exit(kill_other(kill_tincd));
-#ifndef LOG_PERROR
- openlog("tinc", LOG_CONS, LOG_DAEMON); /* Catch all syslog() calls issued before detaching */
-#else
- openlog("tinc", LOG_PERROR, LOG_DAEMON); /* Catch all syslog() calls issued before detaching */
-#endif
+ openlogger("tinc", LOGMODE_STDERR);
/* Lock all pages into memory if requested */
if(do_mlock)
#ifdef HAVE_MLOCKALL
if(mlockall(MCL_CURRENT | MCL_FUTURE)) {
- syslog(LOG_ERR, _("System call `%s' failed: %s"), "mlockall",
+ logger(DEBUG_ALWAYS, LOG_ERR, _("System call `%s' failed: %s"), "mlockall",
strerror(errno));
#else
{
- syslog(LOG_ERR, _("mlockall() not supported on this platform!"));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("mlockall() not supported on this platform!"));
#endif
return -1;
}
@@ -406,7 +417,7 @@
exit(1);
if(lzo_init() != LZO_E_OK) {
- syslog(LOG_ERR, _("Error initializing LZO compressor!"));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Error initializing LZO compressor!"));
exit(1);
}
@@ -419,14 +430,14 @@
cleanup_and_exit(1);
}
- syslog(LOG_ERR, _("Unrecoverable error"));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Unrecoverable error"));
cp_trace();
if(do_detach) {
- syslog(LOG_NOTICE, _("Restarting in %d seconds!"), maxtimeout);
+ logger(DEBUG_ALWAYS, LOG_NOTICE, _("Restarting in %d seconds!"), maxtimeout);
sleep(maxtimeout);
} else {
- syslog(LOG_ERR, _("Not restarting."));
+ logger(DEBUG_ALWAYS, LOG_ERR, _("Not restarting."));
exit(1);
}
}
--
Tinc-cvs: CVS changelog list for the tinc VPN daemon
Archive: http://mail.nl.linux.org/tinc-cvs/
Tinc site: http://tinc.nl.linux.org/
- Prev by Date:
tinc/src conf.c,1.9.4.62,1.9.4.63 conf.h,1.6.4.36,1.6.4.37 connection.c,1.1.2.37,1.1.2.38 connection.h,1.1.2.31,1.1.2.32 edge.c,1.1.2.19,1.1.2.20 edge.h,1.1.2.11,1.1.2.12 event.c,1.1.4.6,1.1.4.7 event.h,1.1.4.4,1.1.4.5 logger.c,1.1.2.1,1.1.2.2 net.c,1.35.4.188,1.35.4.189 net.h,1.9.4.59,1.9.4.60 net_packet.c,1.1.2.31,1.1.2.32 node.c,1.1.2.20,1.1.2.21 node.h,1.1.2.22,1.1.2.23 process.c,1.1.2.51,1.1.2.52 process.h,1.1.2.13,1.1.2.14 protocol.c,1.28.4.138,1.28.4.139 protocol.h,1.5.4.37,1.5.4.38 protocol_auth.c,1.1.4.21,1.1.4.22 protocol_misc.c,1.1.4.8,1.1.4.9 route.c,1.1.2.54,1.1.2.55 subnet.c,1.1.2.44,1.1.2.45 subnet.h,1.1.2.20,1.1.2.21 tincd.c,1.10.4.70,1.10.4.71
- Next by Date:
tinc/lib utils.h,1.1.1.1.4.13,1.1.1.1.4.14
- Prev by thread:
tinc/src conf.c,1.9.4.62,1.9.4.63 conf.h,1.6.4.36,1.6.4.37 connection.c,1.1.2.37,1.1.2.38 connection.h,1.1.2.31,1.1.2.32 edge.c,1.1.2.19,1.1.2.20 edge.h,1.1.2.11,1.1.2.12 event.c,1.1.4.6,1.1.4.7 event.h,1.1.4.4,1.1.4.5 logger.c,1.1.2.1,1.1.2.2 net.c,1.35.4.188,1.35.4.189 net.h,1.9.4.59,1.9.4.60 net_packet.c,1.1.2.31,1.1.2.32 node.c,1.1.2.20,1.1.2.21 node.h,1.1.2.22,1.1.2.23 process.c,1.1.2.51,1.1.2.52 process.h,1.1.2.13,1.1.2.14 protocol.c,1.28.4.138,1.28.4.139 protocol.h,1.5.4.37,1.5.4.38 protocol_auth.c,1.1.4.21,1.1.4.22 protocol_misc.c,1.1.4.8,1.1.4.9 route.c,1.1.2.54,1.1.2.55 subnet.c,1.1.2.44,1.1.2.45 subnet.h,1.1.2.20,1.1.2.21 tincd.c,1.10.4.70,1.10.4.71
- Next by thread:
tinc/lib utils.h,1.1.1.1.4.13,1.1.1.1.4.14
- Index(es):