kit/Kit.cpp            |   22 ++--------------------
 net/Socket.cpp         |   15 +++++++++++----
 net/Socket.hpp         |    6 ++++--
 wsd/Admin.cpp          |   10 +++-------
 wsd/Admin.hpp          |    5 +++--
 wsd/AdminModel.cpp     |   11 +++--------
 wsd/AdminModel.hpp     |    5 +++--
 wsd/DocumentBroker.cpp |   15 ++-------------
 wsd/LOOLWSD.cpp        |    3 ++-
 9 files changed, 33 insertions(+), 59 deletions(-)

New commits:
commit d006204478cb4a10e35574f4c12a37318f7b39eb
Author:     Gabriel Masei <gabriel.ma...@1and1.ro>
AuthorDate: Tue Apr 28 16:55:47 2020 +0300
Commit:     Michael Meeks <michael.me...@collabora.com>
CommitDate: Tue Apr 28 17:20:07 2020 +0200

    wsd: admin: send smaps fd along websocket upgrade request
    
    Change-Id: I2c5c23284b7578f4c177ec337cc1262bf1259e96
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/93074
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Michael Meeks <michael.me...@collabora.com>

diff --git a/kit/Kit.cpp b/kit/Kit.cpp
index ae775fee3..b5409ca68 100644
--- a/kit/Kit.cpp
+++ b/kit/Kit.cpp
@@ -649,9 +649,6 @@ public:
     }
 };
 
-#if !MOBILEAPP
-static int ProcSMapsFile = -1;
-#endif
 
 class ThreadPool {
     std::mutex _mutex;
@@ -795,22 +792,6 @@ public:
                 "] and id [" << _docId << "].");
         assert(_loKit);
 
-#if !MOBILEAPP
-        if (ProcSMapsFile >= 0)
-        {
-            static const std::string str = "smapsfd:";
-            if (websocketHandler->sendTextMessageWithFD(str.c_str(), 
str.size(), ProcSMapsFile) > 0)
-            {
-                LOG_DBG("Successfully sent smaps fd to wsd");
-                close(ProcSMapsFile);
-                ProcSMapsFile = -1;
-            }
-            else
-            {
-                LOG_ERR("Failed to send smaps fd to wsd");
-            }
-        }
-#endif
     }
 
     virtual ~Document()
@@ -2505,6 +2486,7 @@ void lokit_main(
 
     std::string userdir_url;
     std::string instdir_path;
+    int ProcSMapsFile = -1;
 
     // lokit's destroy typically throws from
     // framework/source/services/modulemanager.cxx:198
@@ -2749,7 +2731,7 @@ void lokit_main(
             std::make_shared<KitWebSocketHandler>("child_ws", loKit, jailId, 
mainKit);
 
 #if !MOBILEAPP
-        mainKit.insertNewUnixSocket(MasterLocation, pathAndQuery, 
websocketHandler);
+        mainKit.insertNewUnixSocket(MasterLocation, pathAndQuery, 
websocketHandler, ProcSMapsFile);
 #else
         mainKit.insertNewFakeSocket(docBrokerSocket, websocketHandler);
 #endif
diff --git a/net/Socket.cpp b/net/Socket.cpp
index 0b7a2f2ff..5e96ab2ac 100644
--- a/net/Socket.cpp
+++ b/net/Socket.cpp
@@ -407,7 +407,7 @@ void SocketPoll::insertNewWebSocketSync(
 // should this be a static method in the WebsocketHandler(?)
 void SocketPoll::clientRequestWebsocketUpgrade(const 
std::shared_ptr<StreamSocket>& socket,
                                                const 
std::shared_ptr<ProtocolHandlerInterface>& websocketHandler,
-                                               const std::string &pathAndQuery)
+                                               const std::string 
&pathAndQuery, const int shareFD)
 {
     // cf. WebSocketHandler::upgradeToWebSocket (?)
     // send Sec-WebSocket-Key: <hmm> ... Sec-WebSocket-Protocol: chat, 
Sec-WebSocket-Version: 13
@@ -426,14 +426,21 @@ void SocketPoll::clientRequestWebsocketUpgrade(const 
std::shared_ptr<StreamSocke
         "Sec-WebSocket-Version:13\r\n"
         "User-Agent: " WOPI_AGENT_STRING "\r\n"
         "\r\n";
-    socket->send(oss.str());
+    if (shareFD == -1)
+        socket->send(oss.str());
+    else
+    {
+        std::string request = oss.str();
+        socket->sendFD(request.c_str(), request.size(), shareFD);
+    }
     websocketHandler->onConnect(socket);
 }
 
 void SocketPoll::insertNewUnixSocket(
     const std::string &location,
     const std::string &pathAndQuery,
-    const std::shared_ptr<ProtocolHandlerInterface>& websocketHandler)
+    const std::shared_ptr<ProtocolHandlerInterface>& websocketHandler,
+    const int shareFD)
 {
     int fd = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0);
 
@@ -456,7 +463,7 @@ void SocketPoll::insertNewUnixSocket(
         if (socket)
         {
             LOG_DBG("Connected to local UDS " << location << " #" << 
socket->getFD());
-            clientRequestWebsocketUpgrade(socket, websocketHandler, 
pathAndQuery);
+            clientRequestWebsocketUpgrade(socket, websocketHandler, 
pathAndQuery, shareFD);
             insertNewSocket(socket);
         }
     }
diff --git a/net/Socket.hpp b/net/Socket.hpp
index ed59edb23..34da98aab 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -640,7 +640,8 @@ public:
     void insertNewUnixSocket(
         const std::string &location,
         const std::string &pathAndQuery,
-        const std::shared_ptr<ProtocolHandlerInterface>& websocketHandler);
+        const std::shared_ptr<ProtocolHandlerInterface>& websocketHandler,
+        const int shareFD = -1);
 #else
     void insertNewFakeSocket(
         int peerSocket,
@@ -698,9 +699,10 @@ protected:
 
 private:
     /// Generate the request to connect & upgrade this socket to a given path
+    /// and sends a file descriptor along request if is != -1.
     void clientRequestWebsocketUpgrade(const std::shared_ptr<StreamSocket>& 
socket,
                                        const 
std::shared_ptr<ProtocolHandlerInterface>& websocketHandler,
-                                       const std::string &pathAndQuery);
+                                       const std::string &pathAndQuery, const 
int shareFD = -1);
 
     /// Initialize the poll fds array with the right events
     void setupPollFds(std::chrono::steady_clock::time_point now,
diff --git a/wsd/Admin.cpp b/wsd/Admin.cpp
index 0af46c8ad..ace0d6e5d 100644
--- a/wsd/Admin.cpp
+++ b/wsd/Admin.cpp
@@ -483,9 +483,10 @@ void Admin::modificationAlert(const std::string& dockey, 
Poco::Process::PID pid,
 }
 
 void Admin::addDoc(const std::string& docKey, Poco::Process::PID pid, const 
std::string& filename,
-        const std::string& sessionId, const std::string& userName, const 
std::string& userId)
+                   const std::string& sessionId, const std::string& userName, 
const std::string& userId,
+                   const int smapsFD)
 {
-    addCallback([=] { _model.addDocument(docKey, pid, filename, sessionId, 
userName, userId); });
+    addCallback([=] { _model.addDocument(docKey, pid, filename, sessionId, 
userName, userId, smapsFD); });
 }
 
 void Admin::rmDoc(const std::string& docKey, const std::string& sessionId)
@@ -593,11 +594,6 @@ void Admin::setDocWopiUploadDuration(const std::string& 
docKey, const std::chron
     addCallback([=]{ _model.setDocWopiUploadDuration(docKey, uploadDuration); 
});
 }
 
-void Admin::setDocProcSMapsFD(const std::string& docKey, const int smapsFD)
-{
-    addCallback([=]{ _model.setDocProcSMapsFD(docKey, smapsFD); });
-}
-
 void Admin::addSegFaultCount(unsigned segFaultCount)
 {
     addCallback([=]{ _model.addSegFaultCount(segFaultCount); });
diff --git a/wsd/Admin.hpp b/wsd/Admin.hpp
index 80364378d..3d9af9ef3 100644
--- a/wsd/Admin.hpp
+++ b/wsd/Admin.hpp
@@ -84,7 +84,9 @@ public:
     void update(const std::string& message);
 
     /// Calls with same pid will increment view count, if pid already exists
-    void addDoc(const std::string& docKey, Poco::Process::PID pid, const 
std::string& filename, const std::string& sessionId, const std::string& 
userName, const std::string& userId);
+    void addDoc(const std::string& docKey, Poco::Process::PID pid, const 
std::string& filename,
+                const std::string& sessionId, const std::string& userName, 
const std::string& userId,
+                const int smapsFD);
 
     /// Decrement view count till becomes zero after which doc is removed
     void rmDoc(const std::string& docKey, const std::string& sessionId);
@@ -129,7 +131,6 @@ public:
     void setViewLoadDuration(const std::string& docKey, const std::string& 
sessionId, std::chrono::milliseconds viewLoadDuration);
     void setDocWopiDownloadDuration(const std::string& docKey, 
std::chrono::milliseconds wopiDownloadDuration);
     void setDocWopiUploadDuration(const std::string& docKey, const 
std::chrono::milliseconds uploadDuration);
-    void setDocProcSMapsFD(const std::string& docKey, const int smapsFD);
     void addSegFaultCount(unsigned segFaultCount);
 
     void getMetrics(std::ostringstream &metrics);
diff --git a/wsd/AdminModel.cpp b/wsd/AdminModel.cpp
index 18ccb62f1..bebd00b7d 100644
--- a/wsd/AdminModel.cpp
+++ b/wsd/AdminModel.cpp
@@ -495,11 +495,13 @@ void AdminModel::modificationAlert(const std::string& 
docKey, Poco::Process::PID
 
 void AdminModel::addDocument(const std::string& docKey, Poco::Process::PID pid,
                              const std::string& filename, const std::string& 
sessionId,
-                             const std::string& userName, const std::string& 
userId)
+                             const std::string& userName, const std::string& 
userId,
+                             const int smapsFD)
 {
     assertCorrectThread();
 
     const auto ret = _documents.emplace(docKey, std::unique_ptr<Document>(new 
Document(docKey, pid, filename)));
+    ret.first->second->setProcSMapsFD(smapsFD);
     ret.first->second->takeSnapshot();
     ret.first->second->addView(sessionId, userName, userId);
     LOG_DBG("Added admin document [" << docKey << "].");
@@ -776,13 +778,6 @@ void AdminModel::setDocWopiUploadDuration(const 
std::string& docKey, const std::
         it->second->setWopiUploadDuration(wopiUploadDuration);
 }
 
-void AdminModel::setDocProcSMapsFD(const std::string& docKey, const int 
smapsFD)
-{
-    auto it = _documents.find(docKey);
-    if (it != _documents.end())
-        it->second->setProcSMapsFD(smapsFD);
-}
-
 void AdminModel::addSegFaultCount(unsigned segFaultCount)
 {
     _segFaultCount += segFaultCount;
diff --git a/wsd/AdminModel.hpp b/wsd/AdminModel.hpp
index 15afb344a..862b02b1b 100644
--- a/wsd/AdminModel.hpp
+++ b/wsd/AdminModel.hpp
@@ -311,7 +311,9 @@ public:
 
     void notify(const std::string& message);
 
-    void addDocument(const std::string& docKey, Poco::Process::PID pid, const 
std::string& filename, const std::string& sessionId, const std::string& 
userName, const std::string& userId);
+    void addDocument(const std::string& docKey, Poco::Process::PID pid, const 
std::string& filename,
+                     const std::string& sessionId, const std::string& 
userName, const std::string& userId,
+                     const int smapsFD);
 
     void removeDocument(const std::string& docKey, const std::string& 
sessionId);
     void removeDocument(const std::string& docKey);
@@ -331,7 +333,6 @@ public:
     void setViewLoadDuration(const std::string& docKey, const std::string& 
sessionId, std::chrono::milliseconds viewLoadDuration);
     void setDocWopiDownloadDuration(const std::string& docKey, 
std::chrono::milliseconds wopiDownloadDuration);
     void setDocWopiUploadDuration(const std::string& docKey, const 
std::chrono::milliseconds wopiUploadDuration);
-    void setDocProcSMapsFD(const std::string& docKey, const int smapsFD);
     void addSegFaultCount(unsigned segFaultCount);
     void setForKitPid(pid_t pid) { _forKitPid = pid; }
 
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index fd1dc7f46..b6defa9d5 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -1340,7 +1340,8 @@ size_t DocumentBroker::addSessionInternal(const 
std::shared_ptr<ClientSession>&
 
 #if !MOBILEAPP
     // Tell the admin console about this new doc
-    Admin::instance().addDoc(_docKey, getPid(), getFilename(), id, 
session->getUserName(), session->getUserId());
+    Admin::instance().addDoc(_docKey, getPid(), getFilename(), id, 
session->getUserName(),
+                             session->getUserId(), 
_childProcess->getSMapsFD());
     Admin::instance().setDocWopiDownloadDuration(_docKey, _wopiLoadDuration);
 #endif
 
@@ -1591,18 +1592,6 @@ bool DocumentBroker::handleInput(const 
std::vector<char>& payload)
             LOG_CHECK_RET(kind != "", false);
             Util::alertAllUsers(cmd, kind);
         }
-#if !MOBILEAPP
-        else if (command == "smapsfd:")
-        {
-            std::shared_ptr<StreamSocket> socket = 
std::static_pointer_cast<StreamSocket>(_childProcess->_socket);
-            if (socket)
-            {
-                _childProcess->setSMapsFD(socket->getIncomingFD());
-                Admin::instance().setDocProcSMapsFD(_docKey, 
_childProcess->getSMapsFD());
-                LOG_DBG("Received smaps fd");
-            }
-        }
-#endif
         else
         {
             LOG_ERR("Unexpected message: [" << msg << "].");
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 329051698..ba66a372d 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -2032,6 +2032,7 @@ private:
 
             auto child = std::make_shared<ChildProcess>(pid, jailId, socket, 
request);
 
+            child->setSMapsFD(socket->getIncomingFD());
             _childProcess = child; // weak
 
             // Remove from prisoner poll since there is no activity
@@ -2072,7 +2073,7 @@ private:
         if (docBroker)
             docBroker->handleInput(data);
         else
-            LOG_WRN("Child " << child->getPid() <<
+                LOG_WRN("Child " << child->getPid() <<
                     " has no DocumentBroker to handle message: [" << abbr << 
"].");
     }
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to