]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephtool: accept semicolons in commandline args
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Mon, 1 Aug 2011 22:51:19 +0000 (15:51 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Tue, 2 Aug 2011 00:23:03 +0000 (17:23 -0700)
Semicolons can now be used to give multiple arguments to cephtool in one
invocation. So a command like this is now possible:

$ ./ceph osd dump --format=json \; pg dump --format=json -o -

The backslash is to prevent the shell from consuming the semicolon.

Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
src/tools/ceph.cc
src/tools/common.cc

index f3124c4221f0429c869183065a91a594109f6597..bec079806f8c53ff688bb2221b94e48af0aa7c33 100644 (file)
@@ -162,17 +162,25 @@ int main(int argc, const char **argv)
     }
 
     case CEPH_TOOL_MODE_CLI_INPUT: {
-      vector<string> cmd;
-      for (unsigned int i = 0; i < nargs.size(); ++i) {
-       cmd.push_back(string(nargs[i]));
-      }
-      if (cmd.empty()) {
+      if (nargs.empty()) {
        if (ceph_tool_do_cli(ctx))
          ret = 1;
       }
       else {
-       if (ceph_tool_cli_input(ctx, cmd, out_file, indata))
-         ret = 1;
+       while (!nargs.empty()) {
+         vector<string> cmd;
+         for (vector<const char*>::iterator n = nargs.begin();
+              n != nargs.end(); ) {
+           std::string np(*n);
+           n = nargs.erase(n);
+           if (np == ";")
+             break;
+           cmd.push_back(np);
+         }
+
+         if (ceph_tool_cli_input(ctx, cmd, out_file, indata))
+           ret = 1;
+       }
       }
       if (ceph_tool_messenger_shutdown())
        ret = 1;
index 89e52b2168867e554bc8c583fbb935d040e958fe..32aede39059101ac599eac2fa36ad9a8e7f7d51a 100644 (file)
@@ -25,6 +25,7 @@ using namespace std;
 #include "msg/SimpleMessenger.h"
 #include "tools/common.h"
 
+#include "common/errno.h"
 #include "common/Cond.h"
 #include "common/Mutex.h"
 #include "common/Timer.h"
@@ -516,10 +517,27 @@ int ceph_tool_cli_input(CephToolCtx *ctx, std::vector<std::string> &cmd,
     return 0;
   }
 
-  // write to file
-  odata.write_file(outfile);
-  derr << " wrote " << len << " byte payload to "
-       << outfile << dendl;
+  // Write to a file. Don't truncate the file.
+  int fd = TEMP_FAILURE_RETRY(::open(outfile, O_WRONLY|O_CREAT, 0644));
+  if (fd < 0) {
+    int err = errno;
+    derr << " failed to create file '" << outfile << "': "
+        << cpp_strerror(err) << dendl;
+    return 1;
+  }
+  ret = odata.write_fd(fd);
+  if (ret) {
+    derr << " error writing file: " << cpp_strerror(ret) << dendl;
+    close(fd);
+    return 1;
+  }
+  derr << " wrote " << len << " byte payload to " << outfile << dendl;
+  if (close(fd)) {
+    int err = errno;
+    derr << " error while closing file '" << outfile << "': "
+        << cpp_strerror(err) << dendl;
+    return 1;
+  }
   return 0;
 }