X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libtest%2Fserver.cc;h=135aa0f0d6cdce97ce722bb956d0af15209c8955;hb=f47caf2833675cce0b62a6e4ffd6764c1490a8b4;hp=68a463b889e9628536f7f1d32439ded4a9110f3b;hpb=9ad3090b40fabae0ccc1b3e156bfc84c4c62d47d;p=m6w6%2Flibmemcached diff --git a/libtest/server.cc b/libtest/server.cc index 68a463b8..135aa0f0 100644 --- a/libtest/server.cc +++ b/libtest/server.cc @@ -99,7 +99,8 @@ Server::Server(const std::string& host_arg, const in_port_t port_arg, _is_socket(is_socket_arg), _port(port_arg), _hostname(host_arg), - _app(executable, _is_libtool) + _app(executable, _is_libtool), + out_of_ban_killed_(false) { } @@ -148,14 +149,9 @@ bool Server::cycle() bool Server::wait_for_pidfile() const { - if (has_pid_file()) - { - Wait wait(pid_file(), 4); - - return wait.successful(); - } + Wait wait(pid_file(), 4); - return true; + return wait.successful(); } bool Server::has_pid() const @@ -182,6 +178,12 @@ bool Server::start() } #endif + if (port() == LIBTEST_FAIL_PORT) + { + throw libtest::disconnected(LIBYATL_DEFAULT_PARAM, + hostname(), port(), "Called failure"); + } + if (getenv("YATL_PTRCHECK_SERVER")) { _app.use_ptrcheck(); @@ -193,15 +195,16 @@ bool Server::start() if (args(_app) == false) { - Error << "Could not build command()"; - return false; + throw libtest::disconnected(LIBYATL_DEFAULT_PARAM, + hostname(), port(), "Could not build command()"); } libtest::release_port(_port); Application::error_t ret; if (Application::SUCCESS != (ret= _app.run())) { - Error << "Application::run() " << ret; + throw libtest::disconnected(LIBYATL_DEFAULT_PARAM, + hostname(), port(), "Application::run() %s", libtest::Application::toString(ret)); return false; } _running= _app.print(); @@ -211,32 +214,30 @@ bool Server::start() dream(5, 50000); } + size_t repeat= 5; _app.slurp(); - if (has_pid_file()) + while (--repeat) { - size_t repeat= 5; - while (--repeat) + if (pid_file().empty() == false) { - if (pid_file().empty() == false) - { - Wait wait(pid_file(), 8); + Wait wait(pid_file(), 8); - if (wait.successful() == false) + if (wait.successful() == false) + { + if (_app.check()) { - if (_app.check()) - { - _app.slurp(); - continue; - } - - char buf[PATH_MAX]; - char *getcwd_buf= getcwd(buf, sizeof(buf)); - throw libtest::fatal(LIBYATL_DEFAULT_PARAM, - "Unable to open pidfile in %s for: %s stderr:%s", - getcwd_buf ? getcwd_buf : "", - _running.c_str(), - _app.stderr_c_str()); + _app.slurp(); + continue; } + + char buf[PATH_MAX]; + char *getcwd_buf= getcwd(buf, sizeof(buf)); + throw libtest::disconnected(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()); } } } @@ -248,7 +249,7 @@ bool Server::start() uint32_t waited; uint32_t retry; - for (waited= 0, retry= 1; ; retry++, waited+= this_wait) + for (waited= 0, retry= 4; ; retry++, waited+= this_wait) { if ((pinged= ping()) == true) { @@ -272,32 +273,38 @@ bool Server::start() _app.slurp(); if (kill_file(pid_file()) == false) { - throw libtest::fatal(LIBYATL_DEFAULT_PARAM, - "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()); + throw libtest::disconnected(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::disconnected(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()); } - - throw libtest::fatal(LIBYATL_DEFAULT_PARAM, - "Failed native ping(), pid: %d is 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::fatal(LIBYATL_DEFAULT_PARAM, - "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()); + throw libtest::disconnected(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; } @@ -414,7 +421,6 @@ bool Server::args(Application& app) } // Update pid_file - if (has_pid_file()) { if (_pid_file.empty() and set_pid_file() == false) { @@ -439,7 +445,7 @@ bool Server::args(Application& app) port_option(app, _port); } - for (Options::const_iterator iter= _options.begin(); iter != _options.end(); iter++) + for (Options::const_iterator iter= _options.begin(); iter != _options.end(); ++iter) { if ((*iter).second.empty() == false) {