X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Flogger.c;h=026a120260e8de51a3d9bb6a100151617e2fca4d;hb=668750c022a02cc54756316907f1cbbf7d673025;hp=1a2e95ffbeb779367bddba7f30bccddc55c6f8ba;hpb=0871c3095151bce6a4031a2662aa51b7193b855c;p=tinc diff --git a/src/logger.c b/src/logger.c index 1a2e95ff..026a1202 100644 --- a/src/logger.c +++ b/src/logger.c @@ -1,6 +1,6 @@ /* logger.c -- logging code - Copyright (C) 2004-2017 Guus Sliepen + Copyright (C) 2004-2022 Guus Sliepen 2004-2005 Ivo Timmermans This program is free software; you can redistribute it and/or modify @@ -34,7 +34,7 @@ debug_t debug_level = DEBUG_NOTHING; static logmode_t logmode = LOGMODE_STDERR; static pid_t logpid; static FILE *logfile = NULL; -#ifdef HAVE_MINGW +#ifdef HAVE_WINDOWS static HANDLE loghandle = NULL; #endif static const char *logident = NULL; @@ -72,7 +72,7 @@ static void real_logger(debug_t level, int priority, const char *message) { break; case LOGMODE_SYSLOG: -#ifdef HAVE_MINGW +#ifdef HAVE_WINDOWS { const char *messages[] = {message}; ReportEvent(loghandle, priority, 0, 0, NULL, 1, 0, messages, NULL); @@ -91,8 +91,11 @@ static void real_logger(debug_t level, int priority, const char *message) { } 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. + } } } @@ -107,13 +110,13 @@ static void real_logger(debug_t level, int priority, const char *message) { logcontrol = true; - if(level > (c->outcompression >= COMPRESS_NONE ? c->outcompression : debug_level)) { + if(level > (c->log_level != DEBUG_UNSET ? c->log_level : debug_level)) { continue; } size_t len = strlen(message); - if(send_request(c, "%d %d %zu", CONTROL, REQ_LOG, len)) { + if(send_request(c, "%d %d %lu", CONTROL, REQ_LOG, (unsigned long)len)) { send_meta(c, message, len); } } @@ -147,7 +150,7 @@ static void sptps_logger(sptps_t *s, int s_errno, const char *format, va_list ap char message[1024]; size_t msglen = sizeof(message); - if(!should_log(DEBUG_ALWAYS)) { + if(!should_log(DEBUG_TRAFFIC)) { return; } @@ -168,7 +171,7 @@ static void sptps_logger(sptps_t *s, int s_errno, const char *format, va_list ap } } - real_logger(DEBUG_ALWAYS, LOG_ERR, message); + real_logger(DEBUG_TRAFFIC, LOG_ERR, message); } void openlogger(const char *ident, logmode_t mode) { @@ -192,7 +195,7 @@ void openlogger(const char *ident, logmode_t mode) { break; case LOGMODE_SYSLOG: -#ifdef HAVE_MINGW +#ifdef HAVE_WINDOWS loghandle = RegisterEventSource(NULL, logident); if(!loghandle) { @@ -220,7 +223,7 @@ void openlogger(const char *ident, logmode_t mode) { } } -void reopenlogger() { +void reopenlogger(void) { if(logmode != LOGMODE_FILE) { return; } @@ -245,7 +248,7 @@ void closelogger(void) { break; case LOGMODE_SYSLOG: -#ifdef HAVE_MINGW +#ifdef HAVE_WINDOWS DeregisterEventSource(loghandle); break; #else