[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-cd-3-2' - common/Log.cpp common/Log.hpp common/Seccomp.cpp common/Util.cpp kit/ForKit.cpp kit/Kit.cpp wsd/LOOLWSD.cpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Tue Jul 17 17:45:02 UTC 2018


 common/Log.cpp     |   12 ++++++++++++
 common/Log.hpp     |    7 ++++++-
 common/Seccomp.cpp |    1 +
 common/Util.cpp    |    1 +
 kit/ForKit.cpp     |    6 ++++++
 kit/Kit.cpp        |   28 ++++++++++++++++++++--------
 wsd/LOOLWSD.cpp    |    2 ++
 7 files changed, 48 insertions(+), 9 deletions(-)

New commits:
commit b75e6840b40c4c1ff015f323f54346b0413b0d4c
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Mon Jul 16 21:42:17 2018 -0400

    wsd: flush logs before existing
    
    This is important for when we abort with some explanation.
    Often said explanation doesn't show up anywhere to be useful.
    
    Also, issue fatal logs for abnormal exist and use SFL to log errno.
    
    Change-Id: Ic67064ef40ef6e93d26e5847ecd32bdd49c3cc8b
    Reviewed-on: https://gerrit.libreoffice.org/57540
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>
    Tested-by: Jan Holesovsky <kendy at collabora.com>

diff --git a/common/Log.cpp b/common/Log.cpp
index 1d4d36d39..236e4bea6 100644
--- a/common/Log.cpp
+++ b/common/Log.cpp
@@ -16,6 +16,7 @@
 #include <cstring>
 #include <ctime>
 #include <iomanip>
+#include <iostream>
 #include <sstream>
 #include <string>
 
@@ -175,6 +176,17 @@ namespace Log
     {
         return Poco::Logger::get(Source.inited ? Source.name : std::string());
     }
+
+    void shutdown()
+    {
+        logger().shutdown();
+
+        // Flush
+        std::flush(std::cout);
+        fflush(stdout);
+        std::flush(std::cerr);
+        fflush(stderr);
+    }
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/common/Log.hpp b/common/Log.hpp
index e630c5678..fbafeeadc 100644
--- a/common/Log.hpp
+++ b/common/Log.hpp
@@ -30,13 +30,19 @@ inline std::ostream& operator<< (std::ostream& os, const Poco::Timestamp& ts)
 
 namespace Log
 {
+    /// Initialize the logging system.
     void initialize(const std::string& name,
                     const std::string& logLevel,
                     const bool withColor,
                     const bool logToFile,
                     std::map<std::string, std::string> config);
+
+    /// Returns the underlying logging system.
     Poco::Logger& logger();
 
+    /// Shutdown and release the logging system.
+    void shutdown();
+
     char* prefix(char* buffer, std::size_t len, const char* level);
 
     inline bool traceEnabled() { return logger().trace(); }
@@ -192,7 +198,6 @@ namespace Log
     do                                              \
     {                                               \
         LOG << "| " << __FILE__ << ':' << __LINE__; \
-        LOG.flush();                                \
     } while (false)
 
 #define LOG_BODY_(LOG, PRIO, LVL, X)                                                        \
diff --git a/common/Seccomp.cpp b/common/Seccomp.cpp
index 21fc83c35..7a1f101c3 100644
--- a/common/Seccomp.cpp
+++ b/common/Seccomp.cpp
@@ -74,6 +74,7 @@ static void handleSysSignal(int /* signal */,
 
     SigUtil::dumpBacktrace();
 
+    Log::shutdown();
     _exit(1);
 }
 
diff --git a/common/Util.cpp b/common/Util.cpp
index 4b57d429a..788757e1c 100644
--- a/common/Util.cpp
+++ b/common/Util.cpp
@@ -220,6 +220,7 @@ namespace Util
             int ret = execvp(params[0], &params[0]);
             if (ret < 0)
                 std::cerr << "Failed to exec command '" << cmd << "' with error '" << strerror(errno) << "'\n";
+            Log::shutdown();
             _exit(42);
         }
         // else spawning process still
diff --git a/kit/ForKit.cpp b/kit/ForKit.cpp
index 2548a1c61..7dcf1da5d 100644
--- a/kit/ForKit.cpp
+++ b/kit/ForKit.cpp
@@ -531,7 +531,11 @@ int main(int argc, char** argv)
 
     // Initialize LoKit
     if (!globalPreinit(loTemplate))
+    {
+        LOG_FTL("Failed to preinit lokit.");
+        Log::shutdown();
         std::_Exit(Application::EXIT_SOFTWARE);
+    }
 
     LOG_INF("Preinit stage OK.");
 
@@ -542,6 +546,7 @@ int main(int argc, char** argv)
     if (forKitPid < 0)
     {
         LOG_FTL("Failed to create a kit process.");
+        Log::shutdown();
         std::_Exit(Application::EXIT_SOFTWARE);
     }
 
@@ -578,6 +583,7 @@ int main(int argc, char** argv)
 #endif
 
     LOG_INF("ForKit process finished.");
+    Log::shutdown();
     std::_Exit(returnValue);
 }
 #endif
diff --git a/kit/Kit.cpp b/kit/Kit.cpp
index 3c70a8086..dfc0507cd 100644
--- a/kit/Kit.cpp
+++ b/kit/Kit.cpp
@@ -195,8 +195,9 @@ namespace
                 }
                 catch (const std::exception& exc)
                 {
-                    LOG_ERR("Copying of '" << fpath << "' to " << newPath.toString() <<
+                    LOG_FTL("Copying of '" << fpath << "' to " << newPath.toString() <<
                             " failed: " << exc.what() << ". Exiting.");
+                    Log::shutdown();
                     std::_Exit(Application::EXIT_SOFTWARE);
                 }
             }
@@ -268,7 +269,8 @@ namespace
         caps = cap_get_proc();
         if (caps == nullptr)
         {
-            LOG_SYS("cap_get_proc() failed.");
+            LOG_SFL("cap_get_proc() failed.");
+            Log::shutdown();
             std::_Exit(1);
         }
 
@@ -279,13 +281,15 @@ namespace
         if (cap_set_flag(caps, CAP_EFFECTIVE, sizeof(cap_list)/sizeof(cap_list[0]), cap_list, CAP_CLEAR) == -1 ||
             cap_set_flag(caps, CAP_PERMITTED, sizeof(cap_list)/sizeof(cap_list[0]), cap_list, CAP_CLEAR) == -1)
         {
-            LOG_SYS("cap_set_flag() failed.");
+            LOG_SFL("cap_set_flag() failed.");
+            Log::shutdown();
             std::_Exit(1);
         }
 
         if (cap_set_proc(caps) == -1)
         {
-            LOG_SYS("cap_set_proc() failed.");
+            LOG_SFL("cap_set_proc() failed.");
+            Log::shutdown();
             std::_Exit(1);
         }
 
@@ -812,7 +816,8 @@ public:
             num_sessions = _sessions.size();
             if (num_sessions == 0)
             {
-                LOG_INF("Document [" << anonymizeUrl(_url) << "] has no more views, exiting bluntly.");
+                LOG_FTL("Document [" << anonymizeUrl(_url) << "] has no more views, exiting bluntly.");
+                Log::shutdown();
                 std::_Exit(Application::EXIT_OK);
             }
         }
@@ -1295,6 +1300,7 @@ private:
             if (_sessions.empty())
             {
                 LOG_INF("Document [" << anonymizeUrl(_url) << "] has no more views, exiting bluntly.");
+                Log::shutdown();
                 std::_Exit(Application::EXIT_OK);
             }
 
@@ -2093,13 +2099,15 @@ void lokit_main(const std::string& childRoot,
             LOG_INF("chroot(\"" << jailPath.toString() << "\")");
             if (chroot(jailPath.toString().c_str()) == -1)
             {
-                LOG_SYS("chroot(\"" << jailPath.toString() << "\") failed.");
+                LOG_SFL("chroot(\"" << jailPath.toString() << "\") failed.");
+                Log::shutdown();
                 std::_Exit(Application::EXIT_SOFTWARE);
             }
 
             if (chdir("/") == -1)
             {
-                LOG_SYS("chdir(\"/\") in jail failed.");
+                LOG_SFL("chdir(\"/\") in jail failed.");
+                Log::shutdown();
                 std::_Exit(Application::EXIT_SOFTWARE);
             }
 
@@ -2141,6 +2149,7 @@ void lokit_main(const std::string& childRoot,
             if (!loKit)
             {
                 LOG_FTL("LibreOfficeKit initialization failed. Exiting.");
+                Log::shutdown();
                 std::_Exit(Application::EXIT_SOFTWARE);
             }
         }
@@ -2150,7 +2159,8 @@ void lokit_main(const std::string& childRoot,
         {
             if (!noSeccomp)
             {
-                LOG_ERR("LibreOfficeKit seccomp security lockdown failed. Exiting.");
+                LOG_FTL("LibreOfficeKit seccomp security lockdown failed. Exiting.");
+                Log::shutdown();
                 std::_Exit(Application::EXIT_SOFTWARE);
             }
 
@@ -2319,6 +2329,7 @@ void lokit_main(const std::string& childRoot,
         if (!loKitDoc || !loKitDoc->get())
         {
             LOG_ERR("Failed to load: " << uri << ", error: " << loKit->getError());
+            Log::shutdown();
             std::_Exit(Application::EXIT_OK);
         }
 
@@ -2341,6 +2352,7 @@ void lokit_main(const std::string& childRoot,
     // Trap the signal handler, if invoked,
     // to prevent exiting.
     LOG_INF("Process finished.");
+    Log::shutdown();
     std::unique_lock<std::mutex> lock(SigHandlerTrap);
     std::_Exit(Application::EXIT_OK);
 }
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 0674cd3ae..7c1b365d5 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -789,6 +789,7 @@ void LOOLWSD::initialize(Application& self)
 #if ENABLE_DEBUG
             std::cerr << "\nIf you have used 'make run', edit loolwsd.xml and make sure you have removed '--o:logging.level=trace' from the command line in Makefile.am.\n" << std::endl;
 #endif
+            Log::shutdown();
             _exit(Application::EXIT_SOFTWARE);
         }
     }
@@ -2691,6 +2692,7 @@ private:
         {
             LOG_FTL("Failed to listen on Prisoner port (" <<
                     MasterPortNumber << '-' << port << "). Exiting.");
+            Log::shutdown();
             _exit(Application::EXIT_SOFTWARE);
         }
 


More information about the Libreoffice-commits mailing list