Valgrind returns a different error for invalid binary.
[m6w6/libmemcached] / libtest / server.cc
index c29d8c4338b9a4c3ed2f565526611827d9a8010e..e554039a1c523d8dea88c4c869f89f067af85ed8 100644 (file)
@@ -70,7 +70,6 @@ std::ostream& operator<<(std::ostream& output, const Server &arg)
     output << " Exec:" <<  arg.running();
   }
 
-
   return output;  // for multiple << operators
 }
 
@@ -138,7 +137,20 @@ bool Server::start()
     fatal_message("has_pid() failed, programer error");
   }
 
-  Application app(name(), is_libtool());
+  Application app(executable(), is_libtool());
+
+  if (is_debug())
+  {
+    app.use_gdb();
+  }
+  else if (getenv("TESTS_ENVIRONMENT"))
+  {
+    if (strstr(getenv("TESTS_ENVIRONMENT"), "gdb"))
+    {
+      app.use_gdb();
+    }
+  }
+
   if (args(app) == false)
   {
     Error << "Could not build command()";
@@ -151,10 +163,11 @@ bool Server::start()
     Error << "Application::run() " << ret;
     return false;
   }
+  _running= app.print();
 
   if (Application::SUCCESS !=  (ret= app.wait()))
   {
-    Error << "Application::wait() " << ret;
+    Error << "Application::wait() " << app.print() << " " << ret;
     return false;
   }
 
@@ -186,10 +199,16 @@ bool Server::start()
     // If we happen to have a pid file, lets try to kill it
     if (pid_file().empty() == false)
     {
-      Error << "We are going to kill it off";
-      kill_file(pid_file());
+      if (kill_file(pid_file()) == false)
+      {
+        fatal_message("Failed to kill off server after startup occurred, when pinging failed");
+      }
+      Error << "Failed to ping() server started, having pid_file. exec:" << _running;
+    }
+    else
+    {
+      Error << "Failed to ping() server started. exec:" << _running;
     }
-    Error << "Failed to ping() server started with:" << _running;
     _running.clear();
     return false;
   }
@@ -287,8 +306,7 @@ bool Server::set_log_file()
   int fd;
   if ((fd= mkstemp(file_buffer)) == -1)
   {
-    perror(file_buffer);
-    return false;
+    libtest::fatal(LIBYATL_DEFAULT_PARAM, "mkstemp() failed on %s with %s", file_buffer, strerror(errno));
   }
   close(fd);
 
@@ -301,13 +319,9 @@ bool Server::args(Application& app)
 {
 
   // Set a log file if it was requested (and we can)
-  if (getenv("LIBTEST_LOG") and has_log_file_option())
+  if (has_log_file_option())
   {
-    if (not set_log_file())
-    {
-      return false;
-    }
-
+    set_log_file();
     log_file_option(app, _log_file);
   }
 
@@ -332,9 +346,9 @@ bool Server::args(Application& app)
     app.add_option(daemon_file_option());
   }
 
-  if (_is_socket and has_socket_file_option())
+  if (has_socket_file_option())
   {
-    if (not set_socket_file())
+    if (set_socket_file() == false)
     {
       return false;
     }