From 371f1dca550e93a0a9bdc960bac3db3d4112ffb4 Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Mon, 19 Nov 2007 17:19:09 -0800 Subject: [PATCH] Added memerror so that I can find out what an error code is without resorting to reading the source :) --- ChangeLog | 2 + docs/Makefile.am | 5 +++ docs/libmemcached.pod | 2 +- docs/memerror.pod | 30 ++++++++++++++ src/Makefile.am | 5 ++- src/memerror.c | 79 ++++++++++++++++++++++++++++++++++++ support/libmemcached.spec.in | 2 + 7 files changed, 123 insertions(+), 2 deletions(-) create mode 100755 docs/memerror.pod create mode 100644 src/memerror.c diff --git a/ChangeLog b/ChangeLog index ac498778..b880e29d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,8 @@ multiple DNS lookups. * Added CAS support, though this is optional and must be enabled during runtime. + * Added the utility memerror to create human readable error strings + from memcached errors (aka convert ints to strings) 0.9 Thu Nov 15 07:44:00 PST 2007 * fix for when no servers are definied. diff --git a/docs/Makefile.am b/docs/Makefile.am index 378a8819..767065d4 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -4,6 +4,7 @@ EXTRA_DIST = libmemcached.pod\ memcached_flush.pod\ memcached_stats.pod\ memrm.pod\ + memerror.pod\ libmemcached_examples.pod\ memcached_get.pod\ memcached_strerror.pod\ @@ -26,6 +27,7 @@ man_MANS = libmemcached.3\ libmemcached_examples.3\ memcat.1\ memcp.1\ + memerror.1\ memflush.1\ memrm.1\ memslap.1\ @@ -217,6 +219,9 @@ memstat.1: memstat.pod memrm.1: memrm.pod pod2man -c "libmemcached" -r "" -s 1 memrm.pod > memrm.1 +memerror.1: memerror.pod + pod2man -c "libmemcached" -r "" -s 1 memerror.pod > memerror.1 + memflush.1: memflush.pod pod2man -c "libmemcached" -r "" -s 1 memflush.pod > memflush.1 diff --git a/docs/libmemcached.pod b/docs/libmemcached.pod index 02bd04e0..9685e01e 100755 --- a/docs/libmemcached.pod +++ b/docs/libmemcached.pod @@ -62,6 +62,6 @@ Brian Aker, Ebrian@tangent.orgE =head1 SEE ALSO -memcached(1) libmemcached_examples(3) libmemcached(1) memcat(1) memcp(1) memflush(1) memrm(1) memslap(1) memstat(1) memcached_fetch(3) memcached_replace(3) memcached_server_list_free(3) libmemcached_examples(3) memcached_clone(3) memcached_free(3) memcached_server_add(3) memcached_server_push(3) memcached_add(3) memcached_get(3) memcached_server_count(3) memcached_servers_parse(3) memcached_create(3) memcached_increment(3) memcached_server_list(3) memcached_set(3) memcached_decrement(3) memcached_mget(3) memcached_server_list_append(3) memcached_strerror(3) memcached_delete(3) memcached_quit(3) memcached_server_list_count(3) memcached_verbosity(3) memcached_server_add_unix_socket(3) memcahed_result_create(3) memcached_result_free(3) memcached_result_key_value(3) memcached_result_key_length(3) memcached_result_value(3) memcached_result_length(3) memcached_result_flags(3) memcached_result_cas(3) memcached_result_st(3) memcached_append(3) memcached_prepend(3) memcached_fetch_result(3) +memcached(1) libmemcached_examples(3) libmemcached(1) memcat(1) memcp(1) memflush(1) memrm(1) memslap(1) memstat(1) memcached_fetch(3) memcached_replace(3) memcached_server_list_free(3) libmemcached_examples(3) memcached_clone(3) memcached_free(3) memcached_server_add(3) memcached_server_push(3) memcached_add(3) memcached_get(3) memcached_server_count(3) memcached_servers_parse(3) memcached_create(3) memcached_increment(3) memcached_server_list(3) memcached_set(3) memcached_decrement(3) memcached_mget(3) memcached_server_list_append(3) memcached_strerror(3) memcached_delete(3) memcached_quit(3) memcached_server_list_count(3) memcached_verbosity(3) memcached_server_add_unix_socket(3) memcahed_result_create(3) memcached_result_free(3) memcached_result_key_value(3) memcached_result_key_length(3) memcached_result_value(3) memcached_result_length(3) memcached_result_flags(3) memcached_result_cas(3) memcached_result_st(3) memcached_append(3) memcached_prepend(3) memcached_fetch_result(3) memerror(1) =cut diff --git a/docs/memerror.pod b/docs/memerror.pod new file mode 100755 index 00000000..9dc2e0ce --- /dev/null +++ b/docs/memerror.pod @@ -0,0 +1,30 @@ +=head1 NAME + +memerror - Translate a memcached error code to a string + +=head1 SYNOPSIS + + memerror [options] error_code + +=head1 DESCRIPTION + +B translate an error code from libmemcached(3) to a human +readable string. + +For a full list of operations run the tool with the B<--help> option. + +=head1 HOME + +To find out more infoerroration please check: +L + +=head1 AUTHOR + +Brian Aker, Ebrian@tangent.orgE + +=head1 SEE ALSO + +memcached(1) libmemcached(3) + +=cut + diff --git a/src/Makefile.am b/src/Makefile.am index 435376bd..0bf6ec87 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,7 +1,7 @@ INCLUDES = -I$(top_builddir)/include LDADDS = ../lib/libmemcached.la -bin_PROGRAMS = memcat memcp memstat memrm memflush memslap +bin_PROGRAMS = memcat memcp memstat memrm memflush memslap memerror noinst_HEADERS = client_options.h \ utilities.h \ @@ -23,5 +23,8 @@ memrm_LDADD = $(LDADDS) memflush_SOURCES = memflush.c utilities.c memflush_LDADD = $(LDADDS) +memerror_SOURCES = memerror.c utilities.c +memerror_LDADD = $(LDADDS) + memslap_SOURCES = memslap.c utilities.c generator.c execute.c memslap_LDADD = $(LDADDS) -lpthread diff --git a/src/memerror.c b/src/memerror.c new file mode 100644 index 00000000..d6bfbf7f --- /dev/null +++ b/src/memerror.c @@ -0,0 +1,79 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "utilities.h" + +#define PROGRAM_NAME "memerror" +#define PROGRAM_DESCRIPTION "Translate a memcached errror code into a string." + + +/* Prototypes */ +void options_parse(int argc, char *argv[]); + +static int opt_verbose= 0; + +int main(int argc, char *argv[]) +{ + options_parse(argc, argv); + + if (argc != 2) + return 1; + + printf("%s\n", memcached_strerror(NULL, atoi(argv[1]))); + + return 0; +} + + +void options_parse(int argc, char *argv[]) +{ + int option_index= 0; + int option_rv; + + memcached_programs_help_st help_options[]= + { + {0}, + }; + + static struct option long_options[]= + { + {"version", no_argument, NULL, OPT_VERSION}, + {"help", no_argument, NULL, OPT_HELP}, + {"verbose", no_argument, &opt_verbose, OPT_VERBOSE}, + {"debug", no_argument, &opt_verbose, OPT_DEBUG}, + {0, 0, 0, 0}, + }; + + while (1) + { + option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index); + if (option_rv == -1) break; + switch (option_rv) + { + case 0: + break; + case OPT_VERBOSE: /* --verbose or -v */ + opt_verbose = OPT_VERBOSE; + break; + case OPT_DEBUG: /* --debug or -d */ + opt_verbose = OPT_DEBUG; + break; + case OPT_VERSION: /* --version or -V */ + version_command(PROGRAM_NAME); + break; + case OPT_HELP: /* --help or -h */ + help_command(PROGRAM_NAME, PROGRAM_DESCRIPTION, long_options, help_options); + break; + case '?': + /* getopt_long already printed an error message. */ + exit(1); + default: + abort(); + } + } +} diff --git a/support/libmemcached.spec.in b/support/libmemcached.spec.in index d2eef19c..8e6b1aa7 100644 --- a/support/libmemcached.spec.in +++ b/support/libmemcached.spec.in @@ -24,6 +24,7 @@ memrm - Remove a key(s) from the serrver. memstat - Dump the stats of your servers to standard output. memslap - Generate testing loads on a memcached cluster. memcp - Copy files to memcached servers. +memerror - Creates human readable messages from libmemecached error codes. %prep %setup -q @@ -43,6 +44,7 @@ memcp - Copy files to memcached servers. %files %{_bindir}/memcat %{_bindir}/memcp +%{_bindir}/memerror %{_bindir}/memflush %{_bindir}/memrm %{_bindir}/memstat -- 2.30.2