[Libreoffice-commits] online.git: loolwsd/LOOLSession.cpp loolwsd/LOOLWSD.cpp loolwsd/LOOLWSD.hpp
loolwsd/LOOLSession.cpp |2 +- loolwsd/LOOLWSD.cpp | 17 ++--- loolwsd/LOOLWSD.hpp |3 +-- 3 files changed, 8 insertions(+), 14 deletions(-) New commits: commit c0fbf5ebf995d9390b776d566565cc52346bc2b9 Author: Henry CastroDate: Wed Nov 25 23:17:08 2015 -0400 loolwsd: remove child root folder when it is a gracefull shut down diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp index d517651..1bac381 100644 --- a/loolwsd/LOOLSession.cpp +++ b/loolwsd/LOOLSession.cpp @@ -325,7 +325,7 @@ bool MasterProcessSession::handleInput(const char *buffer, int length) std::unique_lock lock(_availableChildSessionMutex); _availableChildSessions.insert(shared_from_this()); std::cout << Util::logPrefix() << "Inserted " << this << " id=" << childId << " into _availableChildSessions, size=" << _availableChildSessions.size() << std::endl; -_childId = childId; +LOOLWSD::_childId = _childId = childId; lock.unlock(); _availableChildSessionCV.notify_one(); diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index a814de1..b1f0138 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -573,6 +573,7 @@ private: int LOOLWSD::portNumber = DEFAULT_CLIENT_PORT_NUMBER; int LOOLWSD::timeoutCounter = 0; +Poco::UInt64 LOOLWSD::_childId = 0; std::string LOOLWSD::cache = LOOLWSD_CACHEDIR; std::string LOOLWSD::sysTemplate; std::string LOOLWSD::loTemplate; @@ -595,8 +596,7 @@ const std::string LOOLWSD::CHILD_URI = "/loolws/child/"; const std::string LOOLWSD::PIDLOG = "/tmp/loolwsd.pid"; const std::string LOOLWSD::LOKIT_PIDLOG = "/tmp/lokit.pid"; -LOOLWSD::LOOLWSD() : -_childId(0) +LOOLWSD::LOOLWSD() { } @@ -1245,10 +1245,6 @@ int LOOLWSD::main(const std::vector& /*args*/) filePID << Process::id(); } -std::unique_lock rngLock(_rngMutex); -_childId = (((Poco::UInt64)_rng.next()) << 32) | _rng.next() | 1; -rngLock.unlock(); - _namedMutexLOOL.lock(); startupDesktop(1); @@ -1338,12 +1334,11 @@ int LOOLWSD::main(const std::vector& /*args*/) // wait broker process finish waitpid(-1, , WUNTRACED); -return Application::EXIT_OK; -} +// remove child root +if (LOOLWSD::_childId > 0) +File(LOOLWSD::childRoot + Path::separator() + std::to_string(LOOLWSD::_childId)).remove(true); -bool LOOLWSD::childMode() const -{ -return _childId != 0; +return Application::EXIT_OK; } POCO_SERVER_MAIN(LOOLWSD) diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp index 342b36c..0970fc5 100644 --- a/loolwsd/LOOLWSD.hpp +++ b/loolwsd/LOOLWSD.hpp @@ -43,6 +43,7 @@ public: static Poco::SharedMemory _sharedForkChild; static Poco::NamedMutex _namedMutexLOOL; static Poco::Random _rng; +static Poco::UInt64 _childId; static const int DEFAULT_CLIENT_PORT_NUMBER = 9980; static const int MASTER_PORT_NUMBER = 9981; @@ -65,7 +66,6 @@ protected: private: void displayHelp(); -bool childMode() const; void componentMain(); void desktopMain(); void startupComponent(int nComponents); @@ -73,7 +73,6 @@ private: int createComponent(); int createDesktop(); -Poco::UInt64 _childId; static int _numPreSpawnedChildren; static std::mutex _rngMutex; ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLSession.cpp loolwsd/LOOLWSD.cpp loolwsd/LOOLWSD.hpp
loolwsd/LOOLSession.cpp | 12 loolwsd/LOOLWSD.cpp |8 +--- loolwsd/LOOLWSD.hpp |2 +- 3 files changed, 14 insertions(+), 8 deletions(-) New commits: commit 0ec12fe11ec22d8a4a7ce1d334b4af2f5465ca98 Author: Henry Castro hcas...@collabora.com Date: Wed Aug 5 18:19:51 2015 -0400 loolwsd: fix child fork when debugging one child diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp index c74920f..ac299f4 100644 --- a/loolwsd/LOOLSession.cpp +++ b/loolwsd/LOOLSession.cpp @@ -467,13 +467,17 @@ void MasterProcessSession::dispatchChild() } childSession = *(_availableChildSessions.begin()); - _availableChildSessions.erase(childSession); -std::cout Util::logPrefix() _availableChildSessions size= _availableChildSessions.size() std::endl; -if (_availableChildSessions.size() == 0) -LOOLWSD::_sharedForkChild.begin()[0] = 1; lock.unlock(); +if (_availableChildSessions.size() == 0) +{ +LOOLWSD::_namedMutexLOOL.lock(); +std::cout Util::logPrefix() No available child sessions, queue new child session std::endl; +LOOLWSD::_sharedForkChild.begin()[0] = (LOOLWSD::_sharedForkChild.begin()[0] 0 ? LOOLWSD::_sharedForkChild.begin()[0] + 1 : 1); +LOOLWSD::_namedMutexLOOL.unlock(); +} + // Assume a valid URI URI aUri(_docURL); diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index ae2ed32..84f6bf5 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -947,10 +947,12 @@ void LOOLWSD::desktopMain() else if (pid 0) std::cout Util::logPrefix() Child error: strerror(errno); -if ( _sharedForkChild.begin()[0] ) +if ( _sharedForkChild.begin()[0] 0 ) { -_sharedForkChild.begin()[0] = 0; -std::cout Util::logPrefix() No availabe child session, fork new one std::endl; +_namedMutexLOOL.lock(); +_sharedForkChild.begin()[0] = _sharedForkChild.begin()[0] - 1; +std::cout Util::logPrefix() Create child session, fork new one std::endl; +_namedMutexLOOL.unlock(); if (createComponent() 0 ) break; } diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp index 331e9f3..7b5bfd9 100644 --- a/loolwsd/LOOLWSD.hpp +++ b/loolwsd/LOOLWSD.hpp @@ -39,6 +39,7 @@ public: static std::string loSubPath; static std::string jail; static Poco::SharedMemory _sharedForkChild; +static Poco::NamedMutex _namedMutexLOOL; static const int DEFAULT_CLIENT_PORT_NUMBER = 9980; static const int MASTER_PORT_NUMBER = 9981; @@ -69,7 +70,6 @@ private: static int _numPreSpawnedChildren; static std::mutex _rngMutex; static Poco::Random _rng; -static Poco::NamedMutex _namedMutexLOOL; #if ENABLE_DEBUG public: ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLSession.cpp loolwsd/LOOLWSD.cpp loolwsd/LOOLWSD.hpp
loolwsd/LOOLSession.cpp |2 +- loolwsd/LOOLWSD.cpp |6 +++--- loolwsd/LOOLWSD.hpp |2 +- 3 files changed, 5 insertions(+), 5 deletions(-) New commits: commit 1c0153d5e0350ee71437dd14a977f8f7f6f9d61a Author: Henry Castro hcas...@collabora.com Date: Wed Aug 5 20:01:39 2015 -0400 loolwsd: ensure one child when debugging when used with --test option: ./loolwsd --test --systemplate=${SYSTEMPLATE} --lotemplate=${MASTER}/instdir --childroot=${ROOTFORJAILS} ensure that one child is created and attach to it easily to debug lokit messages diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp index ac299f4..10e299f 100644 --- a/loolwsd/LOOLSession.cpp +++ b/loolwsd/LOOLSession.cpp @@ -470,7 +470,7 @@ void MasterProcessSession::dispatchChild() _availableChildSessions.erase(childSession); lock.unlock(); -if (_availableChildSessions.size() == 0) +if (_availableChildSessions.size() == 0 !LOOLWSD::doTest) { LOOLWSD::_namedMutexLOOL.lock(); std::cout Util::logPrefix() No available child sessions, queue new child session std::endl; diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 84f6bf5..6d640d6 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -426,6 +426,7 @@ Poco::NamedMutex LOOLWSD::_namedMutexLOOL(loolwsd); Poco::SharedMemory LOOLWSD::_sharedForkChild(loolwsd, sizeof(bool), Poco::SharedMemory::AM_WRITE); int LOOLWSD::_numPreSpawnedChildren = 10; +bool LOOLWSD::doTest = false; #if ENABLE_DEBUG bool LOOLWSD::runningAsRoot = false; int LOOLWSD::uid = 0; @@ -434,7 +435,6 @@ const std::string LOOLWSD::CHILD_URI = /loolws/child/; const std::string LOOLWSD::PIDLOG = /tmp/loolwsd.pid; LOOLWSD::LOOLWSD() : -_doTest(false), _childId(0) { } @@ -543,7 +543,7 @@ void LOOLWSD::handleOption(const std::string name, const std::string value) else if (name == numprespawns) _numPreSpawnedChildren = std::stoi(value); else if (name == test) -_doTest = true; +LOOLWSD::doTest = true; else if (name == child) _childId = std::stoull(value); else if (name == jail) @@ -1032,7 +1032,7 @@ int LOOLWSD::main(const std::vectorstd::string args) if (portNumber == MASTER_PORT_NUMBER) throw IncompatibleOptionsException(port); -if (_doTest) +if (LOOLWSD::doTest) _numPreSpawnedChildren = 1; // log pid information diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp index 7b5bfd9..494fd8c 100644 --- a/loolwsd/LOOLWSD.hpp +++ b/loolwsd/LOOLWSD.hpp @@ -32,6 +32,7 @@ public: // statics static int portNumber; static int timeoutCounter; +static bool doTest; static std::string cache; static std::string sysTemplate; static std::string loTemplate; @@ -65,7 +66,6 @@ private: int createComponent(); int createDesktop(); -bool _doTest; Poco::UInt64 _childId; static int _numPreSpawnedChildren; static std::mutex _rngMutex; ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLSession.cpp loolwsd/LOOLWSD.cpp loolwsd/LOOLWSD.hpp
loolwsd/LOOLSession.cpp | 12 +++- loolwsd/LOOLWSD.cpp |3 ++- loolwsd/LOOLWSD.hpp |1 + 3 files changed, 14 insertions(+), 2 deletions(-) New commits: commit ee928f9af1bd05752604a10af22e0c4e9180dec7 Author: Henry Castro hcas...@collabora.com Date: Wed Aug 5 20:20:05 2015 -0400 loolwsd: create lokit process id logs Also, when used with --test option, create lokit PID log so it is attached to the debugger. gdb loolwsd $(cat /tmp/lokit.pid) diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp index 10e299f..f7439c5 100644 --- a/loolwsd/LOOLSession.cpp +++ b/loolwsd/LOOLSession.cpp @@ -46,6 +46,7 @@ #include Poco/Net/NetException.h #include Poco/Net/DialogSocket.h #include Poco/Net/SocketAddress.h +#include Poco/FileStream.h #include LOKitHelper.hpp #include LOOLProtocol.hpp @@ -223,13 +224,14 @@ bool MasterProcessSession::handleInput(const char *buffer, int length) sendTextFrame(error: cmd=child kind=invalid); return false; } -if (tokens.count() != 2) +if (tokens.count() != 3) { sendTextFrame(error: cmd=child kind=syntax); return false; } UInt64 childId = std::stoull(tokens[1]); +Process::PID pidChild = std::stoull(tokens[2]); std::unique_lockstd::mutex lock(_availableChildSessionMutex); _availableChildSessions.insert(shared_from_this()); @@ -237,6 +239,14 @@ bool MasterProcessSession::handleInput(const char *buffer, int length) _childId = childId; lock.unlock(); _availableChildSessionCV.notify_one(); + +// log first lokit child pid information +if ( LOOLWSD::doTest ) +{ +Poco::FileOutputStream filePID(LOOLWSD::LOKIT_PIDLOG); +if (filePID.good()) +filePID pidChild; +} } else if (_kind == Kind::ToPrisoner) { diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 6d640d6..3d4869e 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -433,6 +433,7 @@ int LOOLWSD::uid = 0; #endif const std::string LOOLWSD::CHILD_URI = /loolws/child/; const std::string LOOLWSD::PIDLOG = /tmp/loolwsd.pid; +const std::string LOOLWSD::LOKIT_PIDLOG = /tmp/lokit.pid; LOOLWSD::LOOLWSD() : _childId(0) @@ -758,7 +759,7 @@ void LOOLWSD::componentMain() ws-setReceiveTimeout(0); -std::string hello(child + std::to_string(_childId)); +std::string hello(child + std::to_string(_childId) + + std::to_string(Process::id())); session-sendTextFrame(hello); tsqueuestd::string queue; diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp index 494fd8c..aa419c6 100644 --- a/loolwsd/LOOLWSD.hpp +++ b/loolwsd/LOOLWSD.hpp @@ -48,6 +48,7 @@ public: static const int MAINTENANCE_INTERVAL = 1; static const std::string CHILD_URI; static const std::string PIDLOG; +static const std::string LOKIT_PIDLOG; protected: void initialize(Poco::Util::Application self) override; ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLSession.cpp loolwsd/LOOLWSD.cpp loolwsd/LOOLWSD.hpp
loolwsd/LOOLSession.cpp |2 + loolwsd/LOOLWSD.cpp | 83 +--- loolwsd/LOOLWSD.hpp |2 + 3 files changed, 62 insertions(+), 25 deletions(-) New commits: commit 99ca81a944b12a90ebdd744965b18850bae7baf8 Author: Henry Castro hcas...@collabora.com Date: Fri Jul 17 14:02:25 2015 -0400 loolwsd: move server socket to parent process diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp index 75f1fdc..502010a 100644 --- a/loolwsd/LOOLSession.cpp +++ b/loolwsd/LOOLSession.cpp @@ -492,6 +492,8 @@ void MasterProcessSession::dispatchChild() _availableChildSessions.erase(childSession); std::cout Util::logPrefix() _availableChildSessions size= _availableChildSessions.size() std::endl; +if (_availableChildSessions.size() == 0) +LOOLWSD::_sharedForkChild.begin()[0] = 1; lock.unlock(); // Assume a valid URI diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index e5be693..595f955 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -507,6 +507,7 @@ std::string LOOLWSD::jail; std::mutex LOOLWSD::_rngMutex; Random LOOLWSD::_rng; static NamedMutex namedMutexLOOL(loolwsd); +Poco::SharedMemory LOOLWSD::_sharedForkChild(loolwsd, sizeof(bool), Poco::SharedMemory::AM_WRITE); int LOOLWSD::_numPreSpawnedChildren = 10; #if ENABLE_DEBUG @@ -811,6 +812,7 @@ void LOOLWSD::componentMain() { try { + // initialisation //_childId = Process::id(); @@ -997,30 +999,8 @@ void LOOLWSD::desktopMain() Thread::sleep(std::stoul(std::getenv(SLEEPFORDEBUGGER)) * 1000); } -namedMutexLOOL.lock(); - startupComponent(_numPreSpawnedChildren); -// Start a server listening on the port for clients -ServerSocket svs(portNumber, _numPreSpawnedChildren*10); -ThreadPool threadPool(_numPreSpawnedChildren*2, _numPreSpawnedChildren*5); -HTTPServer srv(new RequestHandlerFactory(), threadPool, svs, new HTTPServerParams); - -srv.start(); - -// And one on the port for child processes -SocketAddress addr2(127.0.0.1, MASTER_PORT_NUMBER); -ServerSocket svs2(addr2, _numPreSpawnedChildren); -ThreadPool threadPool2(_numPreSpawnedChildren*2, _numPreSpawnedChildren*5); -HTTPServer srv2(new RequestHandlerFactory(), threadPool2, svs2, new HTTPServerParams); - -srv2.start(); - -namedMutexLOOL.unlock(); - -/* Pause for a second */ -sleep(1); - while (MasterProcessSession::_childProcesses.size() 0) { int status; @@ -1055,8 +1035,9 @@ void LOOLWSD::desktopMain() else if (pid 0) std::cout Util::logPrefix() Child error: strerror(errno); -if (MasterProcessSession::getAvailableChildSessions() == 0 MasterProcessSession::getPendingPreSpawnedChildren() == 0 ) +if ( _sharedForkChild.begin()[0] ) { +_sharedForkChild.begin()[0] = 0; std::cout Util::logPrefix() No availabe child session, fork new one std::endl; if (createComponent() 0 ) break; @@ -1110,6 +1091,8 @@ void LOOLWSD::loolMain() _childId = (((Poco::UInt64)_rng.next()) 32) | _rng.next() | 1; rngLock.unlock(); +namedMutexLOOL.lock(); + startupDesktop(1); #ifdef __linux @@ -1118,12 +1101,62 @@ void LOOLWSD::loolMain() dropCapability(); #endif +// Start a server listening on the port for clients +ServerSocket svs(portNumber, _numPreSpawnedChildren*10); +ThreadPool threadPool(_numPreSpawnedChildren*2, _numPreSpawnedChildren*5); +HTTPServer srv(new RequestHandlerFactory(), threadPool, svs, new HTTPServerParams); + +srv.start(); + +// And one on the port for child processes +SocketAddress addr2(127.0.0.1, MASTER_PORT_NUMBER); +ServerSocket svs2(addr2, _numPreSpawnedChildren); +ThreadPool threadPool2(_numPreSpawnedChildren*2, _numPreSpawnedChildren*5); +HTTPServer srv2(new RequestHandlerFactory(), threadPool2, svs2, new HTTPServerParams); + +srv2.start(); + +namedMutexLOOL.unlock(); + Thread threadFile; FileTransferHandler svrFile; threadFile.start(svrFile); -int status; -waitpid(-1, status, 0); +while (MasterProcessSession::_childProcesses.size() 0) +{ +int status; +pid_t pid = waitpid(-1, status, WUNTRACED | WNOHANG); +if (pid 0) +{ +if ( MasterProcessSession::_childProcesses.find(pid) != MasterProcessSession::_childProcesses.end() ) +{ +if ((WIFEXITED(status) || WIFSIGNALED(status) || WTERMSIG(status) ) ) +{ +std::cout Util::logPrefix() One of our known child processes died : std::to_string(pid) std::endl; +MasterProcessSession::_childProcesses.erase(pid); +} + +if ( WCOREDUMP(status) ) +std::cout Util::logPrefix() The child produced a core dump.