From fa82f62dde8a8c43f5bac93993e5a047be14c70f Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Sat, 30 Jul 2011 12:21:53 +0200 Subject: Create a completely new lua state upon USR2 reconfigure This way, global variables set by the scripts don't persist between hard reconfigures. I also cleaned up the reconfig-handling code in fluxbox.cc. Instead of three reconfig functions (real_reconfig, timed_reconfig, reconfig) we have just one. --- src/FbTk/LResource.cc | 52 ++++++++++++++++++++++++++++++++++++--------------- src/FbTk/LResource.hh | 3 +++ src/fluxbox.cc | 28 ++++++++------------------- src/fluxbox.hh | 4 ---- 4 files changed, 48 insertions(+), 39 deletions(-) diff --git a/src/FbTk/LResource.cc b/src/FbTk/LResource.cc index d7627c9..0909520 100644 --- a/src/FbTk/LResource.cc +++ b/src/FbTk/LResource.cc @@ -101,17 +101,8 @@ void LResourceManager::convert(ResourceManager &old, const std::string &new_file } LResourceManager::LResourceManager(const std::string &root, Lua &l) - : ResourceManager_base(root), m_l(&l) { - l.checkstack(2); - lua::stack_sentry s(l); - - l.pushstring(root); - - l.getfield(lua::REGISTRYINDEX, make_root); - l.pushstring(root); - l.call(1, 1); - - l.readOnlySet(lua::GLOBALSINDEX); + : ResourceManager_base(root), m_l(&l) { + setLua(l); } bool LResourceManager::save(const char *filename, const char *) { @@ -127,11 +118,20 @@ bool LResourceManager::save(const char *filename, const char *) { } void LResourceManager::addResource(Resource_base &r) { + ResourceManager_base::addResource(r); + try { + doAddResource(r); + } + catch(...) { + ResourceManager_base::removeResource(r); + throw; + } +} + +void LResourceManager::doAddResource(Resource_base &r) { m_l->checkstack(5); lua::stack_sentry s(*m_l); - ResourceManager_base::addResource(r); - m_l->getfield(lua::REGISTRYINDEX, register_resource); m_l->getfield(lua::GLOBALSINDEX, m_root.c_str()); m_l->pushstring(r.name()); @@ -143,7 +143,12 @@ void LResourceManager::addResource(Resource_base &r) { } void LResourceManager::removeResource(Resource_base &r) { - m_l->checkstack(5); + doRemoveResource(r); + ResourceManager_base::removeResource(r); +} + +void LResourceManager::doRemoveResource(Resource_base &r) { + m_l->checkstack(4); lua::stack_sentry s(*m_l); m_l->getfield(lua::REGISTRYINDEX, register_resource); @@ -153,8 +158,25 @@ void LResourceManager::removeResource(Resource_base &r) { m_l->call(3, 1); *static_cast(m_l->touserdata(-1)) = NULL; m_l->pop(); +} - ResourceManager_base::removeResource(r); +void LResourceManager::setLua(Lua &l) { + l.checkstack(2); + lua::stack_sentry s(l); + + for(ResourceList::const_iterator i = begin(); i != end(); ++i) + doRemoveResource(**i); + + l.getfield(lua::REGISTRYINDEX, make_root); + l.pushstring(m_root); + l.call(1, 1); + + l.readOnlySetField(lua::GLOBALSINDEX, m_root.c_str()); + + m_l = &l; + + for(ResourceList::const_iterator i = begin(); i != end(); ++i) + doAddResource(**i); } } // end namespace FbTk diff --git a/src/FbTk/LResource.hh b/src/FbTk/LResource.hh index 1567269..bb7f224 100644 --- a/src/FbTk/LResource.hh +++ b/src/FbTk/LResource.hh @@ -41,8 +41,11 @@ public: virtual bool save(const char *filename, const char *); virtual void addResource(Resource_base &r); virtual void removeResource(Resource_base &r); + void setLua(Lua &l); private: + void doAddResource(Resource_base &r); + void doRemoveResource(Resource_base &r); Lua *m_l; }; diff --git a/src/fluxbox.cc b/src/fluxbox.cc index 8b5d11f..c4e6559 100644 --- a/src/fluxbox.cc +++ b/src/fluxbox.cc @@ -303,7 +303,7 @@ Fluxbox::Fluxbox(int argc, char **argv, // Because when the command is executed we shouldn't do reconfig directly // because it could affect ongoing menu stuff so we need to reconfig in // the next event "round". - FbTk::RefCount > reconfig_cmd(new FbTk::SimpleCommand(*this, &Fluxbox::timed_reconfigure)); + FbTk::RefCount > reconfig_cmd(new FbTk::SimpleCommand(*this, &Fluxbox::reconfigure)); m_reconfig_timer.setTimeout(0, 1); m_reconfig_timer.setCommand(reconfig_cmd); m_reconfig_timer.fireOnce(true); @@ -435,8 +435,6 @@ Fluxbox::Fluxbox(int argc, char **argv, //XSynchronize(disp, False); sync(false); - m_reconfigure_wait = false; - ungrab(); m_starting = false; @@ -896,7 +894,7 @@ void Fluxbox::handleSignal(int signum) { load_rc(); break; case SIGUSR2: - reconfigure(); + m_reconfig_timer.start(); break; #endif case SIGSEGV: @@ -1181,17 +1179,6 @@ void Fluxbox::load_rc() { *m_rc_stylefile = DEFAULTSTYLE; } -void Fluxbox::reconfigure() { - load_rc(); - m_reconfigure_wait = true; - m_reconfig_timer.start(); -} - - -void Fluxbox::real_reconfigure() { - STLUtil::forAll(m_screen_list, mem_fun(&BScreen::reconfigure)); -} - BScreen *Fluxbox::findScreen(int id) { BScreen* result = 0; @@ -1204,11 +1191,12 @@ BScreen *Fluxbox::findScreen(int id) { return result; } -void Fluxbox::timed_reconfigure() { - if (m_reconfigure_wait) - real_reconfigure(); - - m_reconfigure_wait = false; +void Fluxbox::reconfigure() { + std::auto_ptr t = m_l; + m_l.reset(new Lua); + m_resourcemanager.setLua(*m_l); + load_rc(); + STLUtil::forAll(m_screen_list, mem_fun(&BScreen::reconfigure)); } void Fluxbox::revertFocus() { diff --git a/src/fluxbox.hh b/src/fluxbox.hh index 6be5253..00a2e7d 100644 --- a/src/fluxbox.hh +++ b/src/fluxbox.hh @@ -159,7 +159,6 @@ public: void attachSignals(FluxboxWindow &win); void attachSignals(WinClient &winclient); - void timed_reconfigure(); void revertFocus(); void setShowingDialog(bool value) { m_showing_dialog = value; if (!value) revertFocus(); @@ -193,8 +192,6 @@ private: std::string getRcFilename(); void load_rc(); - void real_reconfigure(); - void handleEvent(XEvent *xe); void handleUnmapNotify(XUnmapEvent &ue); @@ -273,7 +270,6 @@ private: Atom m_fluxbox_pid; - bool m_reconfigure_wait; Time m_last_time; Window m_masked; std::string m_rc_file; ///< resource filename -- cgit v0.11.2