#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_)}
return ChildProc{pid, pipe};
}
-bool Server::isListening() {
+bool Server::isListening() const {
MemcachedPtr memc;
if (holds_alternative<string>(socket_or_port)) {
}
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;
}
}
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};