From: Kefu Chai Date: Wed, 16 Nov 2016 03:56:09 +0000 (+0800) Subject: crushtool: s/exit(EXIT_FAILURE)/return EXIT_FAILURE/ X-Git-Tag: v11.1.0~158^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e01b89ed6be6b99fec5c725f4bc5769b42468cac;p=ceph.git crushtool: s/exit(EXIT_FAILURE)/return EXIT_FAILURE/ so the destructor(s) can be called. Signed-off-by: Kefu Chai --- diff --git a/src/tools/crushtool.cc b/src/tools/crushtool.cc index 7b199cb584f2..d4bc24fc1d8d 100644 --- a/src/tools/crushtool.cc +++ b/src/tools/crushtool.cc @@ -287,7 +287,7 @@ int main(int argc, const char **argv) break; } else if (ceph_argparse_flag(args, i, "-h", "--help", (char*)NULL)) { usage(); - exit(0); + return EXIT_SUCCESS; } else if (ceph_argparse_witharg(args, i, &val, "-d", "--decompile", (char*)NULL)) { infn = val; decompile = true; @@ -358,17 +358,17 @@ int main(int argc, const char **argv) } else if (ceph_argparse_witharg(args, i, &add_item, err, "--add_item", (char*)NULL)) { if (!err.str().empty()) { cerr << err.str() << std::endl; - exit(EXIT_FAILURE); + return EXIT_FAILURE; } if (i == args.end()) { cerr << "expecting additional argument to --add-item" << std::endl; - exit(EXIT_FAILURE); + return EXIT_FAILURE; } add_weight = atof(*i); i = args.erase(i); if (i == args.end()) { cerr << "expecting additional argument to --add-item" << std::endl; - exit(EXIT_FAILURE); + return EXIT_FAILURE; } add_name.assign(*i); i = args.erase(i); @@ -376,17 +376,17 @@ int main(int argc, const char **argv) update_item = true; if (!err.str().empty()) { cerr << err.str() << std::endl; - exit(EXIT_FAILURE); + return EXIT_FAILURE; } if (i == args.end()) { cerr << "expecting additional argument to --update-item" << std::endl; - exit(EXIT_FAILURE); + return EXIT_FAILURE; } add_weight = atof(*i); i = args.erase(i); if (i == args.end()) { cerr << "expecting additional argument to --update-item" << std::endl; - exit(EXIT_FAILURE); + return EXIT_FAILURE; } add_name.assign(*i); i = args.erase(i); @@ -394,7 +394,7 @@ int main(int argc, const char **argv) std::string type(val); if (i == args.end()) { cerr << "expecting additional argument to --loc" << std::endl; - exit(EXIT_FAILURE); + return EXIT_FAILURE; } std::string name(*i); i = args.erase(i); @@ -405,12 +405,12 @@ int main(int argc, const char **argv) tester.set_output_csv(true); } else if (ceph_argparse_flag(args, i, "--help-output", (char*)NULL)) { data_analysis_usage(); - exit(0); + return EXIT_SUCCESS; } else if (ceph_argparse_witharg(args, i, &val, "--output-name", (char*)NULL)) { std::string name(val); if (i == args.end()) { cerr << "expecting additional argument to --output-name" << std::endl; - exit(EXIT_FAILURE); + return EXIT_FAILURE; } else { tester.set_output_data_file_name(name + "-"); @@ -421,7 +421,7 @@ int main(int argc, const char **argv) reweight_name = val; if (i == args.end()) { cerr << "expecting additional argument to --reweight-item" << std::endl; - exit(EXIT_FAILURE); + return EXIT_FAILURE; } reweight_weight = atof(*i); i = args.erase(i); @@ -430,89 +430,89 @@ int main(int argc, const char **argv) } else if (ceph_argparse_witharg(args, i, &num_osds, err, "--num_osds", (char*)NULL)) { if (!err.str().empty()) { cerr << err.str() << std::endl; - exit(EXIT_FAILURE); + return EXIT_FAILURE; } } else if (ceph_argparse_witharg(args, i, &x, err, "--num_rep", (char*)NULL)) { if (!err.str().empty()) { cerr << err.str() << std::endl; - exit(EXIT_FAILURE); + return EXIT_FAILURE; } tester.set_num_rep(x); } else if (ceph_argparse_witharg(args, i, &x, err, "--max_x", (char*)NULL)) { if (!err.str().empty()) { cerr << err.str() << std::endl; - exit(EXIT_FAILURE); + return EXIT_FAILURE; } tester.set_max_x(x); } else if (ceph_argparse_witharg(args, i, &x, err, "--min_x", (char*)NULL)) { if (!err.str().empty()) { cerr << err.str() << std::endl; - exit(EXIT_FAILURE); + return EXIT_FAILURE; } tester.set_min_x(x); } else if (ceph_argparse_witharg(args, i, &z, err, "--pool_id", (char*)NULL)) { if (!err.str().empty()) { - cerr << err.str() << std::endl; - exit(EXIT_FAILURE); + cerr << err.str() << std::endl; + return EXIT_FAILURE; } tester.set_pool_id(z); } else if (ceph_argparse_witharg(args, i, &x, err, "--x", (char*)NULL)) { if (!err.str().empty()) { cerr << err.str() << std::endl; - exit(EXIT_FAILURE); + return EXIT_FAILURE; } tester.set_x(x); } else if (ceph_argparse_witharg(args, i, &x, err, "--max_rule", (char*)NULL)) { if (!err.str().empty()) { cerr << err.str() << std::endl; - exit(EXIT_FAILURE); + return EXIT_FAILURE; } tester.set_max_rule(x); } else if (ceph_argparse_witharg(args, i, &x, err, "--min_rule", (char*)NULL)) { if (!err.str().empty()) { cerr << err.str() << std::endl; - exit(EXIT_FAILURE); + return EXIT_FAILURE; } tester.set_min_rule(x); } else if (ceph_argparse_witharg(args, i, &x, err, "--rule", (char*)NULL)) { if (!err.str().empty()) { cerr << err.str() << std::endl; - exit(EXIT_FAILURE); + return EXIT_FAILURE; } tester.set_rule(x); } else if (ceph_argparse_witharg(args, i, &x, err, "--ruleset", (char*)NULL)) { if (!err.str().empty()) { cerr << err.str() << std::endl; - exit(EXIT_FAILURE); + return EXIT_FAILURE; } tester.set_ruleset(x); } else if (ceph_argparse_witharg(args, i, &x, err, "--batches", (char*)NULL)) { if (!err.str().empty()) { cerr << err.str() << std::endl; - exit(EXIT_FAILURE); + return EXIT_FAILURE; } tester.set_batches(x); } else if (ceph_argparse_witharg(args, i, &y, err, "--mark-down-ratio", (char*)NULL)) { if (!err.str().empty()) { cerr << err.str() << std::endl; - exit(EXIT_FAILURE); + return EXIT_FAILURE; } tester.set_device_down_ratio(y); } else if (ceph_argparse_witharg(args, i, &y, err, "--mark-down-bucket-ratio", (char*)NULL)) { if (!err.str().empty()) { cerr << err.str() << std::endl; - exit(EXIT_FAILURE); + return EXIT_FAILURE; } tester.set_bucket_down_ratio(y); } else if (ceph_argparse_witharg(args, i, &tmp, err, "--weight", (char*)NULL)) { if (!err.str().empty()) { cerr << err.str() << std::endl; - exit(EXIT_FAILURE); + return EXIT_FAILURE; } int dev = tmp; if (i == args.end()) { cerr << "expecting additional argument to --weight" << std::endl; - exit(EXIT_FAILURE); + return EXIT_FAILURE; } float f = atof(*i); i = args.erase(i); @@ -529,24 +529,24 @@ int main(int argc, const char **argv) if (decompile + compile + build > 1) { cerr << "cannot specify more than one of compile, decompile, and build" << std::endl; - exit(EXIT_FAILURE); + return EXIT_FAILURE; } if (!check && !compile && !decompile && !build && !test && !reweight && !adjust && !tree && add_item < 0 && full_location < 0 && remove_name.empty() && reweight_name.empty()) { cerr << "no action specified; -h for help" << std::endl; - exit(EXIT_FAILURE); + return EXIT_FAILURE; } if ((!build) && (!args.empty())) { cerr << "unrecognized arguments: " << args << std::endl; - exit(EXIT_FAILURE); + return EXIT_FAILURE; } else { if ((args.size() % 3) != 0U) { cerr << "remaining args: " << args << std::endl; cerr << "layers must be specified with 3-tuples of (name, buckettype, size)" << std::endl; - exit(EXIT_FAILURE); + return EXIT_FAILURE; } for (size_t j = 0; j < args.size(); j += 3) { layer_t l; @@ -575,19 +575,19 @@ int main(int argc, const char **argv) if (infn == "-") { if (isatty(STDIN_FILENO)) { cerr << "stdin must not be from a tty" << std::endl; - exit(EXIT_FAILURE); + return EXIT_FAILURE; } r = get_fd_data(STDIN_FILENO, bl); if (r < 0) { cerr << "error reading data from STDIN" << std::endl; - exit(EXIT_FAILURE); + return EXIT_FAILURE; } } else { r = bl.read_file(infn.c_str(), &error); if (r < 0) { cerr << me << ": error reading '" << infn << "': " << error << std::endl; - exit(1); + return EXIT_FAILURE; } } bufferlist::iterator p = bl.begin(); @@ -595,7 +595,7 @@ int main(int argc, const char **argv) crush.decode(p); } catch(...) { cerr << me << ": unable to decode " << infn << std::endl; - exit(EXIT_FAILURE); + return EXIT_FAILURE; } } @@ -614,7 +614,7 @@ int main(int argc, const char **argv) cc.enable_unsafe_tunables(); int r = cc.compile(in, srcfn.c_str()); if (r < 0) - exit(1); + return EXIT_FAILURE; modified = true; } @@ -622,7 +622,7 @@ int main(int argc, const char **argv) if (build) { if (layers.empty()) { cerr << me << ": must specify at least one layer" << std::endl; - exit(1); + return EXIT_FAILURE; } crush.create(); @@ -658,7 +658,7 @@ int main(int argc, const char **argv) } if (buckettype < 0) { cerr << "unknown bucket type '" << l.buckettype << "'" << std::endl; - exit(EXIT_FAILURE); + return EXIT_FAILURE; } // build items @@ -733,7 +733,7 @@ int main(int argc, const char **argv) } if (OSDMap::build_simple_crush_rulesets(g_ceph_context, crush, root, &cerr)) - exit(EXIT_FAILURE); + return EXIT_FAILURE; modified = true; } @@ -851,7 +851,7 @@ int main(int argc, const char **argv) o.open(outfn.c_str(), ios::out | ios::binary | ios::trunc); if (!o.is_open()) { cerr << me << ": error writing '" << outfn << "'" << std::endl; - exit(1); + return EXIT_FAILURE; } cc.decompile(o); o.close(); @@ -864,7 +864,7 @@ int main(int argc, const char **argv) tester.check_overlapped_rules(); if (max_id >= 0) { if (!tester.check_name_maps(max_id)) { - exit(1); + return EXIT_FAILURE; } } } @@ -876,7 +876,7 @@ int main(int argc, const char **argv) int r = tester.test(); if (r < 0) - exit(1); + return EXIT_FAILURE; } // output --- @@ -891,7 +891,7 @@ int main(int argc, const char **argv) int r = bl.write_file(outfn.c_str()); if (r < 0) { cerr << me << ": error writing '" << outfn << "': " << cpp_strerror(r) << std::endl; - exit(1); + return EXIT_FAILURE; } if (verbose) cout << "wrote crush map to " << outfn << std::endl;