X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=clients%2Fmemstat.cc;h=ae6a356584c35007b5c07c5c3febfac4318c3beb;hb=38d8a23b191882419106665e8988f8f5b5532fe2;hp=88221cf38ede6f9ca09e80c1130dab923e22cf86;hpb=906d0558357bdd81dec000c71c165646af8c6e5f;p=awesomized%2Flibmemcached diff --git a/clients/memstat.cc b/clients/memstat.cc index 88221cf3..ae6a3565 100644 --- a/clients/memstat.cc +++ b/clients/memstat.cc @@ -1,4 +1,5 @@ /* LibMemcached + * Copyright (C) 2011-2012 Data Differential, http://datadifferential.com/ * Copyright (C) 2006-2009 Brian Aker * All rights reserved. * @@ -11,7 +12,7 @@ * Brian Aker * Toru Maesaka */ -#include +#include #include #include @@ -25,7 +26,7 @@ #include #include -#include +#include #include "client_options.h" #include "utilities.h" @@ -46,6 +47,8 @@ static bool opt_analyze= false; static char *opt_servers= NULL; static char *stat_args= NULL; static char *analyze_mode= NULL; +static char *opt_username; +static char *opt_passwd; static struct option long_options[]= { @@ -59,6 +62,8 @@ static struct option long_options[]= {(OPTIONSTRING)"server-version", no_argument, NULL, OPT_SERVER_VERSION}, {(OPTIONSTRING)"servers", required_argument, NULL, OPT_SERVERS}, {(OPTIONSTRING)"analyze", optional_argument, NULL, OPT_ANALYZE}, + {(OPTIONSTRING)"username", required_argument, NULL, OPT_USERNAME}, + {(OPTIONSTRING)"password", required_argument, NULL, OPT_PASSWD}, {0, 0, 0, 0}, }; @@ -84,13 +89,13 @@ static memcached_return_t stat_printer(memcached_server_instance_st instance, } static memcached_return_t server_print_callback(const memcached_st *, - const memcached_server_st *instance, + memcached_server_instance_st instance, void *) { std::cerr << memcached_server_name(instance) << ":" << memcached_server_port(instance) << - " " << int(instance->major_version) << - "." << int(instance->minor_version) << - "." << int(instance->micro_version) << std::endl; + " " << int(memcached_server_major_version(instance)) << + "." << int(memcached_server_minor_version(instance)) << + "." << int(memcached_server_micro_version(instance)) << std::endl; return MEMCACHED_SUCCESS; } @@ -123,6 +128,24 @@ int main(int argc, char *argv[]) memcached_return_t rc= memcached_server_push(memc, servers); memcached_server_list_free(servers); + if (opt_username and LIBMEMCACHED_WITH_SASL_SUPPORT == 0) + { + memcached_free(memc); + std::cerr << "--username was supplied, but binary was not built with SASL support." << std::endl; + return EXIT_FAILURE; + } + + if (opt_username) + { + memcached_return_t ret; + if (memcached_failed(ret= memcached_set_sasl_auth_data(memc, opt_username, opt_passwd))) + { + std::cerr << memcached_last_error_message(memc) << std::endl; + memcached_free(memc); + return EXIT_FAILURE; + } + } + if (rc != MEMCACHED_SUCCESS and rc != MEMCACHED_SOME_ERRORS) { printf("Failure to communicate with servers (%s)\n", @@ -393,6 +416,15 @@ static void options_parse(int argc, char *argv[]) close_stdio(); break; + case OPT_USERNAME: + opt_username= optarg; + opt_binary= true; + break; + + case OPT_PASSWD: + opt_passwd= optarg; + break; + case '?': /* getopt_long already printed an error message. */ exit(1);