has.cc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
  2. *
  3. * Data Differential YATL (i.e. libtest) library
  4. *
  5. * Copyright (C) 2012-2013 Data Differential, http://datadifferential.com/
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are
  9. * met:
  10. *
  11. * * Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. *
  14. * * Redistributions in binary form must reproduce the above
  15. * copyright notice, this list of conditions and the following disclaimer
  16. * in the documentation and/or other materials provided with the
  17. * distribution.
  18. *
  19. * * The names of its contributors may not be used to endorse or
  20. * promote products derived from this software without specific prior
  21. * written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  24. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  25. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  26. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  27. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  28. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  29. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  30. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  31. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  32. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. */
  36. #include "libtest/yatlcon.h"
  37. #include <libtest/common.h>
  38. #include <cstdio>
  39. #include <cstdlib>
  40. #include <unistd.h>
  41. namespace libtest {
  42. #pragma GCC diagnostic push
  43. #pragma GCC diagnostic ignored "-Wunreachable-code"
  44. bool has_libmemcached(void)
  45. {
  46. #if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED
  47. if (HAVE_LIBMEMCACHED)
  48. {
  49. return true;
  50. }
  51. #endif
  52. return false;
  53. }
  54. #pragma GCC diagnostic pop
  55. bool has_libdrizzle(void)
  56. {
  57. #if defined(HAVE_LIBDRIZZLE) && HAVE_LIBDRIZZLE
  58. if (HAVE_LIBDRIZZLE)
  59. {
  60. return true;
  61. }
  62. #endif
  63. return false;
  64. }
  65. bool has_postgres_support(void)
  66. {
  67. char *getenv_ptr;
  68. if (bool((getenv_ptr= getenv("POSTGRES_IS_RUNNING_AND_SETUP"))))
  69. {
  70. (void)(getenv_ptr);
  71. if (HAVE_LIBPQ)
  72. {
  73. return true;
  74. }
  75. }
  76. return false;
  77. }
  78. bool has_gearmand()
  79. {
  80. #if defined(GEARMAND_BINARY) && defined(HAVE_GEARMAND_BINARY) && HAVE_GEARMAND_BINARY
  81. if (HAVE_GEARMAND_BINARY)
  82. {
  83. std::stringstream arg_buffer;
  84. char *getenv_ptr;
  85. if (bool((getenv_ptr= getenv("PWD"))) and
  86. ((strcmp(GEARMAND_BINARY, "./gearmand/gearmand") == 0) or (strcmp(GEARMAND_BINARY, "gearmand/gearmand") == 0)))
  87. {
  88. arg_buffer << getenv_ptr;
  89. arg_buffer << "/";
  90. }
  91. arg_buffer << GEARMAND_BINARY;
  92. if (access(arg_buffer.str().c_str(), X_OK) == 0)
  93. {
  94. return true;
  95. }
  96. }
  97. #endif
  98. return false;
  99. }
  100. bool has_drizzled()
  101. {
  102. #if defined(DRIZZLED_BINARY) && defined(HAVE_DRIZZLED_BINARY) && HAVE_DRIZZLED_BINARY && defined(HAVE_LIBMYSQL_BUILD) && HAVE_LIBMYSQL_BUILD
  103. {
  104. if (access(DRIZZLED_BINARY, X_OK) == 0)
  105. {
  106. return true;
  107. }
  108. }
  109. #endif
  110. return false;
  111. }
  112. bool has_mysqld()
  113. {
  114. #if defined(MYSQLD_BINARY) && defined(HAVE_MYSQLD_BUILD) && HAVE_MYSQLD_BUILD && defined(HAVE_LIBMYSQL_BUILD) && HAVE_LIBMYSQL_BUILD
  115. {
  116. if (access(MYSQLD_BINARY, X_OK) == 0)
  117. {
  118. return true;
  119. }
  120. }
  121. #endif
  122. return false;
  123. }
  124. static char memcached_binary_path[FILENAME_MAX +1]= { 0 };
  125. static void initialize_memcached_binary_path()
  126. {
  127. memcached_binary_path[0]= 0;
  128. #if defined(MEMCACHED_BINARY) && defined(HAVE_MEMCACHED_BINARY) && HAVE_MEMCACHED_BINARY
  129. if (HAVE_MEMCACHED_BINARY)
  130. {
  131. std::stringstream arg_buffer;
  132. char *getenv_ptr;
  133. if (bool((getenv_ptr= getenv("PWD"))) and strcmp(MEMCACHED_BINARY, "memcached/memcached") == 0)
  134. {
  135. arg_buffer << getenv_ptr;
  136. arg_buffer << "/";
  137. }
  138. arg_buffer << MEMCACHED_BINARY;
  139. if (access(arg_buffer.str().c_str(), X_OK) == 0)
  140. {
  141. strncpy(memcached_binary_path, arg_buffer.str().c_str(), FILENAME_MAX);
  142. }
  143. }
  144. #endif
  145. }
  146. static pthread_once_t memcached_binary_once= PTHREAD_ONCE_INIT;
  147. static void initialize_memcached_binary(void)
  148. {
  149. int ret;
  150. if ((ret= pthread_once(&memcached_binary_once, initialize_memcached_binary_path)) != 0)
  151. {
  152. FATAL(strerror(ret));
  153. }
  154. }
  155. bool has_memcached()
  156. {
  157. initialize_memcached_binary();
  158. if (memcached_binary_path[0] and (strlen(memcached_binary_path) > 0))
  159. {
  160. return true;
  161. }
  162. return false;
  163. }
  164. const char* memcached_binary()
  165. {
  166. initialize_memcached_binary();
  167. if (memcached_binary_path[0])
  168. {
  169. return memcached_binary_path;
  170. }
  171. return NULL;
  172. }
  173. const char *gearmand_binary()
  174. {
  175. #if defined(GEARMAND_BINARY)
  176. return GEARMAND_BINARY;
  177. #else
  178. return NULL;
  179. #endif
  180. }
  181. const char *drizzled_binary()
  182. {
  183. #if defined(DRIZZLED_BINARY)
  184. return DRIZZLED_BINARY;
  185. #else
  186. return NULL;
  187. #endif
  188. }
  189. } // namespace libtest