[glom] Command spawning: Really check the return value.



commit f3d5e05bb6068d617ff433a68e410a815564de39
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Sep 25 10:28:29 2009 +0200

    Command spawning: Really check the return value.
    
    * glom/libglom/spawn_with_feedback.cc:
    execute_command_line_and_wait_until_second_command_returns_success():
    Actually check the return value of the first command, so we can fail
    immediately (with stderr output) when, for instance, postgresql
    fails to read the configuration file due to changed options, such as
    no longer recognizing max_fsm_pages in PostgreSQL 8.4

 ChangeLog                           |   11 +++++++++++
 glom/libglom/spawn_with_feedback.cc |   26 +++++++++++++++-----------
 2 files changed, 26 insertions(+), 11 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 6c2c631..f15307d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2009-09-25  Murray Cumming  <murrayc murrayc com>
 
+	Command spawning: Really check the return value.
+
+	* glom/libglom/spawn_with_feedback.cc:
+	execute_command_line_and_wait_until_second_command_returns_success():
+	Actually check the return value of the first command, so we can fail 
+	immediately (with stderr output) when, for instance, postgresql 
+	fails to read the configuration file due to changed options, such as 
+	no longer recognizing max_fsm_pages in PostgreSQL 8.4
+
+2009-09-25  Murray Cumming  <murrayc murrayc com>
+
 	Replace some NULLs with 0 because this is C++, not C.
 
 	* glom/libglom/connectionpool_backends/postgres.cc:
diff --git a/glom/libglom/spawn_with_feedback.cc b/glom/libglom/spawn_with_feedback.cc
index d7a1a48..116223d 100644
--- a/glom/libglom/spawn_with_feedback.cc
+++ b/glom/libglom/spawn_with_feedback.cc
@@ -337,12 +337,16 @@ private:
 #endif
 };
 
-std::auto_ptr<const SpawnInfo> spawn_async(const Glib::ustring& command_line, int redirect)
+static std::auto_ptr<const SpawnInfo> spawn_async(const Glib::ustring& command_line, int redirect)
 {
   return std::auto_ptr<const SpawnInfo>(new SpawnInfo(command_line, redirect));
 }
 
-bool spawn_async_end(std::auto_ptr<const SpawnInfo> info, std::string* stdout_text = 0, std::string* stderr_text = 0, int* return_status = 0)
+/**
+ * @param return_status: The return value of the command.
+ * @result Whether we successfully ended the async spawn. 
+ */
+static bool spawn_async_end(std::auto_ptr<const SpawnInfo> info, std::string* stdout_text = 0, std::string* stderr_text = 0, int* return_status = 0)
 {
   if(stdout_text)
     info->get_stdout(*stdout_text);
@@ -356,7 +360,7 @@ bool spawn_async_end(std::auto_ptr<const SpawnInfo> info, std::string* stdout_te
   return !info->is_running();
 }
 
-int spawn_sync(const Glib::ustring& command_line, std::string* stdout_text, std::string* stderr_text)
+static int spawn_sync(const Glib::ustring& command_line, std::string* stdout_text, std::string* stderr_text)
 {
   int redirect_flags = 0;
   if(stdout_text)
@@ -375,7 +379,7 @@ int spawn_sync(const Glib::ustring& command_line, std::string* stdout_text, std:
   mainloop->run();
 
   int return_status = 0;
-  bool returned = spawn_async_end(info, stdout_text, stderr_text, &return_status);
+  const bool returned = spawn_async_end(info, stdout_text, stderr_text, &return_status);
   g_assert(returned);
   return return_status;
 }
@@ -409,7 +413,7 @@ bool execute_command_line_and_wait(const std::string& command, const SlotProgres
   if(!returned)
     return false; // User closed the dialog prematurely?
 
-  return (return_status == 0);
+  return (return_status == EXIT_SUCCESS);
 }
 
 bool execute_command_line_and_wait(const std::string& command, const SlotProgress& slot_progress, std::string& output)
@@ -456,7 +460,7 @@ bool execute_command_line_and_wait(const std::string& command, const SlotProgres
       "  error text: " << stderr_text << std::endl;
   }
 
-  return (return_status == 0);
+  return (return_status == EXIT_SUCCESS);
 }
 
 // Callback handlers for execute_command_line_and_wait_until_second_command_returns_success
@@ -518,7 +522,7 @@ namespace
       Glib::setenv("LANGUAGE", stored_env_language, true /* overwrite */);
     }
 
-    if(return_status == 0)
+    if(return_status == EXIT_SUCCESS)
     {
       bool success = true; //Just check the return code.
       if(!success_text.empty()) //Check the output too.
@@ -597,10 +601,10 @@ bool execute_command_line_and_wait_until_second_command_returns_success(const st
   watch_conn.disconnect();
 
   std::string stderr_text;
-
-  const bool success = Impl::spawn_async_end(info, 0, &stderr_text, 0);
-
-  if(success) //response == Gtk::RESPONSE_OK)
+  int return_status = 0;
+  const bool success = Impl::spawn_async_end(info, 0, &stderr_text, &return_status);
+  
+  if(success && (return_status == EXIT_SUCCESS))
   {
     /* Don't sleep here. Instead we just keep trying to connect until it succeeds, 
      * timing out during that if necessary.



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