From 0b03b32d8ba76fe9f6f1158e68eb440e3670393a Mon Sep 17 00:00:00 2001 From: Bo Cai Date: Mon, 14 Sep 2015 19:19:05 +0800 Subject: [PATCH] tools:remove the local file when get map failed. Signed-off-by: Bo Cai --- src/tools/ceph_monstore_tool.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/tools/ceph_monstore_tool.cc b/src/tools/ceph_monstore_tool.cc index eec3924ccc8..c979bcdabe3 100644 --- a/src/tools/ceph_monstore_tool.cc +++ b/src/tools/ceph_monstore_tool.cc @@ -12,6 +12,7 @@ */ #include #include +#include #include #include @@ -600,6 +601,13 @@ int main(int argc, char **argv) { } } + BOOST_SCOPE_EXIT((&r) (&fd) (&outpath)) { + ::close(fd); + if (r < 0 && fd != STDOUT_FILENO) { + ::remove(outpath.c_str()); + } + } BOOST_SCOPE_EXIT_END + bufferlist bl; r = 0; if (map_type == "osdmap") { @@ -610,7 +618,6 @@ int main(int argc, char **argv) { if (r < 0) { std::cerr << "Error getting map: " << cpp_strerror(r) << std::endl; err = EINVAL; - ::close(fd); goto done; } bl.write_fd(fd);