X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=src%2Fmemrm.c;h=7b774d72d8122ae20041caf5dbe8a95b35266ba7;hb=9e3bf9c2657ea5f32009636394c22530b789ffb2;hp=b8d07ba4afa6d92a0f23947068fc0b267415177c;hpb=735295f0989edbd884a2c3935d1219a59ebe5698;p=awesomized%2Flibmemcached diff --git a/src/memrm.c b/src/memrm.c index b8d07ba4..7b774d72 100644 --- a/src/memrm.c +++ b/src/memrm.c @@ -2,12 +2,14 @@ #include #include #include +#include #include "client_options.h" #include "utilities.h" static int opt_verbose= 0; static time_t opt_expire= 0; static char *opt_servers= NULL; +static char *opt_hash= NULL; #define PROGRAM_NAME "memrm" #define PROGRAM_DESCRIPTION "Erase a key or set of keys from a memcached cluster." @@ -30,10 +32,14 @@ int main(int argc, char *argv[]) if ((temp= getenv("MEMCACHED_SERVERS"))) opt_servers= strdup(temp); else + { + fprintf(stderr, "No Servers provided\n"); exit(1); + } } memc= memcached_create(NULL); + process_hash_option(memc, opt_hash); servers= memcached_servers_parse(opt_servers); memcached_server_push(memc, servers); @@ -47,8 +53,11 @@ int main(int argc, char *argv[]) if (rc != MEMCACHED_SUCCESS) { - fprintf(stderr, "memrm: %s: memcache error %s\n", + fprintf(stderr, "memrm: %s: memcache error %s", argv[optind], memcached_strerror(memc, rc)); + if (memc->cached_errno) + fprintf(stderr, " system error %s", strerror(memc->cached_errno)); + fprintf(stderr, "\n"); } optind++; @@ -56,7 +65,10 @@ int main(int argc, char *argv[]) memcached_free(memc); - free(opt_servers); + if (opt_servers) + free(opt_servers); + if (opt_hash) + free(opt_hash); return 0; } @@ -77,6 +89,7 @@ void options_parse(int argc, char *argv[]) {"debug", no_argument, &opt_verbose, OPT_DEBUG}, {"servers", required_argument, NULL, OPT_SERVERS}, {"expire", required_argument, NULL, OPT_EXPIRE}, + {"hash", required_argument, NULL, OPT_HASH}, {0, 0, 0, 0}, }; int option_index= 0; @@ -108,6 +121,9 @@ void options_parse(int argc, char *argv[]) case OPT_EXPIRE: /* --expire */ opt_expire= (time_t)strtoll(optarg, (char **)NULL, 10); break; + case OPT_HASH: + opt_hash= strdup(optarg); + break; case '?': /* getopt_long already printed an error message. */ exit(1);