X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libtest%2Fserver.cc;h=401218baeb32e1e3a5668f90cd3cdbff6190121e;hb=refs%2Ftags%2Fpre_cmake;hp=a80a181239fb1f7d9ac42b486cac7370a7a5aaa8;hpb=fde9567090d20b035433241720f00cfbe6e66bf2;p=awesomized%2Flibmemcached diff --git a/libtest/server.cc b/libtest/server.cc index a80a1812..401218ba 100644 --- a/libtest/server.cc +++ b/libtest/server.cc @@ -43,6 +43,7 @@ #include #include #include +#include #include #include @@ -98,7 +99,7 @@ class Buffer { public: Buffer(char *b) : b_(b) {} - ~Buffer() { free(b_); } + ~Buffer() { if (b_) free(b_); } char* buf() { return b_; } private: char *b_; @@ -129,9 +130,8 @@ Server::~Server() bool Server::check() { - _app.slurp(); - _app.check(); - return true; + _app.clear(); + return _app.check(); } bool Server::validate() @@ -173,6 +173,22 @@ bool Server::wait_for_pidfile() const return wait.successful(); } +bool Server::init(const char *argv[]) +{ + if (argv) + { + for (const char **ptr= argv; *ptr ; ++ptr) + { + if (ptr) + { + add_option(*ptr); + } + } + } + + return build(); +} + bool Server::has_pid() const { return (_app.pid() > 1); @@ -181,22 +197,11 @@ bool Server::has_pid() const bool Server::start() { - // If we find that we already have a pid then kill it. - if (has_pid() == true) + if (getenv("YATL_GDB_SERVER")) { -#if 0 - fatal_message("has_pid() failed, programer error"); -#endif + _app.use_gdb(true); } - // This needs more work. -#if 0 - if (gdb_is_caller()) - { - _app.use_gdb(); - } -#endif - if (port() == LIBTEST_FAIL_PORT) { throw libtest::disconnected(LIBYATL_DEFAULT_PARAM, @@ -205,11 +210,11 @@ bool Server::start() if (getenv("YATL_PTRCHECK_SERVER")) { - _app.use_ptrcheck(); + _app.use_ptrcheck(true); } else if (getenv("YATL_VALGRIND_SERVER")) { - _app.use_valgrind(); + _app.use_valgrind(true); } out_of_ban_killed(false); @@ -275,7 +280,7 @@ bool Server::start() uint32_t waited; uint32_t retry; - for (waited= 0, retry= 7; ; retry++, waited+= this_wait) + for (waited= 0, retry= 1; ; retry++, waited+= this_wait) { if (_app.check() == false) { @@ -291,8 +296,6 @@ 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); } @@ -300,6 +303,10 @@ bool Server::start() if (pinged == false) { +#if 0 + Error << "Failed to ping(" << _app.pid() << ") wait: " << this_wait << " " << hostname() << ":" << port() << " run:" << _running << " " << error(); +#endif + // 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)) { @@ -483,13 +490,16 @@ bool Server::args(Application& app) for (Options::const_iterator iter= _options.begin(); iter != _options.end(); ++iter) { - if ((*iter).second.empty() == false) + if ((*iter).first.empty() == false) { - app.add_option((*iter).first, (*iter).second); - } - else - { - app.add_option((*iter).first); + if ((*iter).second.empty() == false) + { + app.add_option((*iter).first, (*iter).second); + } + else + { + app.add_option((*iter).first); + } } } @@ -519,4 +529,20 @@ bool Server::kill() return false; } +std::pair Server::output() +{ + _app.slurp(); + return { + std::string { + _app.stdout_result().data(), + _app.stdout_result().size() + }, + std::string { + _app.stderr_result().data(), + _app.stderr_result().size() + } + }; +} + + } // namespace libtest