Bug 1306920 - Make sure log file is closed when clearing it at runtime r=nfroyd
authorValentin Gosu <valentin.gosu@gmail.com>
Wed, 05 Oct 2016 11:34:12 +0200
changeset 316573 7cedca0e724800f47dc7d0b3ed31683f18829537
parent 316572 af72e3cf941f708a58ec68d1a4ba5dfe669e35c0
child 316574 e8fa13708c070d1fadf488ed9d951464745b4e17
child 316668 68fb465c29515f215eeb623f097cf4f2fa8dbcc0
push id30776
push usercbook@mozilla.com
push dateWed, 05 Oct 2016 13:43:03 +0000
treeherdermozilla-central@e8fa13708c07 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnfroyd
bugs1306920
milestone52.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1306920 - Make sure log file is closed when clearing it at runtime r=nfroyd
xpcom/base/Logging.cpp
--- a/xpcom/base/Logging.cpp
+++ b/xpcom/base/Logging.cpp
@@ -143,16 +143,25 @@ ExpandPIDMarker(const char* aFilename, c
     return buffer;
   }
 
   return aFilename;
 }
 
 } // detail
 
+namespace {
+  // Helper method that initializes an empty va_list to be empty.
+  void empty_va(va_list *va, ...)
+  {
+    va_start(*va, va);
+    va_end(*va);
+  }
+}
+
 class LogModuleManager
 {
 public:
   LogModuleManager()
     : mModulesLock("logmodules")
     , mModules(kInitialModuleCount)
     , mPrintEntryCount(0)
     , mOutFile(nullptr)
@@ -270,16 +279,24 @@ public:
     detail::LogFile* newFile = OpenFile(false, 0);
     detail::LogFile* oldFile = mOutFile.exchange(newFile);
 
     // Since we don't allow changing the logfile if MOZ_LOG_FILE is already set,
     // and we don't allow log rotation when setting it at runtime, mToReleaseFile
     // will be null, so we're not leaking.
     DebugOnly<detail::LogFile*> prevFile = mToReleaseFile.exchange(oldFile);
     MOZ_ASSERT(!prevFile, "Should be null because rotation is not allowed");
+
+    // If we just need to release a file, we must force print, in order to
+    // trigger the closing and release of mToReleaseFile.
+    if (oldFile) {
+      va_list va;
+      empty_va(&va);
+      Print("Logger", LogLevel::Info, "Flushing old log files\n", va);
+    }
   }
 
   uint32_t GetLogFile(char *aBuffer, size_t aLength)
   {
     uint32_t len = strlen(mOutFilePath.get());
     if (len + 1 > aLength) {
       return 0;
     }