From 54ed350776d4f78de9aabb0273f085aa7c2ce124 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. --- nls/fluxbox-nls.hh | 2 ++ src/FbTk/LResource.cc | 52 ++++++++++++++++++++++++++++++++++++--------------- src/FbTk/LResource.hh | 3 +++ src/Keys.cc | 2 ++ src/fluxbox.cc | 28 ++++++++------------------- src/fluxbox.hh | 4 ---- 6 files changed, 52 insertions(+), 39 deletions(-) diff --git a/nls/fluxbox-nls.hh b/nls/fluxbox-nls.hh index a218ea9..023d229 100644 --- a/nls/fluxbox-nls.hh +++ b/nls/fluxbox-nls.hh @@ -131,6 +131,8 @@ enum { KeysBadLine = 1, KeysBadMerge = 2, KeysInvalidKeyMod = 3, + KeysBad3rdArg = 4, + KeysLoadError = 5, MenuSet = 10, MenuConfiguration = 1, 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/Keys.cc b/src/Keys.cc index f741be6..fcf8150 100644 --- a/src/Keys.cc +++ b/src/Keys.cc @@ -223,6 +223,7 @@ int Keys::t_key::newindex(lua::state *l) } else if(l->isnil(3)) k2.reset(); else { + _FB_USES_NLS; throw KeyError(_FB_CONSOLETEXT(Keys, Bad3rdArg, "3rd argument is not a command.", "3rd argument is not a command.")); } @@ -580,6 +581,7 @@ void Keys::reload() { l.call(0, 0); } catch(std::runtime_error &e) { + _FB_USES_NLS; cerr << _FB_CONSOLETEXT(Keys, LoadError, "Error loading keys file: ", "Actual error message follows") << e.what() << endl; loadDefaults(l); diff --git a/src/fluxbox.cc b/src/fluxbox.cc index e293606..f66d83d 100644 --- a/src/fluxbox.cc +++ b/src/fluxbox.cc @@ -310,7 +310,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(1); m_reconfig_timer.setCommand(reconfig_cmd); m_reconfig_timer.fireOnce(true); @@ -438,8 +438,6 @@ Fluxbox::Fluxbox(int argc, char **argv, //XSynchronize(disp, False); sync(false); - m_reconfigure_wait = false; - ungrab(); m_starting = false; @@ -905,7 +903,7 @@ void Fluxbox::handleSignal(int signum) { load_rc(); break; case SIGUSR2: - reconfigure(); + m_reconfig_timer.start(); break; #endif case SIGSEGV: @@ -1190,17 +1188,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; @@ -1213,11 +1200,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 68e4fb5..c24d581 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); @@ -272,7 +269,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