]> granicus.if.org Git - icinga2/commitdiff
ApiListener#RotateLogFile(): don't overwrite previous log
authorAlexander A. Klimov <alexander.klimov@icinga.com>
Wed, 17 Apr 2019 12:31:49 +0000 (14:31 +0200)
committerAlexander A. Klimov <alexander.klimov@icinga.com>
Thu, 18 Apr 2019 15:22:33 +0000 (17:22 +0200)
lib/remote/apilistener.cpp

index 8aea0915954d0a63725faf230400eed7a26db95e..a5bbb8079742f3b6fcbdff20c3643ebcb8eb24c4 100644 (file)
@@ -1148,13 +1148,11 @@ void ApiListener::RotateLogFile()
        String oldpath = GetApiDir() + "log/current";
        String newpath = GetApiDir() + "log/" + Convert::ToString(static_cast<int>(ts)+1);
 
-
-#ifdef _WIN32
-       _unlink(newpath.CStr());
-#endif /* _WIN32 */
-
-
-       (void) rename(oldpath.CStr(), newpath.CStr());
+       // If the log is being rotated more than once per second,
+       // don't overwrite the previous one, but silently deny rotation.
+       if (!Utility::PathExists(newpath)) {
+               (void) rename(oldpath.CStr(), newpath.CStr());
+       }
 }
 
 void ApiListener::LogGlobHandler(std::vector<int>& files, const String& file)