From bbc4466149476f043a6eabf6757f97ab42c0f6cd Mon Sep 17 00:00:00 2001 From: Mark Atwood Date: Thu, 20 Sep 2007 13:11:55 -0700 Subject: [PATCH] add error reporting to tools, and link memcached_strerror into library --- lib/Makefile.am | 1 + lib/memcached_strerror.c | 2 +- src/memcat.c | 5 +++++ src/memcp.c | 19 +++++++++++++++---- src/memrm.c | 6 ++++++ 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/lib/Makefile.am b/lib/Makefile.am index 43e4a27f..b9072cf2 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -3,6 +3,7 @@ LIBS = lib_LTLIBRARIES = libmemcached.la libmemcached_la_SOURCES = memcached.c \ + memcached_strerror.c \ memcached_connect.c \ memcached_response.c \ memcached_get.c \ diff --git a/lib/memcached_strerror.c b/lib/memcached_strerror.c index 5c7dadfb..f6d9105e 100644 --- a/lib/memcached_strerror.c +++ b/lib/memcached_strerror.c @@ -1,4 +1,4 @@ -#include +#include char *memcached_strerror(memcached_st *ptr, memcached_return rc) { diff --git a/src/memcat.c b/src/memcat.c index 7789ec9b..ec2fad9b 100644 --- a/src/memcat.c +++ b/src/memcat.c @@ -49,6 +49,11 @@ int main(int argc, char *argv[]) free(string); } } + else + { + fprintf(stderr, "memcat: %s: memcache error %s\n", + argv[argc], memcached_strerror(memc, rc)); + } optind++; } diff --git a/src/memcp.c b/src/memcp.c index 6ae8e3b4..fc396ff1 100644 --- a/src/memcp.c +++ b/src/memcp.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include "client_options.h" @@ -39,15 +40,20 @@ int main(int argc, char *argv[]) char *ptr; fd= open(argv[optind], O_RDONLY); - - if (fd == -1) - { - fprintf(stderr, "Failed opening %s\n", argv[optind]); + if (fd < 0) { + fprintf(stderr, "memcp: %s: %s\n", argv[optind], strerror(errno)); + optind++; continue; } (void)fstat(fd, &sbuf); mptr= mmap(NULL, sbuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + if (mptr == MAP_FAILED) { + fprintf(stderr, "memcp: %s: %s\n", argv[optind], strerror(errno)); + close(fd); + optind++; + continue; + } ptr= rindex(argv[optind], '/'); if (ptr) @@ -78,6 +84,11 @@ int main(int argc, char *argv[]) else abort(); + if (rc != MEMCACHED_SUCCESS) { + fprintf(stderr, "memcp: %s: memcache error %s\n", + ptr, memcached_strerror(memc, rc)); + } + munmap(mptr, sbuf.st_size); close(fd); optind++; diff --git a/src/memrm.c b/src/memrm.c index 6deca09b..49172e5a 100644 --- a/src/memrm.c +++ b/src/memrm.c @@ -66,6 +66,12 @@ int main(int argc, char *argv[]) printf("key: %s\nexpires: %ld\n", argv[optind], expires); } rc = memcached_delete(memc, argv[optind], strlen(argv[optind]), expires); + + if (rc != MEMCACHED_SUCCESS) { + fprintf(stderr, "memrm: %s: memcache error %s\n", + argv[optind], memcached_strerror(memc, rc)); + } + optind++; } -- 2.30.2