]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
tools:remove the local file when get map failed. 5920/head
authorBo Cai <cai.bo@h3c.com>
Mon, 14 Sep 2015 11:19:05 +0000 (19:19 +0800)
committerBo Cai <cai.bo@h3c.com>
Mon, 14 Sep 2015 15:15:09 +0000 (23:15 +0800)
Signed-off-by: Bo Cai <cai.bo@h3c.com>
src/tools/ceph_monstore_tool.cc

index eec3924ccc83250dec9626a8ac1edcea312e7545..c979bcdabe38ed98bb9dfe8a4b5808e67966280b 100644 (file)
@@ -12,6 +12,7 @@
 */
 #include <boost/program_options/variables_map.hpp>
 #include <boost/program_options/parsers.hpp>
+#include <boost/scope_exit.hpp>
 
 #include <stdlib.h>
 #include <string>
@@ -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);