loolwsd/DocumentBroker.hpp | 37 ++++++++++++++++++++++++++++--------- loolwsd/LOOLKit.cpp | 5 +++++ loolwsd/protocol.txt | 4 ++++ 3 files changed, 37 insertions(+), 9 deletions(-)
New commits: commit 8cd8ca27a642c3049476a575948f63e34ebb8df8 Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk> Date: Sun Nov 6 21:16:11 2016 -0500 loolwsd: new 'exit' command to request child process termination Change-Id: Id3f9bc67096b422630e04f59ed4ccbca012ddd4a Reviewed-on: https://gerrit.libreoffice.org/30641 Reviewed-by: Ashod Nakashian <ashnak...@gmail.com> Tested-by: Ashod Nakashian <ashnak...@gmail.com> diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp index fdb7fac..60a7099 100644 --- a/loolwsd/DocumentBroker.hpp +++ b/loolwsd/DocumentBroker.hpp @@ -69,6 +69,18 @@ public: { LOG_DBG("Stopping ChildProcess [" << _pid << "]"); _stop = true; + + try + { + if (_pid != -1 && _ws) + { + sendTextFrame("exit"); + } + } + catch (const std::exception&) + { + LOG_ERR("Failed to send 'exit' command to child [" << _pid << "]."); + } } void close(const bool rude) @@ -84,16 +96,19 @@ public: } _ws.reset(); - if (_pid != -1) + if (_pid != -1 && kill(_pid, 0) != 0) { - LOG_INF("Closing child [" << _pid << "]."); - if (rude && kill(_pid, SIGINT) != 0 && kill(_pid, 0) != 0) + if (rude) { - Log::syserror("Cannot terminate lokit [" + std::to_string(_pid) + "]. Abandoning."); + LOG_INF("Killing child [" << _pid << "]."); + if (kill(_pid, SIGINT) != 0 && kill(_pid, 0) != 0) + { + Log::syserror("Cannot terminate lokit [" + std::to_string(_pid) + "]. Abandoning."); + } } - - _pid = -1; } + + _pid = -1; } catch (const std::exception& ex) { @@ -108,9 +123,12 @@ public: { try { - LOG_TRC("DocBroker to Child: " << data); - _ws->sendFrame(data.data(), data.size()); - return true; + if (_ws) + { + LOG_TRC("DocBroker to Child: " << data); + _ws->sendFrame(data.data(), data.size()); + return true; + } } catch (const std::exception& exc) { @@ -119,6 +137,7 @@ public: throw; } + LOG_WRN("No socket between DocBroker and child to send [" << data << "]"); return false; } diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 2fc199d..a89ba53 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -1521,6 +1521,11 @@ void lokit_main(const std::string& childRoot, LOG_DBG("CreateSession failed."); } } + else if (tokens[0] == "exit") + { + LOG_TRC("Setting TerminationFlag due to 'exit' command from parent."); + TerminationFlag = true; + } else if (tokens[0] == "tile" || tokens[0] == "tilecombine" || tokens[0] == "canceltiles" || LOOLProtocol::getFirstToken(tokens[0], '-') == "child") { diff --git a/loolwsd/protocol.txt b/loolwsd/protocol.txt index 560208f..f6035b9 100644 --- a/loolwsd/protocol.txt +++ b/loolwsd/protocol.txt @@ -395,6 +395,10 @@ disconnect Signals to the child that the client for the respective connection has disconnected. +exit + + Signals to the child that the process must end and exit. + Admin console =============== _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits