void logger(int level, int priority, const char *format, ...) {
va_list ap;
+ int len;
char timestr[32] = "";
char message[1024] = "";
time_t now;
return;
va_start(ap, format);
- vsnprintf(message, sizeof message, format, ap);
+ len = vsnprintf(message, sizeof message, format, ap);
va_end(ap);
+ if(len > 0 && len < sizeof message && message[len - 1] == '\n')
+ message[len - 1] = 0;
+
if(level <= debug_level) {
switch(logmode) {
case LOGMODE_STDERR:
for(node = myself->subnet_tree->head; node; node = node->next) {
subnet_t *subnet = node->data;
- logger(DEBUG_ALWAYS, LOG_DEBUG, "subnet %p expires %d\n", subnet, (int)subnet->expires);
+ logger(DEBUG_ALWAYS, LOG_DEBUG, "subnet %p expires %d", subnet, (int)subnet->expires);
if(!subnet->expires)
subnet->expires = 1;
}
continue;
if((s2 = lookup_subnet(myself, subnet))) {
- logger(DEBUG_ALWAYS, LOG_DEBUG, "read subnet that already exists: %p expires %d\n", s2, (int)s2->expires);
+ logger(DEBUG_ALWAYS, LOG_DEBUG, "read subnet that already exists: %p expires %d", s2, (int)s2->expires);
if(s2->expires == 1)
s2->expires = 0;
int fd[2];
if(socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) {
- logger(DEBUG_ALWAYS, LOG_ERR, "Could not create socketpair: %s\n", strerror(errno));
+ logger(DEBUG_ALWAYS, LOG_ERR, "Could not create socketpair: %s", strerror(errno));
return;
}
int result = system(command);
if(result < 0)
- logger(DEBUG_ALWAYS, LOG_ERR, "Could not execute %s: %s\n", command, strerror(errno));
+ logger(DEBUG_ALWAYS, LOG_ERR, "Could not execute %s: %s", command, strerror(errno));
else if(result)
logger(DEBUG_ALWAYS, LOG_ERR, "%s exited with non-zero status %d", command, result);
exit(result);