WIP
[m6w6/libmemcached] / test / lib / Server.cpp
index 2744f3e1b9c1876b895cb056d6905518cfb534c4..cf520094029949cb94b0ac7d9d61087858370f04 100644 (file)
@@ -3,7 +3,9 @@
 #include "ForkAndExec.hpp"
 
 #include <sys/wait.h>
-#include <unistd.h>
+#if HAVE_UNISTD_H
+#  include <unistd.h>
+#endif
 
 Server::Server(string binary_, Server::argv_t args_)
     : binary{move(binary_)}
@@ -117,7 +119,7 @@ optional<Server::ChildProc> Server::start() {
   return ChildProc{pid, pipe};
 }
 
-bool Server::isListening() {
+bool Server::isListening() const {
   MemcachedPtr memc;
 
   if (holds_alternative<string>(socket_or_port)) {
@@ -149,11 +151,16 @@ bool Server::isListening() {
 }
 
 bool Server::ensureListening() {
+  if (!start()) {
+    return false;
+  }
   return Retry{[this] {
     again:
     start();
     if (!isListening()) {
-      if (tryWait()){
+      auto old = pid;
+      if (tryWait()) {
+        cerr << "Collected zombie " << *this << "(old pid=" << old << ")\n";
         goto again;
       }
     }
@@ -186,7 +193,8 @@ bool Server::check() {
 
 bool Server::wait(int flags) {
   if (pid && pid == waitpid(pid, &status, flags)) {
-    if (drain().length() && output != "Signal handled: Terminated.\n") {
+    if (drain().length() &&
+        output.rfind("Signal handled: Terminated", 0) != 0) {
       cerr << "Output of " << *this << ":\n";
 
       istringstream iss{output};