Replace MinGW with Windows to avoid ambiguities
[tinc] / src / logger.c
index 1a2e95f..390023b 100644 (file)
@@ -1,6 +1,6 @@
 /*
     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
@@ -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.
+                       }
                }
        }
 
@@ -113,7 +116,7 @@ static void real_logger(debug_t level, int priority, const char *message) {
 
                        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);
                        }
                }
@@ -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