[glom] Add a --stop-auto-server-shutdown command-line option for debugging.



commit 0d9be4039a477f5b0f9a61b38b3308c9ac7db96b
Author: Murray Cumming <murrayc murrayc com>
Date:   Tue Sep 7 11:28:50 2010 +0200

    Add a --stop-auto-server-shutdown command-line option for debugging.
    
    * glom/libglom/connectionpool.[h|cc]: Added set_auto_server_shutdown().
      startup(): Only handle the linux crash signal if this is set, so we can
      instead let gdb handle it.
    * glom/application.[h|cc]: Added set_stop_auto_server_shutdown() which calls
      it.
    * glom/main.cc: Add a --stop-auto-server-shutdown command line option that
      calls that.

 ChangeLog                      |   12 ++++++++++++
 glom/application.cc            |    7 +++++++
 glom/application.h             |    3 +++
 glom/libglom/connectionpool.cc |   28 +++++++++++++++++++---------
 glom/libglom/connectionpool.h  |    5 ++++-
 glom/main.cc                   |   10 +++++++++-
 6 files changed, 54 insertions(+), 11 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 5549f1f..d21f24b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2010-09-07  Murray Cumming  <murrayc murrayc com>
+
+	Add a --stop-auto-server-shutdown command-line option for debugging.
+
+	* glom/libglom/connectionpool.[h|cc]: Added set_auto_server_shutdown().
+  startup(): Only handle the linux crash signal if this is set, so we can
+  instead let gdb handle it.
+	* glom/application.[h|cc]: Added set_stop_auto_server_shutdown() which calls
+  it.
+	* glom/main.cc: Add a --stop-auto-server-shutdown command line option that
+  calls that.
+
 2010-09-06  Murray Cumming  <murrayc murrayc-desktop>
 
 	Renamed Dialog_GroupBy_SecondaryFields to Dialog_FieldsList.
diff --git a/glom/application.cc b/glom/application.cc
index def2a7a..73e17e3 100644
--- a/glom/application.cc
+++ b/glom/application.cc
@@ -243,6 +243,13 @@ void Application::set_show_sql_debug(bool val)
   m_show_sql_debug = val;
 }
 
+void Application::set_stop_auto_server_shutdown(bool val)
+{
+  ConnectionPool* connection_pool = ConnectionPool::get_instance();
+  if(connection_pool)
+    connection_pool->set_auto_server_shutdown(!val);
+}
+
 void Application::init_layout()
 {
   //We override this method so that we can put everything in the vbox from the glade file, instead of the vbox from App_Gtk.
diff --git a/glom/application.h b/glom/application.h
index af54244..26eb874 100644
--- a/glom/application.h
+++ b/glom/application.h
@@ -121,6 +121,9 @@ public:
   ///Whether to show the generated SQL queries on stdout, for debugging.
   void set_show_sql_debug(bool val = true);
 
+  ///Whether to automatically shutdown the database server when Glom crashes.
+  void set_stop_auto_server_shutdown(bool val = true);
+
   void show_table_details(const Glib::ustring& table_name, const Gnome::Gda::Value& primary_key_value);
   void show_table_list(const Glib::ustring& table_name);
 
diff --git a/glom/libglom/connectionpool.cc b/glom/libglom/connectionpool.cc
index 6b42e94..f558ece 100644
--- a/glom/libglom/connectionpool.cc
+++ b/glom/libglom/connectionpool.cc
@@ -104,7 +104,8 @@ ConnectionPool::ConnectionPool()
   m_sharedconnection_refcount(0),
   m_ready_to_connect(false),
   m_pFieldTypes(0),
-  m_show_debug_output(false)
+  m_show_debug_output(false),
+  m_auto_server_shutdown(true)
 {
 }
 
@@ -561,7 +562,7 @@ static void on_linux_signal(int signum)
 {
   ConnectionPool* connection_pool = ConnectionPool::get_instance();
   if(!connection_pool)
-  return;
+    return;
 
   if(signum == SIGSEGV)
   {
@@ -592,7 +593,8 @@ ConnectionPool::StartupErrors ConnectionPool::startup(const SlotProgress& slot_p
 
   //If we crash while running (unlikely, hopefully), then try to cleanup.
   //Comment this out if you want to see the backtrace in a debugger.
-  previous_sig_handler = signal(SIGSEGV, &on_linux_signal);
+  if(m_auto_server_shutdown)
+    previous_sig_handler = signal(SIGSEGV, &on_linux_signal);
 
   return started;
 }
@@ -623,8 +625,11 @@ bool ConnectionPool::cleanup(const SlotProgress& slot_progress)
 #endif // !G_OS_WIN32
 
   //We don't need the segfault handler anymore:
-  signal(SIGSEGV, previous_sig_handler);
-  previous_sig_handler = SIG_DFL; /* Arbitrary default */
+  if(previous_sig_handler != SIG_DFL) /* Arbitrary default */
+  {
+    signal(SIGSEGV, previous_sig_handler);
+    previous_sig_handler = SIG_DFL; /* Arbitrary default */
+  }
 
   return result;
 }
@@ -648,7 +653,7 @@ bool ConnectionPool::add_column(const Glib::ustring& table_name, const sharedptr
 
   if(!m_refGdaConnection)
     return false;
-  
+
   try
   {
     m_backend->add_column(m_refGdaConnection, table_name, field);
@@ -659,7 +664,7 @@ bool ConnectionPool::add_column(const Glib::ustring& table_name, const sharedptr
   {
     std::cerr << G_STRFUNC << ": exception:" << ex.what() << std::endl;
   }
-  
+
   return false;
 }
 
@@ -684,7 +689,7 @@ bool ConnectionPool::drop_column(const Glib::ustring& table_name, const Glib::us
   {
     std::cerr << G_STRFUNC << ": exception:" << ex.what() << std::endl;
   }
-  
+
   return false;
 }
 
@@ -905,10 +910,15 @@ void ConnectionPool::set_show_debug_output(bool val)
 {
   m_show_debug_output = val;
 }
- 
+
 bool ConnectionPool::get_show_debug_output() const
 {
   return m_show_debug_output;
 }
 
+void ConnectionPool::set_auto_server_shutdown(bool val)
+{
+  m_auto_server_shutdown = val;
+}
+
 } //namespace Glom
diff --git a/glom/libglom/connectionpool.h b/glom/libglom/connectionpool.h
index cb14880..6f64de0 100644
--- a/glom/libglom/connectionpool.h
+++ b/glom/libglom/connectionpool.h
@@ -212,6 +212,9 @@ public:
    */
   bool cleanup(const SlotProgress& slot_progress);
 
+  ///Whether to automatically shutdown the database server when Glom crashes.
+  void set_auto_server_shutdown(bool val = true);
+
   /** Change the database server's configration to allow or prevent access from
    * other users on the network.
    *
@@ -289,7 +292,7 @@ private:
   Glib::ustring m_host, m_user, m_password, m_database;
 
   FieldTypes* m_pFieldTypes;
-  bool m_show_debug_output;
+  bool m_show_debug_output, m_auto_server_shutdown;
 
 private:
 
diff --git a/glom/main.cc b/glom/main.cc
index d168529..88e8966 100644
--- a/glom/main.cc
+++ b/glom/main.cc
@@ -189,6 +189,7 @@ public:
   std::string m_arg_filename;
   bool m_arg_version;
   bool m_arg_restore;
+  bool m_arg_stop_auto_server_shutdown;
   bool m_arg_debug_sql;
   bool m_arg_debug_date_check;
 };
@@ -197,6 +198,7 @@ OptionGroup::OptionGroup()
 : Glib::OptionGroup("Glom", _("Glom options"), _("Command-line options for glom")),
   m_arg_version(false),
   m_arg_restore(false),
+  m_arg_stop_auto_server_shutdown(false),
   m_arg_debug_sql(false),
   m_arg_debug_date_check(false)
 {
@@ -217,6 +219,11 @@ OptionGroup::OptionGroup()
   entry_restore.set_description(_("Whether the filename is a .tar.gz backup to be restored."));
   add_entry(entry_restore, m_arg_restore);
 
+  Glib::OptionEntry entry_stop_auto_server_shutdown;
+  entry_stop_auto_server_shutdown.set_long_name("stop-auto-server-shutdown");
+  entry_stop_auto_server_shutdown.set_description(_("Do not automatically stop the database server if Glom quits. This is helpful for debugging with gdb."));
+  add_entry(entry_stop_auto_server_shutdown, m_arg_stop_auto_server_shutdown);
+
   Glib::OptionEntry entry_debug_sql;
   entry_debug_sql.set_long_name("debug_sql");
   entry_debug_sql.set_description(_("Show the generated SQL queries on stdout, for debugging."));
@@ -468,7 +475,7 @@ main(int argc, char* argv[])
   PySys_SetArgv(argc, argv);
 
   std::auto_ptr<Gtk::Main> mainInstance;
-  try 
+  try
   {
     mainInstance = std::auto_ptr<Gtk::Main>( new Gtk::Main(argc, argv, context) );
   }
@@ -611,6 +618,7 @@ main(int argc, char* argv[])
 
     pApplication->set_command_line_args(argc, argv);
     pApplication->set_show_sql_debug(group.m_arg_debug_sql);
+    pApplication->set_stop_auto_server_shutdown(group.m_arg_stop_auto_server_shutdown);
     Glom::ConnectionPool::get_instance()->set_show_debug_output(group.m_arg_debug_sql);
 
     const bool test = pApplication->init(input_uri, group.m_arg_restore); //Sets it up and shows it.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]