[Libreoffice-commits] online.git: kit/ForKit.cpp kit/Kit.cpp net/DelaySocket.cpp net/ServerSocket.hpp net/Socket.cpp net/Socket.hpp net/SslSocket.hpp net/WebSocketHandler.hpp tools/WebSocketDump.cpp wsd/Admin.cpp wsd/Admin.hpp wsd/DocumentBroker.cpp wsd/LOOLWSD.cpp

Michael Meeks (via logerrit) logerrit at kemper.freedesktop.org
Fri Apr 10 11:58:19 UTC 2020


 kit/ForKit.cpp           |    2 +-
 kit/Kit.cpp              |    4 ++--
 net/DelaySocket.cpp      |    4 ++--
 net/ServerSocket.hpp     |    4 ++--
 net/Socket.cpp           |    6 +++---
 net/Socket.hpp           |   18 +++++++++---------
 net/SslSocket.hpp        |    6 +++---
 net/WebSocketHandler.hpp |    2 +-
 tools/WebSocketDump.cpp  |    6 +++---
 wsd/Admin.cpp            |   38 +++++++++++++++++++++++++-------------
 wsd/Admin.hpp            |    9 ++++-----
 wsd/DocumentBroker.cpp   |    4 ++--
 wsd/LOOLWSD.cpp          |   10 +++++-----
 13 files changed, 62 insertions(+), 51 deletions(-)

New commits:
commit 28a9c4dc05646f32883387bd071ac79e853044d5
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Fri Apr 10 12:34:15 2020 +0100
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Fri Apr 10 13:58:00 2020 +0200

    Poll - cleanup method naming, and fix merge issues.
    
    This mends several problems from commit
    5710c8632383e92372e1d81b6e26acc975e25ec4.
    
    Change-Id: I1b29f29ca81679608a2692488fa1ef22b2e62dfd
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/92032
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/kit/ForKit.cpp b/kit/ForKit.cpp
index 5506fa339..1c763f8a3 100644
--- a/kit/ForKit.cpp
+++ b/kit/ForKit.cpp
@@ -606,7 +606,7 @@ int main(int argc, char** argv)
     {
         UnitKit::get().invokeForKitTest();
 
-        mainPoll.ppoll(POLL_TIMEOUT_MICRO_S);
+        mainPoll.poll(POLL_TIMEOUT_MICRO_S);
 
 #if ENABLE_DEBUG
         if (!SingleKit)
diff --git a/kit/Kit.cpp b/kit/Kit.cpp
index acec37bb9..bb7933c93 100644
--- a/kit/Kit.cpp
+++ b/kit/Kit.cpp
@@ -2261,7 +2261,7 @@ public:
         if (timeoutMicroS < 0)
         {
             // Flush at most 1 + maxExtraEvents, or return when nothing left.
-            while (ppoll(0) > 0 && maxExtraEvents-- > 0)
+            while (poll(0) > 0 && maxExtraEvents-- > 0)
                 ++eventsSignalled;
         }
         else
@@ -2270,7 +2270,7 @@ public:
             _pollEnd = std::chrono::steady_clock::now() + std::chrono::microseconds(timeoutMicroS);
             do
             {
-                if (ppoll(timeoutMicroS) <= 0)
+                if (poll(timeoutMicroS) <= 0)
                     break;
 
                 const auto now = std::chrono::steady_clock::now();
diff --git a/net/DelaySocket.cpp b/net/DelaySocket.cpp
index b07b46cc4..fe9478bca 100644
--- a/net/DelaySocket.cpp
+++ b/net/DelaySocket.cpp
@@ -77,8 +77,8 @@ public:
     // FIXME - really need to propagate 'noDelay' etc.
     // have a debug only lookup of delayed sockets for this case ?
 
-    int pgetPollEvents(std::chrono::steady_clock::time_point now,
-                       int64_t &timeoutMaxMicroS) override
+    int getPollEvents(std::chrono::steady_clock::time_point now,
+                      int64_t &timeoutMaxMicroS) override
     {
         if (_chunks.size() > 0)
         {
diff --git a/net/ServerSocket.hpp b/net/ServerSocket.hpp
index 65f826913..5316d3318 100644
--- a/net/ServerSocket.hpp
+++ b/net/ServerSocket.hpp
@@ -65,8 +65,8 @@ public:
     /// Returns a valid Socket shared_ptr on success only.
     virtual std::shared_ptr<Socket> accept();
 
-    int pgetPollEvents(std::chrono::steady_clock::time_point /* now */,
-                       int64_t & /* timeoutMaxMicroS */) override
+    int getPollEvents(std::chrono::steady_clock::time_point /* now */,
+                      int64_t & /* timeoutMaxMicroS */) override
     {
         return POLLIN;
     }
diff --git a/net/Socket.cpp b/net/Socket.cpp
index 47ae1ad41..372f9ea1a 100644
--- a/net/Socket.cpp
+++ b/net/Socket.cpp
@@ -194,7 +194,7 @@ void SocketPoll::pollingThreadEntry()
     LOG_INF("Finished polling thread [" << _name << "].");
 }
 
-int SocketPoll::ppoll(int64_t timeoutMaxMicroS)
+int SocketPoll::poll(int64_t timeoutMaxMicroS)
 {
     if (_runOnClientThread)
         checkAndReThread();
@@ -205,7 +205,7 @@ int SocketPoll::ppoll(int64_t timeoutMaxMicroS)
         std::chrono::steady_clock::now();
 
     // The events to poll on change each spin of the loop.
-    psetupPollFds(now, timeoutMaxMicroS);
+    setupPollFds(now, timeoutMaxMicroS);
     const size_t size = _pollSockets.size();
 
     int rc;
@@ -529,7 +529,7 @@ void WebSocketHandler::dumpState(std::ostream& os)
 void StreamSocket::dumpState(std::ostream& os)
 {
     int64_t timeoutMaxMicroS = SocketPoll::DefaultPollTimeoutMicroS;
-    int events = pgetPollEvents(std::chrono::steady_clock::now(), timeoutMaxMicroS);
+    int events = getPollEvents(std::chrono::steady_clock::now(), timeoutMaxMicroS);
     os << "\t" << getFD() << "\t" << events << "\t"
        << _inBuffer.size() << "\t" << _outBuffer.size() << "\t"
        << " r: " << _bytesRecvd << "\t w: " << _bytesSent << "\t"
diff --git a/net/Socket.hpp b/net/Socket.hpp
index 852012424..199ea0a09 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -154,7 +154,7 @@ public:
     /// Prepare our poll record; adjust @timeoutMaxMs downwards
     /// for timeouts, based on current time @now.
     /// @returns POLLIN and POLLOUT if output is expected.
-    virtual int pgetPollEvents(std::chrono::steady_clock::time_point now,
+    virtual int getPollEvents(std::chrono::steady_clock::time_point now,
                               int64_t &timeoutMaxMicroS) = 0;
 
     /// Handle results of events returned from poll
@@ -370,8 +370,8 @@ public:
     /// Prepare our poll record; adjust @timeoutMaxMs downwards
     /// for timeouts, based on current time @now.
     /// @returns POLLIN and POLLOUT if output is expected.
-    virtual int pgetPollEvents(std::chrono::steady_clock::time_point now,
-                               int64_t &timeoutMaxMicroS) = 0;
+    virtual int getPollEvents(std::chrono::steady_clock::time_point now,
+                              int64_t &timeoutMaxMicroS) = 0;
 
     /// Do we need to handle a timeout ?
     virtual void checkTimeout(std::chrono::steady_clock::time_point /* now */) {}
@@ -533,7 +533,7 @@ public:
     {
         while (continuePolling())
         {
-            ppoll(DefaultPollTimeoutMicroS);
+            poll(DefaultPollTimeoutMicroS);
         }
     }
 
@@ -576,7 +576,7 @@ public:
     /// Poll the sockets for available data to read or buffer to write.
     /// Returns the return-value of poll(2): 0 on timeout,
     /// -1 for error, and otherwise the number of events signalled.
-    int ppoll(int64_t timeoutMaxMicroS);
+    int poll(int64_t timeoutMaxMicroS);
 
     /// Write to a wakeup descriptor
     static void wakeup (int fd)
@@ -695,7 +695,7 @@ private:
                                        const std::string &pathAndQuery);
 
     /// Initialize the poll fds array with the right events
-    void psetupPollFds(std::chrono::steady_clock::time_point now,
+    void setupPollFds(std::chrono::steady_clock::time_point now,
                       int64_t &timeoutMaxMicroS)
     {
         const size_t size = _pollSockets.size();
@@ -704,7 +704,7 @@ private:
 
         for (size_t i = 0; i < size; ++i)
         {
-            int events = _pollSockets[i]->pgetPollEvents(now, timeoutMaxMicroS);
+            int events = _pollSockets[i]->getPollEvents(now, timeoutMaxMicroS);
             assert(events >= 0); // Or > 0 even?
             _pollFds[i].fd = _pollSockets[i]->getFD();
             _pollFds[i].events = events;
@@ -804,12 +804,12 @@ public:
         Socket::shutdown();
     }
 
-    int pgetPollEvents(std::chrono::steady_clock::time_point now,
+    int getPollEvents(std::chrono::steady_clock::time_point now,
                       int64_t &timeoutMaxMicroS) override
     {
         // cf. SslSocket::getPollEvents
         assertCorrectThread();
-        int events = _socketHandler->pgetPollEvents(now, timeoutMaxMicroS);
+        int events = _socketHandler->getPollEvents(now, timeoutMaxMicroS);
         if (!_outBuffer.empty() || _shutdownSignalled)
             events |= POLLOUT;
         return events;
diff --git a/net/SslSocket.hpp b/net/SslSocket.hpp
index e6b7f908f..e7853c33f 100644
--- a/net/SslSocket.hpp
+++ b/net/SslSocket.hpp
@@ -126,11 +126,11 @@ public:
         return handleSslState(SSL_write(_ssl, buf, len));
     }
 
-    int pgetPollEvents(std::chrono::steady_clock::time_point now,
-                       int64_t & timeoutMaxMicroS) override
+    int getPollEvents(std::chrono::steady_clock::time_point now,
+                      int64_t & timeoutMaxMicroS) override
     {
         assertCorrectThread();
-        int events = getSocketHandler()->pgetPollEvents(now, timeoutMaxMicroS);
+        int events = getSocketHandler()->getPollEvents(now, timeoutMaxMicroS);
 
         if (_sslWantsTo == SslWantsTo::Read)
         {
diff --git a/net/WebSocketHandler.hpp b/net/WebSocketHandler.hpp
index 24c3a839a..83a3fa244 100644
--- a/net/WebSocketHandler.hpp
+++ b/net/WebSocketHandler.hpp
@@ -430,7 +430,7 @@ public:
         }
     }
 
-    int pgetPollEvents(std::chrono::steady_clock::time_point now,
+    int getPollEvents(std::chrono::steady_clock::time_point now,
                       int64_t & timeoutMaxMicroS) override
     {
         if (!_isClient)
diff --git a/tools/WebSocketDump.cpp b/tools/WebSocketDump.cpp
index 822a256e8..81e034a67 100644
--- a/tools/WebSocketDump.cpp
+++ b/tools/WebSocketDump.cpp
@@ -175,8 +175,8 @@ private:
         in.erase(in.begin(), itBody);
     }
 
-    int pgetPollEvents(std::chrono::steady_clock::time_point /* now */,
-                       int64_t & /* timeoutMaxMicroS */) override
+    int getPollEvents(std::chrono::steady_clock::time_point /* now */,
+                      int64_t & /* timeoutMaxMicroS */) override
     {
         return POLLIN;
     }
@@ -290,7 +290,7 @@ int main (int argc, char **argv)
 
     while (true)
     {
-        DumpSocketPoll.ppoll(100 * 1000 * 1000);
+        DumpSocketPoll.poll(100 * 1000 * 1000);
     }
 }
 
diff --git a/wsd/Admin.cpp b/wsd/Admin.cpp
index ea905827c..b439a9ee8 100644
--- a/wsd/Admin.cpp
+++ b/wsd/Admin.cpp
@@ -24,7 +24,6 @@
 #include <Common.hpp>
 #include "FileServer.hpp"
 #include <IoUtil.hpp>
-#include "LOOLWSD.hpp"
 #include <Log.hpp>
 #include <Protocol.hpp>
 #include "Storage.hpp"
@@ -158,11 +157,24 @@ void AdminSocketHandler::handleMessage(const std::vector<char> &payload)
         {
             const int pid = std::stoi(tokens[1]);
             LOG_INF("Admin request to kill PID: " << pid);
-            SigUtil::killChild(pid);
+
+            std::set<pid_t> pids = model.getDocumentPids();
+            if (pids.find(pid) != pids.end())
+            {
+                SigUtil::killChild(pid);
+            }
+            else
+            {
+                LOG_WRN("Invalid PID to kill (not a document pid)");
+            }
         }
         catch (std::invalid_argument& exc)
         {
-            LOG_WRN("Invalid PID to kill: " << tokens[1]);
+            LOG_WRN("Invalid PID to kill (invalid argument): " << tokens[1]);
+        }
+        catch (std::out_of_range& exc)
+        {
+            LOG_WRN("Invalid PID to kill (out of range): " << tokens[1]);
         }
     }
     else if (tokens.equals(0, "settings"))
@@ -283,7 +295,11 @@ AdminSocketHandler::AdminSocketHandler(Admin* adminManager)
 
 void AdminSocketHandler::sendTextFrame(const std::string& message)
 {
-    UnitWSD::get().onAdminQueryMessage(message);
+    if (!Util::isFuzzing())
+    {
+        UnitWSD::get().onAdminQueryMessage(message);
+    }
+
     if (_isAuthenticated)
     {
         LOG_TRC("send admin text frame '" << message << "'");
@@ -344,7 +360,6 @@ Admin::Admin() :
     SocketPoll("admin"),
     _model(AdminModel()),
     _forKitPid(-1),
-    _forKitWritePipe(-1),
     _lastTotalMemory(0),
     _lastJiffies(0),
     _lastSentCount(0),
@@ -455,7 +470,7 @@ void Admin::pollingThread()
         // Handle websockets & other work.
         const int timeout = capAndRoundInterval(std::min(std::min(cpuWait, memWait), netWait));
         LOG_TRC("Admin poll for " << timeout << "ms.");
-        ppoll(timeout * 1000); // continue with ms for admin, settings etc.
+        poll(timeout * 1000); // continue with ms for admin, settings etc.
     }
 }
 
@@ -591,10 +606,7 @@ void Admin::notifyForkit()
         << "setconfig limit_file_size_mb " << _defDocProcSettings.getLimitFileSizeMb() << '\n'
         << "setconfig limit_num_open_files " << _defDocProcSettings.getLimitNumberOpenFiles() << '\n';
 
-    if (_forKitWritePipe != -1)
-        IoUtil::writeToPipe(_forKitWritePipe, oss.str());
-    else
-        LOG_INF("Forkit write pipe not set (yet).");
+    LOOLWSD::sendMessageToForKit(oss.str());
 }
 
 void Admin::triggerMemoryCleanup(const size_t totalMem)
@@ -663,8 +675,8 @@ public:
         _uri(uri)
     {
     }
-    int pgetPollEvents(std::chrono::steady_clock::time_point now,
-                       int64_t &timeoutMaxMicroS) override
+    int getPollEvents(std::chrono::steady_clock::time_point now,
+                      int64_t &timeoutMaxMicroS) override
     {
         if (_connecting)
         {
@@ -672,7 +684,7 @@ public:
             return POLLOUT;
         }
         else
-            return AdminSocketHandler::pgetPollEvents(now, timeoutMaxMicroS);
+            return AdminSocketHandler::getPollEvents(now, timeoutMaxMicroS);
     }
 
     void performWrites() override
diff --git a/wsd/Admin.hpp b/wsd/Admin.hpp
index a418040c6..6287d38bc 100644
--- a/wsd/Admin.hpp
+++ b/wsd/Admin.hpp
@@ -16,6 +16,7 @@
 #include "Log.hpp"
 
 #include "net/WebSocketHandler.hpp"
+#include "LOOLWSD.hpp"
 
 class Admin;
 
@@ -38,13 +39,13 @@ public:
 
     static void subscribeAsync(const std::shared_ptr<AdminSocketHandler>& handler);
 
+    /// Process incoming websocket messages
+    void handleMessage(const std::vector<char> &data) override;
+
 private:
     /// Sends text frames simply to authenticated clients.
     void sendTextFrame(const std::string& message);
 
-    /// Process incoming websocket messages
-    void handleMessage(const std::vector<char> &data) override;
-
 private:
     Admin* _admin;
     int _sessionId;
@@ -91,7 +92,6 @@ public:
     void rmDoc(const std::string& docKey);
 
     void setForKitPid(const int forKitPid) { _forKitPid = forKitPid; _model.setForKitPid(forKitPid);}
-    void setForKitWritePipe(const int forKitWritePipe) { _forKitWritePipe = forKitWritePipe; }
 
     /// Callers must ensure that modelMutex is acquired
     AdminModel& getModel();
@@ -157,7 +157,6 @@ private:
     /// the Admin Poll thread.
     AdminModel _model;
     int _forKitPid;
-    int _forKitWritePipe;
     size_t _lastTotalMemory;
     size_t _lastJiffies;
     uint64_t _lastSentCount;
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 1d63e813f..bbe3b7937 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -298,7 +298,7 @@ void DocumentBroker::pollThread()
     // Main polling loop goodness.
     while (!_stop && _poll->continuePolling() && !SigUtil::getTerminationFlag())
     {
-        _poll->ppoll(SocketPoll::DefaultPollTimeoutMicroS);
+        _poll->poll(SocketPoll::DefaultPollTimeoutMicroS);
 
         const auto now = std::chrono::steady_clock::now();
 
@@ -455,7 +455,7 @@ void DocumentBroker::pollThread()
         if (elapsedMicroS > flushTimeoutMicroS)
             break;
 
-        _poll->ppoll(std::min(flushTimeoutMicroS - elapsedMicroS, (int64_t)POLL_TIMEOUT_MICRO_S / 5));
+        _poll->poll(std::min(flushTimeoutMicroS - elapsedMicroS, (int64_t)POLL_TIMEOUT_MICRO_S / 5));
     }
 
     LOG_INF("Finished flushing socket for doc [" << _docKey << "]. stop: " << _stop << ", continuePolling: " <<
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 1d014927a..92aae506a 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -2061,8 +2061,8 @@ private:
                     " has no DocumentBroker to handle message: [" << abbr << "].");
     }
 
-    int pgetPollEvents(std::chrono::steady_clock::time_point /* now */,
-                       int64_t & /* timeoutMaxMs */) override
+    int getPollEvents(std::chrono::steady_clock::time_point /* now */,
+                      int64_t & /* timeoutMaxMs */) override
     {
         return POLLIN;
     }
@@ -2393,8 +2393,8 @@ private:
 #endif
     }
 
-    int pgetPollEvents(std::chrono::steady_clock::time_point /* now */,
-                       int64_t & /* timeoutMaxMs */) override
+    int getPollEvents(std::chrono::steady_clock::time_point /* now */,
+                      int64_t & /* timeoutMaxMs */) override
     {
         return POLLIN;
     }
@@ -3580,7 +3580,7 @@ int LOOLWSD::innerMain()
         const int waitMicroS = UnitWSD::isUnitTesting() ?
             UnitWSD::get().getTimeoutMilliSeconds() * 1000 / 4 :
             SocketPoll::DefaultPollTimeoutMicroS * 4;
-        mainWait.ppoll(waitMicroS);
+        mainWait.poll(waitMicroS);
 
         // Wake the prisoner poll to spawn some children, if necessary.
         PrisonerPoll.wakeup();


More information about the Libreoffice-commits mailing list