[Libreoffice-commits] online.git: 2 commits - loolwsd/Log.cpp loolwsd/Log.hpp loolwsd/LOOLForKit.cpp loolwsd/LOOLKit.cpp loolwsd/LOOLWSD.cpp

Tor Lillqvist tml at collabora.com
Fri Oct 14 10:03:31 UTC 2016


 loolwsd/LOOLForKit.cpp |   10 +++++-----
 loolwsd/LOOLKit.cpp    |   14 +++++++-------
 loolwsd/LOOLWSD.cpp    |   18 +++++++++++++-----
 loolwsd/Log.cpp        |   10 ++++++++++
 loolwsd/Log.hpp        |    8 ++++++++
 5 files changed, 43 insertions(+), 17 deletions(-)

New commits:
commit 650ab54d00594fdf5746e2517f4d7a90109ec376
Author: Tor Lillqvist <tml at collabora.com>
Date:   Fri Oct 14 12:57:27 2016 +0300

    Log fatal errors as such

diff --git a/loolwsd/LOOLForKit.cpp b/loolwsd/LOOLForKit.cpp
index a5f97a4..7f95ef2 100644
--- a/loolwsd/LOOLForKit.cpp
+++ b/loolwsd/LOOLForKit.cpp
@@ -112,7 +112,7 @@ static bool haveCapability(cap_value_t capability)
 
     if (caps == nullptr)
     {
-        Log::syserror("cap_get_proc() failed.");
+        Log::sysfatal("cap_get_proc() failed.");
         return false;
     }
 
@@ -123,12 +123,12 @@ static bool haveCapability(cap_value_t capability)
     {
         if (cap_name)
         {
-            Log::syserror("cap_get_flag failed for " + std::string(cap_name) + ".");
+            Log::sysfatal("cap_get_flag failed for " + std::string(cap_name) + ".");
             cap_free(cap_name);
         }
         else
         {
-            Log::syserror("cap_get_flag failed for capability " + std::to_string(capability) + ".");
+            Log::sysfatal("cap_get_flag failed for capability " + std::to_string(capability) + ".");
         }
         return false;
     }
@@ -137,7 +137,7 @@ static bool haveCapability(cap_value_t capability)
     {
         if (cap_name)
         {
-            Log::error("Capability " + std::string(cap_name) + " is not set for the loolforkit program.");
+            Log::fatal("Capability " + std::string(cap_name) + " is not set for the loolforkit program.");
             cap_free(cap_name);
         }
         else
@@ -376,7 +376,7 @@ int main(int argc, char** argv)
     // Ask this first child to send version information to master process
     if (createLibreOfficeKit(childRoot, sysTemplate, loTemplate, loSubPath, true) < 0)
     {
-        Log::error("Failed to create a kit process.");
+        Log::fatal("Failed to create a kit process.");
         std::_Exit(Application::EXIT_SOFTWARE);
     }
 
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index 426d684..cd62e12 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -179,7 +179,7 @@ namespace
             Log::error("nftw: stat failed for '" + std::string(fpath) + "'");
             return 1;
         default:
-            Log::error("nftw: unexpected type: '" + std::to_string(typeflag));
+            Log::fatal("nftw: unexpected type: '" + std::to_string(typeflag));
             assert(false);
             break;
         }
@@ -1454,7 +1454,7 @@ void lokit_main(const std::string& childRoot,
             loKit = std::make_shared<lok::Office>(kit);
             if (!loKit || !loKit->get())
             {
-                Log::error("LibreOfficeKit initialization failed. Exiting.");
+                Log::fatal("LibreOfficeKit initialization failed. Exiting.");
                 std::_Exit(Application::EXIT_SOFTWARE);
             }
         }
@@ -1616,7 +1616,7 @@ bool globalPreinit(const std::string &loTemplate)
         handle = dlopen(libMerged.c_str(), RTLD_GLOBAL|RTLD_NOW);
         if (!handle)
         {
-            Log::error("Failed to load " + libMerged + ": " + std::string(dlerror()));
+            Log::fatal("Failed to load " + libMerged + ": " + std::string(dlerror()));
             return false;
         }
         loadedLibrary = libMerged;
@@ -1629,14 +1629,14 @@ bool globalPreinit(const std::string &loTemplate)
             handle = dlopen(libSofficeapp.c_str(), RTLD_GLOBAL|RTLD_NOW);
             if (!handle)
             {
-                Log::error("Failed to load " + libSofficeapp + ": " + std::string(dlerror()));
+                Log::fatal("Failed to load " + libSofficeapp + ": " + std::string(dlerror()));
                 return false;
             }
             loadedLibrary = libSofficeapp;
         }
         else
         {
-            Log::error("Neither " + libSofficeapp + " or " + libMerged + " exist.");
+            Log::fatal("Neither " + libSofficeapp + " or " + libMerged + " exist.");
             return false;
         }
     }
@@ -1644,14 +1644,14 @@ bool globalPreinit(const std::string &loTemplate)
     LokHookPreInit* preInit = (LokHookPreInit *)dlsym(handle, "lok_preinit");
     if (!preInit)
     {
-        Log::error("No lok_preinit symbol in " + loadedLibrary + ": " + std::string(dlerror()));
+        Log::fatal("No lok_preinit symbol in " + loadedLibrary + ": " + std::string(dlerror()));
         return false;
     }
 
     Log::trace("lok_preinit(" + loTemplate + "/program\", \"file:///user\")");
     if (preInit((loTemplate + "/program").c_str(), "file:///user") != 0)
     {
-        Log::error("lok_preinit() in " + loadedLibrary + " failed");
+        Log::fatal("lok_preinit() in " + loadedLibrary + " failed");
         return false;
     }
 
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 1b176eb..d801502 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -1417,7 +1417,7 @@ ServerSocket* getServerSocket(int nClientPortNumber)
     }
     catch (const Exception& exc)
     {
-        Log::error() << "Could not create server socket: " << exc.displayText() << Log::end;
+        Log::fatal() << "Could not create server socket: " << exc.displayText() << Log::end;
         return nullptr;
     }
 }
@@ -1904,7 +1904,7 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
 
     if (access(Cache.c_str(), R_OK | W_OK | X_OK) != 0)
     {
-        Log::syserror("Unable to access cache [" + Cache +
+        Log::sysfatal("Unable to access cache [" + Cache +
                       "] please make sure it exists, and has write permission for this user.");
         return Application::EXIT_SOFTWARE;
     }
@@ -1914,12 +1914,20 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
     // child) separately now. Also check for options that are
     // meaningless for the parent.
     if (SysTemplate.empty())
+    {
+        Log::fatal("Missing --systemplate option");
         throw MissingOptionException("systemplate");
+    }
     if (LoTemplate.empty())
+    {
+        Log::fatal("Missing --lotemplate option");
         throw MissingOptionException("lotemplate");
-
+    }
     if (ChildRoot.empty())
+    {
+        Log::fatal("Missing --childroot option");
         throw MissingOptionException("childroot");
+    }
     else if (ChildRoot[ChildRoot.size() - 1] != '/')
         ChildRoot += '/';
 
@@ -1967,7 +1975,7 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
     const Process::PID forKitPid = createForKit();
     if (forKitPid < 0)
     {
-        Log::error("Failed to spawn loolforkit.");
+        Log::fatal("Failed to spawn loolforkit.");
         return Application::EXIT_SOFTWARE;
     }
 
@@ -2039,7 +2047,7 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
             if (errno == ECHILD)
             {
                 // No child processes.
-                Log::error("No Forkit instance. Terminating.");
+                Log::fatal("No Forkit instance. Terminating.");
                 TerminationFlag = true;
                 continue;
             }
commit 0e047c8a1a397be1a6f48a64143f4cd101d6d2d2
Author: Tor Lillqvist <tml at collabora.com>
Date:   Fri Oct 14 12:47:48 2016 +0300

    Add Log API for the 'FATAL' priority
    
    To be used only for truly fatal configuration or resource errors when
    the lool service cannot continue functioning at all.
    
    Add also a sysfatal() variant that appends the strerror(errno)
    message, like syserror().

diff --git a/loolwsd/Log.cpp b/loolwsd/Log.cpp
index 9885d9f..e9b9576 100644
--- a/loolwsd/Log.cpp
+++ b/loolwsd/Log.cpp
@@ -186,6 +186,16 @@ namespace Log
     {
         logger().error(prefix("ERR") + msg + " (errno: " + std::string(std::strerror(errno)) + ")");
     }
+
+    void fatal(const std::string& msg)
+    {
+        logger().fatal(prefix("FTL") + msg);
+    }
+
+    void sysfatal(const std::string& msg)
+    {
+        logger().fatal(prefix("FTL") + msg + " (errno: " + std::string(std::strerror(errno)) + ")");
+    }
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/loolwsd/Log.hpp b/loolwsd/Log.hpp
index 76c5605..93724a2 100644
--- a/loolwsd/Log.hpp
+++ b/loolwsd/Log.hpp
@@ -32,6 +32,8 @@ namespace Log
     void warn(const std::string& msg);
     void error(const std::string& msg);
     void syserror(const std::string& msg);
+    void fatal(const std::string& msg);
+    void sysfatal(const std::string& msg);
 
     /// Signal safe prefix logging
     void signalLogPrefix();
@@ -105,6 +107,12 @@ namespace Log
         return StreamLogger([](const std::string& msg) { error(msg);});
     }
 
+    inline
+    StreamLogger fatal()
+    {
+        return StreamLogger([](const std::string& msg) { fatal(msg);});
+    }
+
     template <typename U>
     StreamLogger& operator <<(StreamLogger& lhs, const U& rhs)
     {


More information about the Libreoffice-commits mailing list