From: Joao Eduardo Luis Date: Fri, 22 Nov 2013 02:17:16 +0000 (+0000) Subject: mon: OSDMonitor: don't crash if formatter is invalid during osd crush dump X-Git-Tag: v0.73~12^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=49d2fb71422fe4edfe5795c001104fb5bc8c98c3;p=ceph.git mon: OSDMonitor: don't crash if formatter is invalid during osd crush dump Code would assume a formatter would always be defined. If a 'plain' formatter or even an invalid formatter were to be supplied, the monitor would crash and burn in poor style. Fixes: 6820 Backport: emperor Signed-off-by: Joao Eduardo Luis --- diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 1994b0d2dbab..058a5cfeef3a 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -2414,7 +2414,10 @@ stats_out: prefix == "osd crush rule ls") { string format; cmd_getval(g_ceph_context, cmdmap, "format", format, string("json-pretty")); - boost::scoped_ptr f(new_formatter(format)); + Formatter *fp = new_formatter(format); + if (!fp) + fp = new_formatter("json-pretty"); + boost::scoped_ptr f(fp); f->open_array_section("rules"); osdmap.crush->list_rules(f.get()); f->close_section(); @@ -2425,7 +2428,10 @@ stats_out: } else if (prefix == "osd crush rule dump") { string format; cmd_getval(g_ceph_context, cmdmap, "format", format, string("json-pretty")); - boost::scoped_ptr f(new_formatter(format)); + Formatter *fp = new_formatter(format); + if (!fp) + fp = new_formatter("json-pretty"); + boost::scoped_ptr f(fp); f->open_array_section("rules"); osdmap.crush->dump_rules(f.get()); f->close_section(); @@ -2436,7 +2442,10 @@ stats_out: } else if (prefix == "osd crush dump") { string format; cmd_getval(g_ceph_context, cmdmap, "format", format, string("json-pretty")); - boost::scoped_ptr f(new_formatter(format)); + Formatter *fp = new_formatter(format); + if (!fp) + fp = new_formatter("json-pretty"); + boost::scoped_ptr f(fp); f->open_object_section("crush_map"); osdmap.crush->dump(f.get()); f->close_section();