From 9d762a9c58fd0cfdd529002bf2b0ab6b2aaea2c3 Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Fri, 19 Apr 2013 22:43:10 -0700 Subject: [PATCH] Additional fixes from Debian. --- libtest/cmdline.cc | 26 +++++++++++---------- libtest/cmdline.h | 3 --- libtest/has.cc | 54 ++++++++++++++++++++++++++++++++++++++++---- libtest/has.hpp | 10 +++++++- libtest/memcached.cc | 10 ++++---- 5 files changed, 78 insertions(+), 25 deletions(-) diff --git a/libtest/cmdline.cc b/libtest/cmdline.cc index 0553fdde..1423eca6 100644 --- a/libtest/cmdline.cc +++ b/libtest/cmdline.cc @@ -2,7 +2,7 @@ * * Data Differential YATL (i.e. libtest) library * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ + * Copyright (C) 2012-2013 Data Differential, http://datadifferential.com/ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -481,8 +481,20 @@ Application::error_t Application::join() } else if (waited_pid == -1) { + std::string error_string + if (stdout_result_length()) + { + error_string+= " stdout: "; + error_string+= stdout_c_str(); + } + + if (stderr_result_length()) + { + error_string+= " stderr: "; + error_string+= stderr_c_str(); + } + Error << "waitpid() returned errno:" << strerror(errno) << " " << error_string; _app_exit_state= Application::UNKNOWN; - Error << "waitpid() returned errno:" << strerror(errno); } else { @@ -818,14 +830,4 @@ int exec_cmdline(const std::string& command, const char *args[], bool use_libtoo return int(app.join()); } -const char *gearmand_binary() -{ - return GEARMAND_BINARY; -} - -const char *drizzled_binary() -{ - return DRIZZLED_BINARY; -} - } // namespace exec_cmdline diff --git a/libtest/cmdline.h b/libtest/cmdline.h index 6bf71b64..368daaec 100644 --- a/libtest/cmdline.h +++ b/libtest/cmdline.h @@ -245,7 +245,4 @@ static inline std::ostream& operator<<(std::ostream& output, const enum Applicat int exec_cmdline(const std::string& executable, const char *args[], bool use_libtool= false); -const char *gearmand_binary(); -const char *drizzled_binary(); - } diff --git a/libtest/has.cc b/libtest/has.cc index 9b26b96b..a7a09cb4 100644 --- a/libtest/has.cc +++ b/libtest/has.cc @@ -2,7 +2,7 @@ * * Data Differential YATL (i.e. libtest) library * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ + * Copyright (C) 2012-2013 Data Differential, http://datadifferential.com/ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -37,6 +37,7 @@ #include "libtest/yatlcon.h" #include +#include #include #include @@ -138,14 +139,17 @@ bool has_mysqld() return false; } -bool has_memcached() +static char memcached_binary_path[FILENAME_MAX]; + +static void initialize_curl_startup() { + memcached_binary_path[0]= NULL; + #if defined(HAVE_MEMCACHED_BINARY) && HAVE_MEMCACHED_BINARY if (HAVE_MEMCACHED_BINARY) { std::stringstream arg_buffer; - char *getenv_ptr; if (bool((getenv_ptr= getenv("PWD"))) and strcmp(MEMCACHED_BINARY, "memcached/memcached") == 0) { @@ -156,14 +160,46 @@ bool has_memcached() if (access(arg_buffer.str().c_str(), X_OK) == 0) { - return true; + strncpy(memcached_binary_path, arg_buffer.str().c_str(), FILENAME_MAX); } } #endif +} + +static pthread_once_t memcached_binary_once= PTHREAD_ONCE_INIT; +static void initialize_memcached_binary(void) +{ + int ret; + if ((ret= pthread_once(&memcached_binary_once, initialize_curl_startup)) != 0) + { + FATAL(strerror(ret)); + } +} + +bool has_memcached() +{ + initialize_memcached_binary(); + + if (memcached_binary_path[0]) + { + return true; + } return false; } +const char* memcached_binary() +{ + initialize_memcached_binary(); + + if (memcached_binary_path[0]) + { + return memcached_binary_path; + } + + return NULL; +} + bool has_memcached_sasl() { #if defined(HAVE_MEMCACHED_SASL_BINARY) && HAVE_MEMCACHED_SASL_BINARY @@ -179,4 +215,14 @@ bool has_memcached_sasl() return false; } +const char *gearmand_binary() +{ + return GEARMAND_BINARY; +} + +const char *drizzled_binary() +{ + return DRIZZLED_BINARY; +} + } // namespace libtest diff --git a/libtest/has.hpp b/libtest/has.hpp index e6c9d4d5..f38306d5 100644 --- a/libtest/has.hpp +++ b/libtest/has.hpp @@ -2,7 +2,7 @@ * * Data Differential YATL (i.e. libtest) library * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ + * Copyright (C) 2012-2013 Data Differential, http://datadifferential.com/ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -62,4 +62,12 @@ bool has_drizzled(); LIBTEST_API bool has_mysqld(); +LIBTEST_API +const char* memcached_binary(); + +LIBTEST_API +const char *gearmand_binary(); + +LIBTEST_API +const char *drizzled_binary(); } // namespace libtest diff --git a/libtest/memcached.cc b/libtest/memcached.cc index 24bc3b8d..15fcbffa 100644 --- a/libtest/memcached.cc +++ b/libtest/memcached.cc @@ -72,14 +72,14 @@ public: const std::string& username_arg, const std::string& password_arg) : libtest::Server(host_arg, port_arg, - MEMCACHED_BINARY, false, is_socket_arg), + memcached_binary(), false, is_socket_arg), _username(username_arg), _password(password_arg) { } Memcached(const std::string& host_arg, const in_port_t port_arg, const bool is_socket_arg) : libtest::Server(host_arg, port_arg, - MEMCACHED_BINARY, false, is_socket_arg) + memcached_binary(), false, is_socket_arg) { set_pid_file(); } @@ -131,7 +131,7 @@ public: const char *executable() { - return MEMCACHED_BINARY; + return memcached_binary(); } bool is_libtool() @@ -218,7 +218,7 @@ bool Memcached::build() libtest::Server *build_memcached(const std::string& hostname, const in_port_t try_port) { - if (HAVE_MEMCACHED_BINARY) + if (has_memcached()) { return new Memcached(hostname, try_port, false); } @@ -228,7 +228,7 @@ libtest::Server *build_memcached(const std::string& hostname, const in_port_t tr libtest::Server *build_memcached_socket(const std::string& socket_file, const in_port_t try_port) { - if (HAVE_MEMCACHED_BINARY) + if (has_memcached()) { return new Memcached(socket_file, try_port, true); } -- 2.30.2