[Libreoffice-commits] online.git: loolwsd/configure.ac loolwsd/LOOLForKit.cpp loolwsd/LOOLWSD.cpp loolwsd/LOOLWSD.hpp loolwsd/loolwsd.service loolwsd/test loolwsd/Util.cpp loolwsd/Util.hpp

Michael Meeks michael.meeks at collabora.com
Fri Apr 15 14:09:10 UTC 2016


 loolwsd/LOOLForKit.cpp      |    4 ++++
 loolwsd/LOOLWSD.cpp         |   16 +++++++---------
 loolwsd/LOOLWSD.hpp         |    1 -
 loolwsd/Util.cpp            |   10 ++++++++++
 loolwsd/Util.hpp            |    3 +++
 loolwsd/configure.ac        |   10 ++++++++++
 loolwsd/loolwsd.service     |    2 +-
 loolwsd/test/run_test.sh.in |    7 +++++--
 8 files changed, 40 insertions(+), 13 deletions(-)

New commits:
commit a49f642801ba54ba3dc0692439bdbb9c8cac985a
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Fri Apr 15 15:07:24 2016 +0100

    Tolerate --version, and add git hash version, print on default start.
    
    Should help diagnosing issues - to have this in our logs.

diff --git a/loolwsd/LOOLForKit.cpp b/loolwsd/LOOLForKit.cpp
index 256a2c3..ffebf56 100644
--- a/loolwsd/LOOLForKit.cpp
+++ b/loolwsd/LOOLForKit.cpp
@@ -202,6 +202,10 @@ int main(int argc, char** argv)
             eq = std::strchr(cmd, '=');
             ClientPortNumber = std::stoll(std::string(eq+1));
         }
+        else if (std::strstr(cmd, "--version") == cmd)
+        {
+            Util::displayVersionInfo("loolforkit");
+        }
 #if ENABLE_DEBUG
         // this process has various privileges - don't run arbitrary code.
         else if (std::strstr(cmd, "--unitlib=") == cmd)
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 9d14ca9..31ed0d2 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -146,6 +146,7 @@ int ClientPortNumber = DEFAULT_CLIENT_PORT_NUMBER;
 
 /// New LOK child processes ready to host documents.
 //TODO: Move to a more sensible namespace.
+static bool DisplayVersion = false;
 static std::vector<std::shared_ptr<ChildProcess>> newChildren;
 static std::mutex newChildrenMutex;
 static std::condition_variable newChildrenCV;
@@ -1233,10 +1234,7 @@ void LOOLWSD::handleOption(const std::string& optionName,
         std::exit(Application::EXIT_OK);
     }
     else if (optionName == "version")
-    {
-        displayVersion();
-        std::exit(Application::EXIT_OK);
-    }
+        DisplayVersion = true;
     else if (optionName == "port")
         ClientPortNumber = std::stoi(value);
     else if (optionName == "cache")
@@ -1274,11 +1272,6 @@ void LOOLWSD::displayHelp()
     helpFormatter.format(std::cout);
 }
 
-void LOOLWSD::displayVersion()
-{
-    std::cout << LOOLWSD_VERSION << std::endl;
-}
-
 Process::PID LOOLWSD::createForKit()
 {
     Process::Args args;
@@ -1290,6 +1283,8 @@ Process::PID LOOLWSD::createForKit()
     args.push_back("--clientport=" + std::to_string(ClientPortNumber));
     if (UnitWSD::get().hasKitHooks())
         args.push_back("--unitlib=" + UnitTestLibrary);
+    if (DisplayVersion)
+        args.push_back("--version");
 
     const std::string forKitPath = Path(Application::instance().commandPath()).parent().toString() + "loolforkit";
 
@@ -1305,6 +1300,9 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
 {
     Log::initialize("wsd");
 
+    if (DisplayVersion)
+        Util::displayVersionInfo("loolwsd");
+
     if (geteuid() == 0)
     {
         Log::error("Don't run this as root");
diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index ae290e4..5562837 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -65,7 +65,6 @@ protected:
 private:
     void initializeSSL();
     void displayHelp();
-    void displayVersion();
     Poco::Process::PID createForKit();
 
     /// Reads and processes path entries with the given property
diff --git a/loolwsd/Util.cpp b/loolwsd/Util.cpp
index 32b9072..8952179 100644
--- a/loolwsd/Util.cpp
+++ b/loolwsd/Util.cpp
@@ -7,6 +7,8 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
+#include "config.h"
+
 #include <execinfo.h>
 #include <sys/poll.h>
 #include <sys/prctl.h>
@@ -15,6 +17,7 @@
 #include <cassert>
 #include <cstdlib>
 #include <cstring>
+#include <iostream>
 #include <iomanip>
 #include <mutex>
 #include <random>
@@ -448,6 +451,13 @@ namespace Util
         if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(s.c_str()), 0, 0, 0) != 0)
             Log::syserror("Cannot set thread name to " + s + ".");
     }
+
+    void displayVersionInfo(const char *app)
+    {
+        std::string hash(LOOLWSD_VERSION_HASH);
+        hash.resize(std::min(8, (int)hash.length()));
+        std::cout << app << " " << LOOLWSD_VERSION << " - " << hash << std::endl;
+    }
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/loolwsd/Util.hpp b/loolwsd/Util.hpp
index 46b973b..223d0fb 100644
--- a/loolwsd/Util.hpp
+++ b/loolwsd/Util.hpp
@@ -114,6 +114,9 @@ namespace Util
 
     /// Ensure that we have the correct UID unless in debug mode.
     bool hasCorrectUID();
+
+    /// Display version information
+    void displayVersionInfo(const char *app);
 };
 
 #endif
diff --git a/loolwsd/configure.ac b/loolwsd/configure.ac
index 90a1a46..48b2539 100644
--- a/loolwsd/configure.ac
+++ b/loolwsd/configure.ac
@@ -22,6 +22,15 @@ AC_SUBST([LOOLWSD_VERSION])
 
 AC_DEFINE_UNQUOTED([LOOLWSD_VERSION],[["$LOOLWSD_VERSION"]],[LibreOffice On-Line WebSocket server version])
 
+# try to add a git hash for a version if we're developing
+LOOLWSD_VERSION_HASH=package
+git_hash=`cd ${ac_srcdir} && git log -1 --format=%H 2> /dev/null`
+if test "z$git_hash" != "z"; then
+   LOOLWSD_VERSION_HASH=$git_hash
+fi
+
+AC_DEFINE_UNQUOTED([LOOLWSD_VERSION_HASH],[["$LOOLWSD_VERSION_HASH"]],[LibreOffice On-Line git hash if present])
+
 AC_CONFIG_SRCDIR([LOOLWSD.cpp])
 
 AC_CONFIG_HEADERS([config.h])
@@ -260,3 +269,4 @@ echo "    \$ make run # to start loolwsd
 fi
 
 dnl vim:set shiftwidth=4 softtabstop=4 expandtab:
+
diff --git a/loolwsd/loolwsd.service b/loolwsd/loolwsd.service
index fdc32c5..13107c1 100644
--- a/loolwsd/loolwsd.service
+++ b/loolwsd/loolwsd.service
@@ -4,7 +4,7 @@ After=network.target
 
 [Service]
 EnvironmentFile=-/etc/sysconfig/loolwsd
-ExecStart=/usr/bin/loolwsd --systemplate=/opt/lool/systemplate --lotemplate=/opt/collaboraoffice5.0 --childroot=/opt/lool/child-roots --numprespawns=5 --fileserverroot=/usr/share/loolwsd
+ExecStart=/usr/bin/loolwsd --version --systemplate=/opt/lool/systemplate --lotemplate=/opt/collaboraoffice5.0 --childroot=/opt/lool/child-roots --numprespawns=5 --fileserverroot=/usr/share/loolwsd
 User=lool
 KillMode=control-group
 Restart=always
diff --git a/loolwsd/test/run_test.sh.in b/loolwsd/test/run_test.sh.in
index c52034e..f7895c7 100755
--- a/loolwsd/test/run_test.sh.in
+++ b/loolwsd/test/run_test.sh.in
@@ -18,16 +18,19 @@ if test "z at ENABLE_DEBUG@" != "ztrue"; then
     exit 1;
 fi
 
+echo "Running cppunit test ...";
+
 # result logging
 echo > $test_output
 
-echo "Running cppunit test ...";
-
 ${abs_top_builddir}/loolwsd --systemplate="@SYSTEMPLATE_PATH@" --lotemplate="@LO_PATH@" \
            --childroot="@JAILS_PATH@" --allowlocalstorage 2>$test_log_output/run_test.log &
 
+echo "  waiting for loolwsd to start"
 sleep 1 # sad - need to add a wait to the start of test.cpp ...
 
+echo "  executing test"
+
 cd $test_build
 if ./test; then
 	echo "Test run_test.sh passed."


More information about the Libreoffice-commits mailing list