]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph: make -o - the default
authorSage Weil <sage.weil@dreamhost.com>
Wed, 28 Sep 2011 20:57:44 +0000 (13:57 -0700)
committerSage Weil <sage.weil@dreamhost.com>
Wed, 28 Sep 2011 20:57:44 +0000 (13:57 -0700)
Finally.

Signed-off-by: Sage Weil <sage.weil@dreamhost.com>
src/tools/ceph.cc

index b00685b6b7940a4e4cd9cf258f76db0eaac9a556..c18045a0515d0d73474433dbe54da615fd46c25c 100644 (file)
@@ -136,11 +136,9 @@ int main(int argc, const char **argv)
 
   // output
   int out_fd;
-  if (out_file.empty()) {
-    out_fd = ::open("/dev/null", O_WRONLY);
-    out_file = "/dev/null";
-  } else if (out_file == "-") {
-    out_fd = dup(STDOUT_FILENO);
+  bool close_out_fd = false;
+  if (out_file.empty() || out_file == "-") {
+    out_fd = STDOUT_FILENO;
   } else {
     out_fd = TEMP_FAILURE_RETRY(::open(out_file.c_str(), O_WRONLY|O_CREAT|O_TRUNC, 0644));
     if (out_fd < 0) {
@@ -149,6 +147,7 @@ int main(int argc, const char **argv)
           << cpp_strerror(ret) << dendl;
       return 1;
     }
+    close_out_fd = true;
   }
 
   CephToolCtx *ctx = ceph_tool_common_init(mode, concise);
@@ -195,8 +194,8 @@ int main(int argc, const char **argv)
                   << cpp_strerror(err) << dendl;
              goto out;
            }
-           if (!concise)
-             cout << " wrote " << obl.length() << " byte payload to " << out_file << std::endl;
+           if (!concise && !out_file.empty())
+             cerr << " wrote " << obl.length() << " byte payload to " << out_file << std::endl;
          }
        }
       }
@@ -213,7 +212,8 @@ int main(int argc, const char **argv)
   }
 
  out:
-  ::close(out_fd);
+  if (close_out_fd)
+    ::close(out_fd);
   if (ceph_tool_common_shutdown(ctx))
     ret = 1;
   return ret;