You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by jp...@apache.org on 2017/02/21 03:37:58 UTC

[trafficserver] 02/04: Use Result to show Cache configuration parse errors.

This is an automated email from the ASF dual-hosted git repository.

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit a7100edbc4cf3b357de43b91dfe3ddbf7493bcbb
Author: James Peach <jp...@apache.org>
AuthorDate: Sat Feb 18 13:54:52 2017 -0800

    Use Result to show Cache configuration parse errors.
---
 iocore/cache/Cache.cc  |  7 +++----
 iocore/cache/I_Store.h | 10 ++++------
 iocore/cache/Store.cc  | 22 ++++++++--------------
 proxy/Main.cc          |  6 ++++--
 4 files changed, 19 insertions(+), 26 deletions(-)

diff --git a/iocore/cache/Cache.cc b/iocore/cache/Cache.cc
index 3ac09dd..1088845 100644
--- a/iocore/cache/Cache.cc
+++ b/iocore/cache/Cache.cc
@@ -3285,10 +3285,9 @@ ink_cache_init(ModuleVersion v)
 
   REC_ReadConfigInteger(cacheProcessor.wait_for_cache, "proxy.config.http.wait_for_cache");
 
-  const char *err = nullptr;
-  if ((err = theCacheStore.read_config())) {
-    printf("Failed to read cache storage configuration - %s\n", err);
-    exit(1);
+  Result result = theCacheStore.read_config();
+  if (result.failed()) {
+    Fatal("Failed to read cache storage configuration: %s", result.message());
   }
 }
 
diff --git a/iocore/cache/I_Store.h b/iocore/cache/I_Store.h
index de6ceb7..9f9ef21 100644
--- a/iocore/cache/I_Store.h
+++ b/iocore/cache/I_Store.h
@@ -32,6 +32,7 @@
 #define _Store_h_
 
 #include "ts/ink_platform.h"
+#include "ts/Result.h"
 
 #define STORE_BLOCK_SIZE 8192
 #define STORE_BLOCK_SHIFT 13
@@ -258,12 +259,9 @@ struct Store {
   // The number of disks/paths we could actually read and parse.
   unsigned n_disks;
   Span **disk;
-  //
-  // returns nullptr on success
-  // if fd >= 0 then on failure it returns an error string
-  //            otherwise on failure it returns (char *)-1
-  //
-  const char *read_config();
+
+  Result read_config();
+
   int write_config_data(int fd) const;
 
   /// Additional configuration key values.
diff --git a/iocore/cache/Store.cc b/iocore/cache/Store.cc
index e922d3b..54ea293 100644
--- a/iocore/cache/Store.cc
+++ b/iocore/cache/Store.cc
@@ -306,7 +306,7 @@ Lagain:
   return found ? 0 : -1;
 }
 
-const char *
+Result
 Store::read_config()
 {
   int n_dsstore   = 0;
@@ -321,8 +321,7 @@ Store::read_config()
   Debug("cache_init", "Store::read_config, fd = -1, \"%s\"", (const char *)storage_path);
   fd = ::open(storage_path, O_RDONLY);
   if (fd < 0) {
-    err = "error on open";
-    goto Lfail;
+    return Result::failure("open %s: %s", (const char *)storage_path, strerror(errno));
   }
 
   // For each line
@@ -358,8 +357,8 @@ Store::read_config()
     while (nullptr != (e = tokens.getNext())) {
       if (ParseRules::is_digit(*e)) {
         if ((size = ink_atoi64(e)) <= 0) {
-          err = "error parsing size";
-          goto Lfail;
+          delete sd;
+          return Result::failure("failed to parse size '%s'", e);
         }
       } else if (0 == strncasecmp(HASH_BASE_STRING_KEY, e, sizeof(HASH_BASE_STRING_KEY) - 1)) {
         e += sizeof(HASH_BASE_STRING_KEY) - 1;
@@ -372,8 +371,8 @@ Store::read_config()
         if ('=' == *e)
           ++e;
         if (!*e || !ParseRules::is_digit(*e) || 0 >= (volume_num = ink_atoi(e))) {
-          err = "error parsing volume number";
-          goto Lfail;
+          delete sd;
+          return Result::failure("failed to parse volume number '%s'", e);
         }
       }
     }
@@ -390,6 +389,7 @@ Store::read_config()
       ats_free(pp);
       continue;
     }
+
     ats_free(pp);
     n_dsstore++;
 
@@ -421,14 +421,8 @@ Store::read_config()
   }
   sd = nullptr; // these are all used.
   sort();
-  return nullptr;
-
-Lfail:
-  // Do clean up.
-  if (sd)
-    delete sd;
 
-  return err;
+  return Result::ok();
 }
 
 int
diff --git a/proxy/Main.cc b/proxy/Main.cc
index edf6c8f..5e36723 100644
--- a/proxy/Main.cc
+++ b/proxy/Main.cc
@@ -597,8 +597,10 @@ cmd_list(char * /* cmd ATS_UNUSED */)
 
   Note("Cache Storage:");
   Store tStore;
-  if (tStore.read_config() != nullptr) {
-    Note("config read failure");
+  Result result = tStore.read_config();
+
+  if (result.failed()) {
+    Note("Failed to read cache storage configuration: %s", result.message());
     return CMD_FAILED;
   } else {
     tStore.write_config_data(fileno(stdout));

-- 
To stop receiving notification emails like this one, please contact
"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>.