]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph_filstore_dump: Save if stdout is a tty and add routine to clean binary strings
authorDavid Zafman <david.zafman@inktank.com>
Tue, 20 May 2014 18:56:20 +0000 (11:56 -0700)
committerDavid Zafman <dzafman@redhat.com>
Thu, 28 Aug 2014 23:21:27 +0000 (16:21 -0700)
Signed-off-by: David Zafman <david.zafman@inktank.com>
src/tools/ceph_filestore_dump.cc

index 00b92844c17b6f579c085a7d36620622b0afa58b..949042f14b952744d567f94657693eddc14bc02a 100644 (file)
@@ -81,6 +81,7 @@ const uint16_t shortmagic = 0xffce;   //goes into stream as "ceff"
 //endmagic goes into stream as "ceff ffec"
 const mymagic_t endmagic = (0xecff << 16) | shortmagic;
 const int fd_none = INT_MIN;
+bool outistty;
 
 //The first FIXED_LENGTH bytes are a fixed
 //portion of the export output.  This includes the overall
@@ -355,6 +356,29 @@ int write_section(sectiontype_t type, const T& obj, int fd) {
   return ret;
 }
 
+// Convert non-printable characters to '\###'
+static void cleanbin(string &str)
+{
+  bool cleaned = false;
+  string clean;
+
+  for (string::iterator it = str.begin(); it != str.end(); ++it) {
+    if (!isprint(*it)) {
+      clean.push_back('\\');
+      clean.push_back('0' + ((*it >> 6) & 7));
+      clean.push_back('0' + ((*it >> 3) & 7));
+      clean.push_back('0' + (*it & 7));
+      cleaned = true;
+    } else {
+      clean.push_back(*it);
+    }
+  }
+
+  if (cleaned)
+    str = clean;
+  return;
+}
+
 int write_simple(sectiontype_t type, int fd)
 {
   bufferlist hbl;
@@ -1147,6 +1171,8 @@ int main(int argc, char **argv)
     return 1;
   } 
 
+  outistty = isatty(STDOUT_FILENO);
+
   file_fd = fd_none;
   if (type == "export") {
     if (!vm.count("file")) {