From: Sage Weil Date: Wed, 28 Sep 2011 20:57:44 +0000 (-0700) Subject: ceph: make -o - the default X-Git-Tag: v0.36~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2f1fc5ab1084de3db52250d9472e4c9473d520d7;p=ceph.git ceph: make -o - the default Finally. Signed-off-by: Sage Weil --- diff --git a/src/tools/ceph.cc b/src/tools/ceph.cc index b00685b6b79..c18045a0515 100644 --- a/src/tools/ceph.cc +++ b/src/tools/ceph.cc @@ -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;