/*
logger.c -- logging code
- Copyright (C) 2004-2017 Guus Sliepen <guus@tinc-vpn.org>
+ Copyright (C) 2004-2022 Guus Sliepen <guus@tinc-vpn.org>
2004-2005 Ivo Timmermans
This program is free software; you can redistribute it and/or modify
#include "control_common.h"
#include "process.h"
#include "sptps.h"
+#include "compression.h"
-int debug_level = DEBUG_NOTHING;
+debug_t debug_level = DEBUG_NOTHING;
static logmode_t logmode = LOGMODE_STDERR;
static pid_t logpid;
static FILE *logfile = NULL;
bool logcontrol = false; // controlled by REQ_LOG <level>
int umbilical = 0;
-static bool should_log(int level) {
+static bool should_log(debug_t level) {
return (level <= debug_level && logmode != LOGMODE_NULL) || logcontrol;
}
-static void real_logger(int level, int priority, const char *message) {
+static void real_logger(debug_t level, int priority, const char *message) {
char timestr[32] = "";
static bool suppress = false;
break;
case LOGMODE_NULL:
+ default:
break;
}
if(umbilical && do_detach) {
- write(umbilical, message, strlen(message));
- write(umbilical, "\n", 1);
+ size_t len = strlen(message);
+
+ if(write(umbilical, message, len) != (ssize_t)len || write(umbilical, "\n", 1) != 1) {
+ // Other end broken, nothing we can do about it.
+ }
}
}
- if(logcontrol && connection_list) {
+ if(logcontrol) {
suppress = true;
logcontrol = false;
- for list_each(connection_t, c, connection_list) {
+ for list_each(connection_t, c, &connection_list) {
if(!c->status.log) {
continue;
}
logcontrol = true;
- if(level > (c->outcompression >= 0 ? c->outcompression : debug_level)) {
+ if(level > (c->outcompression >= COMPRESS_NONE ? c->outcompression : debug_level)) {
continue;
}
- int len = strlen(message);
+ size_t len = strlen(message);
- if(send_request(c, "%d %d %d", CONTROL, REQ_LOG, len)) {
+ if(send_request(c, "%d %d %lu", CONTROL, REQ_LOG, (unsigned long)len)) {
send_meta(c, message, len);
}
}
}
}
-void logger(int level, int priority, const char *format, ...) {
+void logger(debug_t level, int priority, const char *format, ...) {
va_list ap;
char message[1024] = "";
#endif
case LOGMODE_NULL:
+ default:
break;
}
}
}
-void reopenlogger() {
+void reopenlogger(void) {
if(logmode != LOGMODE_FILE) {
return;
}
case LOGMODE_NULL:
case LOGMODE_STDERR:
+ default:
break;
}
}