+ if (valgrind_is_caller())
+ {
+ dream(5, 50000);
+ }
+
+ size_t repeat= 5;
+ _app.slurp();
+ while (--repeat)
+ {
+ if (pid_file().empty() == false)
+ {
+ Wait wait(pid_file(), 8);
+
+ if (wait.successful() == false)
+ {
+ if (_app.check())
+ {
+ _app.slurp();
+ continue;
+ }
+
+ char buf[PATH_MAX];
+ char *getcwd_buf= getcwd(buf, sizeof(buf));
+ throw libtest::start(LIBYATL_DEFAULT_PARAM,
+ hostname(), port(),
+ "Unable to open pidfile in %s for: %s stderr:%s",
+ getcwd_buf ? getcwd_buf : "",
+ _running.c_str(),
+ _app.stderr_c_str());
+ }
+ }
+ }
+
+ uint32_t this_wait= 0;
+ bool pinged= false;
+ {
+ uint32_t timeout= 20; // This number should be high enough for valgrind startup (which is slow)
+ uint32_t waited;
+ uint32_t retry;
+
+ for (waited= 0, retry= 4; ; retry++, waited+= this_wait)
+ {
+ if ((pinged= ping()) == true)
+ {
+ break;
+ }
+ else if (waited >= timeout)
+ {
+ break;
+ }
+
+ this_wait= retry * retry / 3 + 1;
+ libtest::dream(this_wait, 0);
+ }
+ }
+
+ if (pinged == false)
+ {
+ // If we happen to have a pid file, lets try to kill it
+ if ((pid_file().empty() == false) and (access(pid_file().c_str(), R_OK) == 0))
+ {
+ _app.slurp();
+ if (kill_file(pid_file()) == false)
+ {
+ throw libtest::start(LIBYATL_DEFAULT_PARAM,
+ hostname(), port(),
+ "Failed to kill off server, waited: %u after startup occurred, when pinging failed: %.*s stderr:%.*s",
+ this_wait,
+ int(_running.size()), _running.c_str(),
+ int(_app.stderr_result_length()), _app.stderr_c_str());
+ }
+ else
+ {
+ throw libtest::start(LIBYATL_DEFAULT_PARAM,
+ hostname(), port(),
+ "Failed native ping(), pid: %d was alive: %s waited: %u server started, having pid_file. exec: %.*s stderr:%.*s",
+ int(_app.pid()),
+ _app.check() ? "true" : "false",
+ this_wait,
+ int(_running.size()), _running.c_str(),
+ int(_app.stderr_result_length()), _app.stderr_c_str());
+ }
+ }
+ else
+ {
+ throw libtest::start(LIBYATL_DEFAULT_PARAM,
+ hostname(), port(),
+ "Failed native ping(), pid: %d is alive: %s waited: %u server started. exec: %.*s stderr:%.*s",
+ int(_app.pid()),
+ _app.check() ? "true" : "false",
+ this_wait,
+ int(_running.size()), _running.c_str(),
+ int(_app.stderr_result_length()), _app.stderr_c_str());
+ }
+ _running.clear();
+
+ return false;
+ }