From ad563cf5d23e7f8ac29059be459cc4747eb746c0 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Tue, 17 Dec 2013 10:20:28 +0100 Subject: [PATCH] Use CompatUtility::GetCommandLine in StatusDataWriter::DumpCommand. Fixes #5353 --- components/compat/statusdatawriter.cpp | 19 +------------------ lib/icinga/compatutility.cpp | 10 +++++----- 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/components/compat/statusdatawriter.cpp b/components/compat/statusdatawriter.cpp index 80e50f7d5..b1947464b 100644 --- a/components/compat/statusdatawriter.cpp +++ b/components/compat/statusdatawriter.cpp @@ -134,24 +134,7 @@ void StatusDataWriter::DumpCommand(std::ostream& fp, const Command::Ptr& command fp << command->GetName() << "\n"; - fp << "\t" "command_line\t"; - - Value commandLine = command->GetCommandLine(); - - if (commandLine.IsObjectType()) { - Array::Ptr args = commandLine; - - ObjectLock olock(args); - String arg; - BOOST_FOREACH(arg, args) { - // This is obviously incorrect for non-trivial cases. - fp << " \"" << CompatUtility::EscapeString(arg) << "\""; - } - } else if (!commandLine.IsEmpty()) { - fp << CompatUtility::EscapeString(commandLine); - } else { - fp << ""; - } + fp << "\t" "command_line" "\t" << CompatUtility::GetCommandLine(command); fp << "\n" "\t" "}" "\n" "\n"; diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index 1a394867a..7f86b8230 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -39,7 +39,7 @@ String CompatUtility::GetCommandLine(const Command::Ptr& command) { Value commandLine = command->GetCommandLine(); - String commandline; + String result; if (commandLine.IsObjectType()) { Array::Ptr args = commandLine; @@ -47,15 +47,15 @@ String CompatUtility::GetCommandLine(const Command::Ptr& command) String arg; BOOST_FOREACH(arg, args) { // This is obviously incorrect for non-trivial cases. - commandline = " \"" + EscapeString(arg) + "\""; + result += " \"" + EscapeString(arg) + "\""; } } else if (!commandLine.IsEmpty()) { - commandline = EscapeString(Convert::ToString(commandLine)); + result = EscapeString(Convert::ToString(commandLine)); } else { - commandline = ""; + result = ""; } - return commandline; + return result; } /* host */ -- 2.40.0