Updated Version status. Updated all command line tools to return error
[awesomized/libmemcached] / src / memrm.c
index b8d07ba4afa6d92a0f23947068fc0b267415177c..7b774d72d8122ae20041caf5dbe8a95b35266ba7 100644 (file)
@@ -2,12 +2,14 @@
 #include <unistd.h>
 #include <getopt.h>
 #include <memcached.h>
+#include <string.h>
 #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);