[Libreoffice-commits] online.git: loolwsd/Admin.hpp loolwsd/Capabilities.hpp loolwsd/ChildProcessSession.cpp loolwsd/Connect.cpp loolwsd/LOKitClient.cpp loolwsd/LOOLBroker.cpp loolwsd/LOOLKit.cpp loolwsd/LOOLWSD.cpp loolwsd/LOOLWSD.hpp loolwsd/loolwsd-systemplate-setup loolwsd/QueueHandler.hpp loolwsd/Util.cpp

Tor Lillqvist tml at collabora.com
Mon Feb 29 12:26:25 UTC 2016


 loolwsd/Admin.hpp                 |    3 +--
 loolwsd/Capabilities.hpp          |   23 +----------------------
 loolwsd/ChildProcessSession.cpp   |    4 ++--
 loolwsd/Connect.cpp               |    3 +--
 loolwsd/LOKitClient.cpp           |    3 +--
 loolwsd/LOOLBroker.cpp            |    8 ++------
 loolwsd/LOOLKit.cpp               |   26 ++++----------------------
 loolwsd/LOOLWSD.cpp               |   16 ++++------------
 loolwsd/LOOLWSD.hpp               |    2 --
 loolwsd/QueueHandler.hpp          |    3 +--
 loolwsd/Util.cpp                  |   14 --------------
 loolwsd/loolwsd-systemplate-setup |   14 ++++++--------
 12 files changed, 23 insertions(+), 96 deletions(-)

New commits:
commit 9d655cbcc08a30bbcc3d838a2e2f23d767919b43
Author: Tor Lillqvist <tml at collabora.com>
Date:   Mon Feb 29 14:25:12 2016 +0200

    Don't pretend this will work on anything except Linux

diff --git a/loolwsd/Admin.hpp b/loolwsd/Admin.hpp
index 20ab8a9..b963702 100644
--- a/loolwsd/Admin.hpp
+++ b/loolwsd/Admin.hpp
@@ -65,10 +65,9 @@ public:
         const std::string thread_name = "admin_ws";
         try
         {
-#ifdef __linux
             if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(thread_name.c_str()), 0, 0, 0) != 0)
                 Log::error("Cannot set thread name to " + thread_name + ".");
-#endif
+
             Log::debug("Thread [" + thread_name + "] started.");
 
             auto ws = std::make_shared<WebSocket>(request, response);
diff --git a/loolwsd/Capabilities.hpp b/loolwsd/Capabilities.hpp
index 8fcd9ba..dc94540 100644
--- a/loolwsd/Capabilities.hpp
+++ b/loolwsd/Capabilities.hpp
@@ -10,20 +10,13 @@
 #ifndef INCLUDED_CAPABILITIES
 #define INCLUDED_CAPABILITIES
 
-#ifdef __linux
 #include <sys/capability.h>
-#endif
 
 #include "Util.hpp"
 
 static
-void dropCapability(
-#ifdef __linux
-                    cap_value_t capability
-#endif
-                    )
+void dropCapability(cap_value_t capability)
 {
-#ifdef __linux
     cap_t caps;
     cap_value_t cap_list[] = { capability };
 
@@ -56,20 +49,6 @@ void dropCapability(
     cap_free(capText);
 
     cap_free(caps);
-#else
-    // We assume that on non-Linux we don't need to be root to be able to hardlink to files we
-    // don't own, so drop root.
-    if (geteuid() == 0 && getuid() != 0)
-    {
-        // The program is setuid root. Not normal on Linux where we use setcap, but if this
-        // needs to run on non-Linux Unixes, setuid root is what it will bneed to be to be able
-        // to do chroot().
-        if (setuid(getuid()) != 0)
-        {
-            Log::error("Error: setuid() failed.");
-        }
-    }
-#endif
 }
 
 #endif
diff --git a/loolwsd/ChildProcessSession.cpp b/loolwsd/ChildProcessSession.cpp
index bef7a1a..0f9ad2b 100644
--- a/loolwsd/ChildProcessSession.cpp
+++ b/loolwsd/ChildProcessSession.cpp
@@ -252,10 +252,10 @@ public:
     void run()
     {
         static const std::string thread_name = "kit_callback";
-#ifdef __linux
+
         if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(thread_name.c_str()), 0, 0, 0) != 0)
             Log::error("Cannot set thread name to " + thread_name + ".");
-#endif
+
         Log::debug("Thread [" + thread_name + "] started.");
 
         while (!_stop && !TerminationFlag)
diff --git a/loolwsd/Connect.cpp b/loolwsd/Connect.cpp
index 43da98b..e0f82ea 100644
--- a/loolwsd/Connect.cpp
+++ b/loolwsd/Connect.cpp
@@ -82,7 +82,7 @@ public:
 
                     std::string firstLine = getFirstLine(buffer, n);
                     StringTokenizer tokens(firstLine, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
-#ifdef __linux
+
                     if (std::getenv("DISPLAY") != nullptr && tokens[0] == "tile:")
                     {
                         TemporaryFile pngFile;
@@ -95,7 +95,6 @@ public:
                             // the developer running it surely notices if nothing shows up...
                         }
                     }
-#endif
                 }
             }
             while (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE);
diff --git a/loolwsd/LOKitClient.cpp b/loolwsd/LOKitClient.cpp
index d44f8ae..cd52a1c 100644
--- a/loolwsd/LOKitClient.cpp
+++ b/loolwsd/LOKitClient.cpp
@@ -178,7 +178,7 @@ protected:
                 std::ofstream pngStream(pngFile.path(), std::ios::binary);
                 pngStream.write(png.data(), png.size());
                 pngStream.close();
-#ifdef __linux
+
                 if (std::getenv("DISPLAY") != nullptr)
                 {
                     if (std::system((std::string("display ") + pngFile.path()).c_str()) == -1)
@@ -187,7 +187,6 @@ protected:
                         // the developer running it surely notices if nothing shows up...
                     }
                 }
-#endif
             }
             else
             {
diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index bc11143..05124a6 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -355,10 +355,10 @@ public:
         end   = buffer;
 
         static const std::string thread_name = "brk_pipe_reader";
-#ifdef __linux
+
         if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(thread_name.c_str()), 0, 0, 0) != 0)
             Log::error("Cannot set thread name to " + thread_name + ".");
-#endif
+
         Log::debug("Thread [" + thread_name + "] started.");
 
         while (!TerminationFlag)
@@ -801,13 +801,9 @@ int main(int argc, char** argv)
 
     if (!sharePages)
     {
-#ifdef __linux
         dropCapability(CAP_SYS_CHROOT);
         dropCapability(CAP_MKNOD);
         dropCapability(CAP_FOWNER);
-#else
-        dropCapability();
-#endif
     }
 
     PipeRunnable pipeHandler;
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index 969bfdb..27f4993 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -84,12 +84,6 @@ namespace
 
         assert(fpath[strlen(sourceForLinkOrCopy->c_str())] == '/');
         const char *relativeOldPath = fpath + strlen(sourceForLinkOrCopy->c_str()) + 1;
-
-#ifdef __APPLE__
-        if (strcmp(relativeOldPath, "PkgInfo") == 0)
-            return 0;
-#endif
-
         Path newPath(*destinationForLinkOrCopy, Path(relativeOldPath));
 
         switch (typeflag)
@@ -204,10 +198,10 @@ public:
     void run() override
     {
         const std::string thread_name = "kit_ws_" + _session->getId();
-#ifdef __linux
+
         if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(thread_name.c_str()), 0, 0, 0) != 0)
             Log::error("Cannot set thread name to " + thread_name + ".");
-#endif
+
         Log::debug("Thread [" + thread_name + "] started.");
 
         try
@@ -785,21 +779,15 @@ void lokit_main(const std::string& childRoot,
     static const std::string jailId = std::to_string(Process::id());
     static const std::string process_name = "loolkit";
 
-#ifdef __linux
     if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(process_name.c_str()), 0, 0, 0) != 0)
         Log::error("Cannot set process name to " + process_name + ".");
 
     Util::setTerminationSignals();
     Util::setFatalSignals();
-#endif
+
     Log::debug("Process [" + process_name + "] started.");
 
-    static const std::string instdir_path =
-#ifdef __APPLE__
-                    ("/" + loSubPath + "/Frameworks");
-#else
-                    ("/" + loSubPath + "/program");
-#endif
+    static const std::string instdir_path = "/" + loSubPath + "/program";
     LibreOfficeKit* loKit = nullptr;
 
     try
@@ -866,7 +854,6 @@ void lokit_main(const std::string& childRoot,
             }
         }
 
-#ifdef __linux
         // Create the urandom and random devices
         File(Path(jailPath, "/dev")).createDirectory();
         if (mknod((jailPath.toString() + "/dev/random").c_str(),
@@ -900,7 +887,6 @@ void lokit_main(const std::string& childRoot,
         {
             Log::error("Error: chown(" + jailPath.toString() + "/dev/urandom, 0, 0) failed.");
         }
-#endif
 
         Log::info("chroot(\"" + jailPath.toString() + "\")");
         if (chroot(jailPath.toString().c_str()) == -1)
@@ -915,14 +901,10 @@ void lokit_main(const std::string& childRoot,
             exit(Application::EXIT_SOFTWARE);
         }
 
-#ifdef __linux
         dropCapability(CAP_SYS_CHROOT);
         dropCapability(CAP_MKNOD);
         dropCapability(CAP_CHOWN);
         dropCapability(CAP_FOWNER);
-#else
-        dropCapability();
-#endif
 
         loKit = lok_init_2(instdir_path.c_str(), "file:///user");
         if (loKit == nullptr)
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 6649f41..69a3774 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -44,11 +44,9 @@ DEALINGS IN THE SOFTWARE.
 #include <locale.h>
 #include <unistd.h>
 
-#ifdef __linux
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <sys/prctl.h>
-#endif
 
 #include <ftw.h>
 #include <utime.h>
@@ -555,10 +553,9 @@ public:
         const auto id = LOOLWSD::GenSessionId();
         const std::string thread_name = "client_ws_" + id;
 
-#ifdef __linux
         if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(thread_name.c_str()), 0, 0, 0) != 0)
             Log::error("Cannot set thread name to " + thread_name + ".");
-#endif
+
         Log::debug("Thread [" + thread_name + "] started.");
 
         try
@@ -610,10 +607,9 @@ public:
 
             thread_name += id;
 
-#ifdef __linux
             if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(thread_name.c_str()), 0, 0, 0) != 0)
                 Log::error("Cannot set thread name to " + thread_name + ".");
-#endif
+
             Log::debug("Thread [" + thread_name + "] started.");
 
             auto ws = std::make_shared<WebSocket>(request, response);
@@ -649,10 +645,8 @@ class RequestHandlerFactory: public HTTPRequestHandlerFactory
 public:
     HTTPRequestHandler* createRequestHandler(const HTTPServerRequest& request) override
     {
-#ifdef __linux
         if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>("request_handler"), 0, 0, 0) != 0)
             Log::error("Cannot set thread name to request_handler.");
-#endif
 
         auto logger = Log::info();
         logger << "Request from " << request.clientAddress().toString() << ": "
@@ -910,23 +904,21 @@ Process::PID LOOLWSD::createBroker()
 int LOOLWSD::main(const std::vector<std::string>& /*args*/)
 {
     Log::initialize("wsd");
-#ifdef __linux
+
     if (geteuid() == 0)
     {
         Log::error("Don't run this as root");
         return Application::EXIT_USAGE;
     }
-#endif
+
     //Environment::set("LOK_PREINIT", "1");
     //Environment::set("LOK_FORK", "1");
     //Environment::set("LD_BIND_NOW", "1");
     //Environment::set("LOK_VIEW_CALLBACK", "1");
 
-#ifdef __linux
     char *locale = setlocale(LC_ALL, nullptr);
     if (locale == nullptr || std::strcmp(locale, "C") == 0)
         setlocale(LC_ALL, "en_US.utf8");
-#endif
 
     Util::setTerminationSignals();
     Util::setFatalSignals();
diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index db26497..696ca3a 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -73,14 +73,12 @@ public:
             Log::info("Public URI [" + uriPublic.toString() +
                       "] jailed to [" + uriJailed.toString() + "].");
 
-#ifdef __linux
             Log::info("Linking " + publicFilePath + " to " + jailedFilePath);
             if (!Poco::File(jailedFilePath).exists() && link(publicFilePath.c_str(), jailedFilePath.c_str()) == -1)
             {
                 // Failed
                 Log::error("link(\"" + publicFilePath + "\", \"" + jailedFilePath + "\") failed.");
             }
-#endif
 
             try
             {
diff --git a/loolwsd/QueueHandler.hpp b/loolwsd/QueueHandler.hpp
index 9ac17a2..35d5f7c 100644
--- a/loolwsd/QueueHandler.hpp
+++ b/loolwsd/QueueHandler.hpp
@@ -27,10 +27,9 @@ public:
 
     void run() override
     {
-#ifdef __linux
         if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(_name.c_str()), 0, 0, 0) != 0)
             Log::error("Cannot set thread name to " + _name + ".");
-#endif
+
         Log::debug("Thread [" + _name + "] started.");
 
         try
diff --git a/loolwsd/Util.cpp b/loolwsd/Util.cpp
index 4655f3c..220f6c1 100644
--- a/loolwsd/Util.cpp
+++ b/loolwsd/Util.cpp
@@ -8,9 +8,7 @@
  */
 
 #include <sys/poll.h>
-#ifdef __linux
 #include <sys/prctl.h>
-#endif
 
 #include <cstdlib>
 #include <cstring>
@@ -102,11 +100,9 @@ namespace Log
                << std::setw(2) << seconds << "." << std::setw(6) << usec
                << ' ';
 
-#ifdef __linux
         char buf[32]; // we really need only 16
         if (prctl(PR_GET_NAME, reinterpret_cast<unsigned long>(buf), 0, 0, 0) == 0)
             stream << '[' << std::setw(15) << std::setfill(' ') << std::left << buf << "] ";
-#endif
 
         return stream.str();
     }
@@ -224,11 +220,7 @@ namespace Util
 
     bool windowingAvailable()
     {
-#ifdef __linux
         return std::getenv("DISPLAY") != nullptr;
-#endif
-
-        return false;
     }
 
     bool encodeBufferToPNG(unsigned char *pixmap, int width, int height, std::vector<char>& output, LibreOfficeKitTileMode mode)
@@ -432,7 +424,6 @@ namespace Util
 
     void setTerminationSignals()
     {
-#ifdef __linux
         struct sigaction action;
 
         sigemptyset(&action.sa_mask);
@@ -443,7 +434,6 @@ namespace Util
         sigaction(SIGINT, &action, nullptr);
         sigaction(SIGQUIT, &action, nullptr);
         sigaction(SIGHUP, &action, nullptr);
-#endif
     }
 
     static
@@ -462,7 +452,6 @@ namespace Util
             sleep(10);
         }
 
-#ifdef __linux
         struct sigaction action;
 
         sigemptyset(&action.sa_mask);
@@ -472,12 +461,10 @@ namespace Util
         sigaction(signal, &action, NULL);
         // let default handler process the signal
         kill(Poco::Process::id(), signal);
-#endif
     }
 
     void setFatalSignals()
     {
-#ifdef __linux
         struct sigaction action;
 
         sigemptyset(&action.sa_mask);
@@ -489,7 +476,6 @@ namespace Util
         sigaction(SIGABRT, &action, NULL);
         sigaction(SIGILL, &action, NULL);
         sigaction(SIGFPE, &action, NULL);
-#endif
     }
 
     int getChildStatus(const int code)
diff --git a/loolwsd/loolwsd-systemplate-setup b/loolwsd/loolwsd-systemplate-setup
index 2b346a5..87af9e0 100755
--- a/loolwsd/loolwsd-systemplate-setup
+++ b/loolwsd/loolwsd-systemplate-setup
@@ -79,12 +79,10 @@ mkdir -p $CHROOT/usr/bin/
 
 cd $CHROOT || exit 1
 
-if [ `uname -s` = Linux ]; then
-    mkdir -p usr/share || exit 1
-    cp -r -p /usr/share/fonts usr/share
-
-    if [ -h usr/share/fonts/ghostscript ]; then
-	mkdir usr/share/ghostscript || exit 1
-	cp -r -p /usr/share/ghostscript/fonts usr/share/ghostscript
-    fi
+mkdir -p usr/share || exit 1
+cp -r -p /usr/share/fonts usr/share
+
+if [ -h usr/share/fonts/ghostscript ]; then
+    mkdir usr/share/ghostscript || exit 1
+    cp -r -p /usr/share/ghostscript/fonts usr/share/ghostscript
 fi


More information about the Libreoffice-commits mailing list