X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libtest%2Fcmdline.cc;h=3a61e4cf267720ad090f4c7d9da8000933be2724;hb=e23d774aaee5cf66ff4dc563f5b0a2cad293dd82;hp=ce98acb16fba7ab884d8fe71a0042e6637fbd6b8;hpb=6b04196d0ea6aa9fcd2a6c14a6cb5733c34aa2d2;p=awesomized%2Flibmemcached diff --git a/libtest/cmdline.cc b/libtest/cmdline.cc index ce98acb1..3a61e4cf 100644 --- a/libtest/cmdline.cc +++ b/libtest/cmdline.cc @@ -34,8 +34,9 @@ * */ -#include -#include +#include "libtest/yatlcon.h" + +#include "libtest/common.h" using namespace libtest; @@ -45,6 +46,12 @@ using namespace libtest; #include #include #include +#ifdef HAVE_POLL_H +# include +#endif +#ifdef HAVE_SPAWN_H +# include +#endif #include #include #include @@ -68,8 +75,8 @@ namespace { std::stringstream arg_buffer; for (vchar_ptr_t::iterator iter= built_argv.begin(); - iter == built_argv.end(); - iter++) + iter != built_argv.end(); + ++iter) { arg_buffer << *iter << " "; } @@ -402,7 +409,6 @@ bool Application::slurp() Application::error_t Application::join() { pid_t waited_pid= waitpid(_pid, &_status, 0); - if (waited_pid == _pid and WIFEXITED(_status) == false) { /* @@ -420,9 +426,8 @@ Application::error_t Application::join() error_string+= built_argv[0]; throw std::logic_error(error_string); } - else if WIFSIGNALED(_status) + else if (WIFSIGNALED(_status)) { - // memcached will die with SIGHUP if (WTERMSIG(_status) != SIGTERM and WTERMSIG(_status) != SIGHUP) { _app_exit_state= Application::INVALID_POSIX_SPAWN; @@ -432,10 +437,15 @@ Application::error_t Application::join() throw std::runtime_error(error_string); } - _app_exit_state= Application::SIGTERM_KILLED; - Out << "waitpid() application terminated at request" - << " pid:" << _pid - << " name:" << built_argv[0]; + // If we terminted it on purpose then it counts as a success. +#if defined(DEBUG) + if (DEBUG) + { + Out << "waitpid() application terminated at request" + << " pid:" << _pid + << " name:" << built_argv[0]; + } +#endif } else { @@ -510,9 +520,10 @@ bool Application::Pipe::read(libtest::vchar_t& arg) bool data_was_read= false; + libtest::vchar_t buffer; + buffer.resize(1024); ssize_t read_length; - char buffer[1024]= { 0 }; - while ((read_length= ::read(_pipe_fd[READ], buffer, sizeof(buffer)))) + while ((read_length= ::read(_pipe_fd[READ], &buffer[0], buffer.size()))) { if (read_length == -1) { @@ -699,10 +710,11 @@ void Application::create_argv(const char *args[]) built_argv.push_back(strdup("--free-fill=DE")); std::string log_file= create_tmpfile("valgrind"); - char buffer[1024]; - int length= snprintf(buffer, sizeof(buffer), "--log-file=%s", log_file.c_str()); - fatal_assert(length > 0 and size_t(length) < sizeof(buffer)); - built_argv.push_back(strdup(buffer)); + libtest::vchar_t buffer; + buffer.resize(1024); + int length= snprintf(&buffer[0], buffer.size(), "--log-file=%s", log_file.c_str()); + fatal_assert(length > 0 and size_t(length) < buffer.size()); + built_argv.push_back(strdup(&buffer[0])); } else if (_use_ptrcheck) { @@ -713,10 +725,11 @@ void Application::create_argv(const char *args[]) built_argv.push_back(strdup("--error-exitcode=1")); built_argv.push_back(strdup("--tool=exp-ptrcheck")); std::string log_file= create_tmpfile("ptrcheck"); - char buffer[1024]; - int length= snprintf(buffer, sizeof(buffer), "--log-file=%s", log_file.c_str()); - fatal_assert(length > 0 and size_t(length) < sizeof(buffer)); - built_argv.push_back(strdup(buffer)); + libtest::vchar_t buffer; + buffer.resize(1024); + int length= snprintf(&buffer[0], buffer.size(), "--log-file=%s", log_file.c_str()); + fatal_assert(length > 0 and size_t(length) < buffer.size()); + built_argv.push_back(strdup(&buffer[0])); } else if (_use_gdb) { @@ -768,7 +781,10 @@ struct DeleteFromVector template void operator() ( T* ptr) const { - free(ptr); + if (ptr) + { + free(ptr); + } } };