// 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) {
<< cpp_strerror(ret) << dendl;
return 1;
}
+ close_out_fd = true;
}
CephToolCtx *ctx = ceph_tool_common_init(mode, concise);
<< 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;
}
}
}
}
out:
- ::close(out_fd);
+ if (close_out_fd)
+ ::close(out_fd);
if (ceph_tool_common_shutdown(ctx))
ret = 1;
return ret;