loolwsd: more cleanups and logging
Change-Id: I23859849af2d7a3411bd4df57916b4166a17c3b5 Reviewed-on: https://gerrit.libreoffice.org/20946 Reviewed-by: Ashod Nakashian <ashnakash@gmail.com> Tested-by: Ashod Nakashian <ashnakash@gmail.com>
This commit is contained in:
parent
7053091c0e
commit
3bd8361c89
7 changed files with 65 additions and 58 deletions
|
@ -52,12 +52,14 @@ ChildProcessSession::ChildProcessSession(std::shared_ptr<WebSocket> ws,
|
|||
_childId(childId),
|
||||
_clientPart(0)
|
||||
{
|
||||
Log::info() << "ChildProcessSession ctor this:" << this << " ws:" << _ws.get() << Log::end;
|
||||
Log::info() << "ChildProcessSession ctor " << Kind::ToMaster
|
||||
<< " this:" << this << " ws:" << _ws.get() << Log::end;
|
||||
}
|
||||
|
||||
ChildProcessSession::~ChildProcessSession()
|
||||
{
|
||||
Log::info() << "ChildProcessSession dtor this:" << this << " ws: " << _ws.get() << Log::end;
|
||||
Log::info() << "ChildProcessSession ctor " << Kind::ToMaster
|
||||
<< " this:" << this << " ws:" << _ws.get() << Log::end;
|
||||
if (LIBREOFFICEKIT_HAS(_loKit, registerCallback))
|
||||
_loKit->pClass->registerCallback(_loKit, 0, 0);
|
||||
Util::shutdownWebSocket(*_ws);
|
||||
|
@ -211,9 +213,6 @@ extern "C"
|
|||
{
|
||||
static void myCallback(int nType, const char* pPayload, void* pData)
|
||||
{
|
||||
/*pid_t tid = syscall(SYS_gettid);
|
||||
std::cout << tid << " callbackWorker : " << priv->m_nViewId << " " << std::string(callbackTypeToString(nType)) << " " << std::string(pPayload ? pPayload : "(nil)") << std::endl;*/
|
||||
|
||||
auto pNotif = new CallBackNotification(nType, pPayload ? pPayload : "(nil)", pData);
|
||||
ChildProcessSession::_callbackQueue.enqueueNotification(pNotif);
|
||||
}
|
||||
|
@ -237,7 +236,7 @@ bool ChildProcessSession::loadDocument(const char *buffer, int length, StringTok
|
|||
{
|
||||
aUri = URI(_docURL);
|
||||
}
|
||||
catch(Poco::SyntaxException&)
|
||||
catch (const Poco::SyntaxException&)
|
||||
{
|
||||
sendTextFrame("error: cmd=load kind=uriinvalid");
|
||||
return false;
|
||||
|
|
|
@ -131,16 +131,13 @@ namespace
|
|||
}
|
||||
break;
|
||||
case FTW_DNR:
|
||||
std::cout <<Util::logPrefix() +
|
||||
"Cannot read directory '" + fpath + "'" << std::endl;
|
||||
Log::error("Cannot read directory '" + std::string(fpath) + "'");
|
||||
return 1;
|
||||
case FTW_NS:
|
||||
std::cout <<Util::logPrefix() +
|
||||
"nftw: stat failed for '" + fpath + "'" << std::endl;
|
||||
Log::error("nftw: stat failed for '" + std::string(fpath) + "'");
|
||||
return 1;
|
||||
case FTW_SLN:
|
||||
std::cout <<Util::logPrefix() +
|
||||
"nftw: symlink to nonexistent file: '" + fpath + "', ignored" << std::endl;
|
||||
Log::error("nftw: symlink to nonexistent file: '" + std::string(fpath) + "', ignored.");
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
|
@ -155,8 +152,7 @@ namespace
|
|||
sourceForLinkOrCopy->pop_back();
|
||||
*destinationForLinkOrCopy = destination;
|
||||
if (nftw(source.c_str(), linkOrCopyFunction, 10, FTW_DEPTH) == -1)
|
||||
std::cout << Util::logPrefix() +
|
||||
"linkOrCopy: nftw() failed for '" + source + "'" << std::endl;
|
||||
Log::error("linkOrCopy: nftw() failed for '" + source + "'");
|
||||
}
|
||||
|
||||
void dropCapability(
|
||||
|
@ -190,7 +186,7 @@ namespace
|
|||
}
|
||||
|
||||
char *capText = cap_to_text(caps, nullptr);
|
||||
std::cout << Util::logPrefix() + "Capabilities now: " + capText << std::endl;
|
||||
Log::info("Capabilities now: " + std::string(capText));
|
||||
cap_free(capText);
|
||||
|
||||
cap_free(caps);
|
||||
|
@ -695,18 +691,18 @@ int main(int argc, char** argv)
|
|||
{
|
||||
Poco::Environment::get("LD_BIND_NOW");
|
||||
}
|
||||
catch (const Poco::NotFoundException& ex)
|
||||
catch (const Poco::NotFoundException& exc)
|
||||
{
|
||||
Log::error(std::string("Exception: ") + ex.what());
|
||||
Log::error(std::string("Exception: ") + exc.what());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Poco::Environment::get("LOK_VIEW_CALLBACK");
|
||||
}
|
||||
catch (const Poco::NotFoundException& ex)
|
||||
catch (const Poco::NotFoundException& exc)
|
||||
{
|
||||
Log::error(std::string("Exception: ") + ex.what());
|
||||
Log::error(std::string("Exception: ") + exc.what());
|
||||
}
|
||||
|
||||
const Poco::UInt64 _childId = Util::rng::getNext();
|
||||
|
@ -783,7 +779,7 @@ int main(int argc, char** argv)
|
|||
|
||||
if (mkfifo(FIFO_BROKER.c_str(), 0666) == -1)
|
||||
{
|
||||
Log::error("Error: Failed to create pipe FIFO.");
|
||||
Log::error("Error: Failed to create pipe FIFO [" + FIFO_BROKER + "].");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
|
|
@ -88,6 +88,16 @@ public:
|
|||
return std::string("LOK_CALLBACK_CURSOR_VISIBLE");
|
||||
case LOK_CALLBACK_GRAPHIC_SELECTION:
|
||||
return std::string("LOK_CALLBACK_GRAPHIC_SELECTION");
|
||||
case LOK_CALLBACK_CELL_CURSOR:
|
||||
return std::string("LLOK_CALLBACK_CELL_CURSOR");
|
||||
case LOK_CALLBACK_CELL_FORMULA:
|
||||
return std::string("LOK_CALLBACK_CELL_FORMULA");
|
||||
case LOK_CALLBACK_MOUSE_POINTER:
|
||||
return std::string("LOK_CALLBACK_MOUSE_POINTER");
|
||||
case LOK_CALLBACK_SEARCH_RESULT_SELECTION:
|
||||
return std::string("LOK_CALLBACK_SEARCH_RESULT_SELECTION");
|
||||
case LOK_CALLBACK_UNO_COMMAND_RESULT:
|
||||
return std::string("LOK_CALLBACK_UNO_COMMAND_RESULT");
|
||||
case LOK_CALLBACK_HYPERLINK_CLICKED:
|
||||
return std::string("LOK_CALLBACK_HYPERLINK_CLICKED");
|
||||
case LOK_CALLBACK_STATE_CHANGED:
|
||||
|
@ -111,6 +121,9 @@ public:
|
|||
void callback(const int nType, const std::string& rPayload, void* pData)
|
||||
{
|
||||
ChildProcessSession *srv = reinterpret_cast<ChildProcessSession *>(pData);
|
||||
Log::debug() << "Callback [" << srv->_viewId << "] "
|
||||
<< std::string(callbackTypeToString(nType))
|
||||
<< " " << rPayload << Log::end;
|
||||
|
||||
switch ((LibreOfficeKitCallbackType) nType)
|
||||
{
|
||||
|
@ -135,10 +148,10 @@ public:
|
|||
width = std::stoi(tokens[2]);
|
||||
height = std::stoi(tokens[3]);
|
||||
}
|
||||
catch (std::out_of_range&)
|
||||
catch (const std::out_of_range&)
|
||||
{
|
||||
// something went wrong, invalidate everything
|
||||
std::cout << Util::logPrefix() << "Ignoring integer values out of range: " << rPayload << std::endl;
|
||||
Log::warn("Ignoring integer values out of range: " + rPayload);
|
||||
x = 0;
|
||||
y = 0;
|
||||
width = INT_MAX;
|
||||
|
@ -274,14 +287,14 @@ public:
|
|||
break;
|
||||
}
|
||||
}
|
||||
catch(std::exception& ex)
|
||||
catch (const std::exception& exc)
|
||||
{
|
||||
Log::error(std::string("Exception: ") + ex.what());
|
||||
Log::error(std::string("Exception: ") + exc.what());
|
||||
raise(SIGABRT);
|
||||
}
|
||||
catch(...)
|
||||
catch (...)
|
||||
{
|
||||
Log::error("Unknown Exception.");
|
||||
Log::error("Unexpected Exception.");
|
||||
raise(SIGABRT);
|
||||
}
|
||||
}
|
||||
|
@ -373,11 +386,11 @@ public:
|
|||
queue.put("eof");
|
||||
queueHandlerThread.join();
|
||||
}
|
||||
catch (Exception& exc)
|
||||
catch (const Exception& exc)
|
||||
{
|
||||
Log::error(std::string("Exception: ") + exc.what());
|
||||
}
|
||||
catch (std::exception& exc)
|
||||
catch (const std::exception& exc)
|
||||
{
|
||||
Log::error(std::string("Exception: ") + exc.what());
|
||||
}
|
||||
|
@ -592,13 +605,13 @@ void run_lok_main(const std::string &loSubPath, Poco::UInt64 _childId, const std
|
|||
|
||||
pthread_exit(0);
|
||||
}
|
||||
catch (const Exception& ex)
|
||||
catch (const Exception& exc)
|
||||
{
|
||||
Log::error(std::string("Exception: ") + ex.what());
|
||||
Log::error(std::string("Exception: ") + exc.what());
|
||||
}
|
||||
catch (const std::exception& ex)
|
||||
catch (const std::exception& exc)
|
||||
{
|
||||
Log::error(std::string("Exception: ") + ex.what());
|
||||
Log::error(std::string("Exception: ") + exc.what());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -659,18 +672,18 @@ int main(int argc, char** argv)
|
|||
{
|
||||
Poco::Environment::get("LD_BIND_NOW");
|
||||
}
|
||||
catch (const Poco::NotFoundException& ex)
|
||||
catch (const Poco::NotFoundException& exc)
|
||||
{
|
||||
Log::error(std::string("Exception: ") + ex.what());
|
||||
Log::error(std::string("Exception: ") + exc.what());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Poco::Environment::get("LOK_VIEW_CALLBACK");
|
||||
}
|
||||
catch (const Poco::NotFoundException& ex)
|
||||
catch (const Poco::NotFoundException& exc)
|
||||
{
|
||||
Log::error(std::string("Exception: ") + ex.what());
|
||||
Log::error(std::string("Exception: ") + exc.what());
|
||||
}
|
||||
|
||||
run_lok_main(loSubPath, _childId, _pipe);
|
||||
|
|
|
@ -88,7 +88,6 @@ LOOLSession::LOOLSession(std::shared_ptr<WebSocket> ws, Kind kind) :
|
|||
_ws(ws),
|
||||
_docURL("")
|
||||
{
|
||||
std::cout << Util::logPrefix() << "LOOLSession ctor this=" << this << " " << _kind << " ws=" << _ws.get() << std::endl;
|
||||
if (kind == Kind::ToClient)
|
||||
{
|
||||
_kindString = "ToClient";
|
||||
|
@ -105,7 +104,6 @@ LOOLSession::LOOLSession(std::shared_ptr<WebSocket> ws, Kind kind) :
|
|||
|
||||
LOOLSession::~LOOLSession()
|
||||
{
|
||||
std::cout << Util::logPrefix() << "loolsession dtor this=" << this << " " << _kind << std::endl;
|
||||
if (_ws)
|
||||
Util::shutdownWebSocket(*_ws);
|
||||
}
|
||||
|
|
|
@ -403,7 +403,7 @@ public:
|
|||
std::string fileName;
|
||||
URI::decode(tokens[3], fileName);
|
||||
std::string filePath = dirPath + "/" + fileName;
|
||||
std::cout << Util::logPrefix() << "HTTP request for: " << filePath << std::endl;
|
||||
Log::info("HTTP request for: " + filePath);
|
||||
File file(filePath);
|
||||
if (file.exists())
|
||||
{
|
||||
|
@ -521,7 +521,7 @@ public:
|
|||
queue.put("eof");
|
||||
queueHandlerThread.join();
|
||||
}
|
||||
catch (WebSocketException& exc)
|
||||
catch (const WebSocketException& exc)
|
||||
{
|
||||
Log::error("RequestHandler::handleRequest(), WebSocketException: " + exc.message());
|
||||
switch (exc.code())
|
||||
|
@ -539,7 +539,7 @@ public:
|
|||
}
|
||||
}
|
||||
}
|
||||
catch (IOException& exc)
|
||||
catch (const IOException& exc)
|
||||
{
|
||||
Log::error("IOException: " + exc.message());
|
||||
}
|
||||
|
@ -592,15 +592,13 @@ public:
|
|||
|
||||
if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE)
|
||||
{
|
||||
std::cout <<
|
||||
Util::logPrefix() <<
|
||||
"Client got " << n << " bytes: " << getAbbreviatedMessage(buffer, n) <<
|
||||
std::endl;
|
||||
Log::trace() << "Client got " << n << " bytes: "
|
||||
<< getAbbreviatedMessage(buffer, n) << Log::end;
|
||||
}
|
||||
}
|
||||
while (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE);
|
||||
}
|
||||
catch (WebSocketException& exc)
|
||||
catch (const WebSocketException& exc)
|
||||
{
|
||||
Log::error("TestOutput::run(), WebSocketException: " + exc.message());
|
||||
_ws.close();
|
||||
|
@ -689,7 +687,7 @@ LOOLWSD::~LOOLWSD()
|
|||
|
||||
void LOOLWSD::handleSignal(int aSignal)
|
||||
{
|
||||
std::cout << Util::logPrefix() << "Signal received: " << strsignal(aSignal) << std::endl;
|
||||
Log::info() << "Signal received: " << strsignal(aSignal) << Log::end;
|
||||
LOOLWSD::isShutDown = true;
|
||||
}
|
||||
|
||||
|
@ -878,8 +876,8 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
|
|||
|
||||
if (access(cache.c_str(), R_OK | W_OK | X_OK) != 0)
|
||||
{
|
||||
std::cout << Util::logPrefix() << "Unable to access " << cache <<
|
||||
", please make sure it exists, and has write permission for this user." << std::endl;
|
||||
Log::error("Unable to access cache [" + cache +
|
||||
"] please make sure it exists, and has write permission for this user.");
|
||||
return Application::EXIT_UNAVAILABLE;
|
||||
}
|
||||
|
||||
|
@ -913,7 +911,7 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
|
|||
|
||||
if (!File(FIFO_FILE).exists() && mkfifo(FIFO_FILE.c_str(), 0666) == -1)
|
||||
{
|
||||
std::cout << Util::logPrefix() << "Fail to create pipe FIFO" << std::endl;
|
||||
Log::error("Error: Failed to create pipe FIFO [" + FIFO_FILE + "].");
|
||||
return Application::EXIT_UNAVAILABLE;
|
||||
}
|
||||
|
||||
|
|
|
@ -55,12 +55,14 @@ MasterProcessSession::MasterProcessSession(std::shared_ptr<WebSocket> ws, const
|
|||
_curPart(0),
|
||||
_loadPart(-1)
|
||||
{
|
||||
std::cout << Util::logPrefix() << "MasterProcessSession ctor this=" << this << " ws=" << _ws.get() << std::endl;
|
||||
Log::info() << "MasterProcessSession ctor " << _kindString
|
||||
<< " this:" << this << " ws:" << _ws.get() << Log::end;
|
||||
}
|
||||
|
||||
MasterProcessSession::~MasterProcessSession()
|
||||
{
|
||||
std::cout << Util::logPrefix() << "MasterProcessSession dtor this=" << this << " _peer=" << _peer.lock().get() << std::endl;
|
||||
Log::info() << "MasterProcessSession ctor " << _kindString
|
||||
<< " this:" << this << " ws:" << _ws.get() << Log::end;
|
||||
|
||||
auto peer = _peer.lock();
|
||||
if (_kind == Kind::ToClient && peer)
|
||||
|
@ -212,8 +214,9 @@ bool MasterProcessSession::handleInput(const char *buffer, int length)
|
|||
|
||||
std::unique_lock<std::mutex> lock(_availableChildSessionMutex);
|
||||
_availableChildSessions.insert(std::pair<Thread::TID, std::shared_ptr<MasterProcessSession>> (tId, shared_from_this()));
|
||||
std::cout << Util::logPrefix() << _kindString << ",Inserted " << this << " id=" << childId << " into _availableChildSessions, size=" << _availableChildSessions.size() << std::endl;
|
||||
std::cout << Util::logPrefix() << "Inserted " << this << " id=" << childId << " into _availableChildSessions, size=" << _availableChildSessions.size() << std::endl;
|
||||
|
||||
Log::info() << _kindString << ",Inserted " << this << " id=" << childId << " into _availableChildSessions, size=" << _availableChildSessions.size() << Log::end;
|
||||
|
||||
_childId = childId;
|
||||
_pidChild = pidChild;
|
||||
lock.unlock();
|
||||
|
@ -379,7 +382,7 @@ bool MasterProcessSession::loadDocument(const char* /*buffer*/, int /*length*/,
|
|||
Log::info("Sending to Broker: " + aMessage);
|
||||
Util::writeFIFO(LOOLWSD::writerBroker, aMessage.c_str(), aMessage.length());
|
||||
}
|
||||
catch(Poco::SyntaxException&)
|
||||
catch (const Poco::SyntaxException&)
|
||||
{
|
||||
sendTextFrame("error: cmd=load kind=uriinvalid");
|
||||
return false;
|
||||
|
@ -607,7 +610,7 @@ void MasterProcessSession::dispatchChild()
|
|||
{
|
||||
File(aDstPath).createDirectories();
|
||||
}
|
||||
catch (Exception& exc)
|
||||
catch (const Exception& exc)
|
||||
{
|
||||
Log::error(
|
||||
"createDirectories(\"" + aDstPath.toString() + "\") failed: " + exc.displayText() );
|
||||
|
@ -636,7 +639,7 @@ void MasterProcessSession::dispatchChild()
|
|||
File(aSrcFile).copyTo(aDstFile.toString());
|
||||
}
|
||||
}
|
||||
catch (Exception& exc)
|
||||
catch (const Exception& exc)
|
||||
{
|
||||
Log::error("copyTo(\"" + aSrcFile.toString() + "\",\"" + aDstFile.toString() + "\") failed: " + exc.displayText());
|
||||
}
|
||||
|
|
|
@ -215,7 +215,7 @@ namespace Util
|
|||
{
|
||||
ws.shutdown();
|
||||
}
|
||||
catch (Poco::IOException& exc)
|
||||
catch (const Poco::IOException& exc)
|
||||
{
|
||||
Poco::Util::Application::instance().logger().error(logPrefix() + "IOException: " + exc.message());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue