X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libtest%2Fserver.cc;h=01d15625bf043e2712dccf8658899c40aafa8b53;hb=3bb738d74511398cbe598b1a177a39bc93d8c84e;hp=78b729f96cb473faeeef973e325865cb0a28689f;hpb=cf55f693c7fc7693afbb4594d97d23795cf7f2a0;p=m6w6%2Flibmemcached diff --git a/libtest/server.cc b/libtest/server.cc index 78b729f9..01d15625 100644 --- a/libtest/server.cc +++ b/libtest/server.cc @@ -34,7 +34,7 @@ * */ -#include +#include "mem_config.h" #include #include @@ -90,6 +90,22 @@ std::ostream& operator<<(std::ostream& output, const Server &arg) return output; // for multiple << operators } +#ifdef __GLIBC__ +namespace { + +class Buffer +{ +public: + Buffer(char *b) : b_(b) {} + ~Buffer() { free(b_); } + char* buf() { return b_; } +private: + char *b_; +}; + +} +#endif // __GLIBC__ + #define MAGIC_MEMORY 123570 Server::Server(const std::string& host_arg, const in_port_t port_arg, @@ -99,12 +115,14 @@ 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) { } Server::~Server() { + kill(); } bool Server::check() @@ -177,6 +195,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(); @@ -186,17 +210,20 @@ bool Server::start() _app.use_valgrind(); } + out_of_ban_killed(false); 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(); @@ -222,26 +249,37 @@ bool Server::start() continue; } +#ifdef __GLIBC__ + Buffer buf( get_current_dir_name()); + char *getcwd_buf= buf.buf(); +#else 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()); +#endif // __GLIBC__ + 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()); } } } - uint32_t this_wait= 0; bool pinged= false; + uint32_t this_wait= 0; { - uint32_t timeout= 20; // This number should be high enough for valgrind startup (which is slow) + uint32_t timeout= 40; // This number should be high enough for valgrind startup (which is slow) uint32_t waited; uint32_t retry; - for (waited= 0, retry= 1; ; retry++, waited+= this_wait) + for (waited= 0, retry= 7; ; retry++, waited+= this_wait) { + if (_app.check() == false) + { + break; + } + if ((pinged= ping()) == true) { break; @@ -251,6 +289,8 @@ bool Server::start() break; } + Error << "ping(" << _app.pid() << ") wait: " << this_wait << " " << hostname() << ":" << port() << " " << error(); + this_wait= retry * retry / 3 + 1; libtest::dream(this_wait, 0); } @@ -264,32 +304,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; } @@ -312,9 +358,9 @@ void Server::add_option(const std::string& arg) _options.push_back(std::make_pair(arg, std::string())); } -void Server::add_option(const std::string& name, const std::string& value) +void Server::add_option(const std::string& name_, const std::string& value_) { - _options.push_back(std::make_pair(name, value)); + _options.push_back(std::make_pair(name_, value_)); } bool Server::set_socket_file() @@ -430,7 +476,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) {