summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJayanth Othayoth <ojayanth@in.ibm.com>2018-10-16 08:29:32 -0500
committerBrad Bishop <bradleyb@fuzziesquirrel.com>2018-10-18 16:33:14 -0400
commitcb65ffce0f0496c603cba6d6e12b20d66372cb9a (patch)
treeea178b2585004b8b00a1006ec1b2f5adffc99ca1
parentae871bd0661c472a0c3ad231fc3623535bcfba2d (diff)
downloadphosphor-debug-collector-cb65ffce0f0496c603cba6d6e12b20d66372cb9a.tar.gz
phosphor-debug-collector-cb65ffce0f0496c603cba6d6e12b20d66372cb9a.zip
Enable clang code format
Change-Id: Ib640ef7cea99ff505965182ec9900a2d53a8986e Signed-off-by: Jayanth Othayoth <ojayanth@in.ibm.com> Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
-rw-r--r--.clang-format99
-rw-r--r--core_manager.cpp34
-rw-r--r--core_manager.hpp80
-rw-r--r--core_manager_main.cpp9
-rw-r--r--dump_entry.cpp11
-rw-r--r--dump_entry.hpp97
-rw-r--r--dump_internal.hpp64
-rw-r--r--dump_manager.cpp139
-rw-r--r--dump_manager.hpp262
-rw-r--r--dump_manager_main.cpp15
-rw-r--r--dump_serialize.cpp9
-rw-r--r--dump_serialize.hpp5
-rw-r--r--dump_utils.hpp59
-rw-r--r--elog_watch.cpp64
-rw-r--r--elog_watch.hpp148
-rw-r--r--watch.cpp41
-rw-r--r--watch.hpp139
17 files changed, 653 insertions, 622 deletions
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..ea71ad6
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,99 @@
+---
+Language: Cpp
+# BasedOnStyle: LLVM
+AccessModifierOffset: -2
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlinesLeft: false
+AlignOperands: true
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: true
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+ AfterClass: true
+ AfterControlStatement: true
+ AfterEnum: true
+ AfterFunction: true
+ AfterNamespace: true
+ AfterObjCDeclaration: true
+ AfterStruct: true
+ AfterUnion: true
+ BeforeCatch: true
+ BeforeElse: true
+ IndentBraces: false
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Custom
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializers: AfterColon
+ColumnLimit: 80
+CommentPragmas: '^ IWYU pragma:'
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: true
+DerivePointerAlignment: false
+PointerAlignment: Left
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: true
+ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
+IncludeBlocks: Regroup
+IncludeCategories:
+ - Regex: '^[<"](gtest|gmock)'
+ Priority: 5
+ - Regex: '^"config.h"'
+ Priority: -1
+ - Regex: '^".*\.hpp"'
+ Priority: 1
+ - Regex: '^<.*\.h>'
+ Priority: 2
+ - Regex: '^<.*'
+ Priority: 3
+ - Regex: '.*'
+ Priority: 4
+IndentCaseLabels: true
+IndentWidth: 4
+IndentWrappedFunctionNames: true
+KeepEmptyLinesAtTheStartOfBlocks: true
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBlockIndentWidth: 2
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 60
+ReflowComments: true
+SortIncludes: true
+SortUsingDeclarations: true
+SpaceAfterCStyleCast: false
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeParens: ControlStatements
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard: Cpp11
+TabWidth: 4
+UseTab: Never
+...
+
diff --git a/core_manager.cpp b/core_manager.cpp
index 3ab726b..19b80a2 100644
--- a/core_manager.cpp
+++ b/core_manager.cpp
@@ -1,12 +1,12 @@
-#include <regex>
-#include <experimental/filesystem>
+#include "config.h"
+
+#include "core_manager.hpp"
+#include <experimental/filesystem>
#include <phosphor-logging/log.hpp>
+#include <regex>
#include <sdbusplus/exception.hpp>
-#include "core_manager.hpp"
-#include "config.h"
-
namespace phosphor
{
namespace dump
@@ -35,9 +35,9 @@ void Manager::watchCallback(const UserMap& fileInfo)
to actual core file creation. Checking the file name format will help
to limit dump creation only for the new core files.
*/
- if("core" == name.substr(0, name.find('.')))
+ if ("core" == name.substr(0, name.find('.')))
{
- //Consider only file name start with "core."
+ // Consider only file name start with "core."
files.push_back(file);
}
}
@@ -58,11 +58,8 @@ void Manager::createHelper(const vector<string>& files)
"xyz.openbmc_project.Dump.Internal.Create.Type.ApplicationCored";
auto b = sdbusplus::bus::new_default();
- auto mapper = b.new_method_call(
- MAPPER_BUSNAME,
- MAPPER_PATH,
- MAPPER_INTERFACE,
- "GetObject");
+ auto mapper = b.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
+ MAPPER_INTERFACE, "GetObject");
mapper.append(OBJ_INTERNAL, vector<string>({IFACE_INTERNAL}));
auto mapperResponseMsg = b.call(mapper);
@@ -79,9 +76,9 @@ void Manager::createHelper(const vector<string>& files)
}
catch (const sdbusplus::exception::SdBusError& e)
{
- log<level::ERR>("Failed to parse dump create message",
- entry("ERROR=%s", e.what()),
- entry("REPLY_SIG=%s", mapperResponseMsg.get_signature()));
+ log<level::ERR>(
+ "Failed to parse dump create message", entry("ERROR=%s", e.what()),
+ entry("REPLY_SIG=%s", mapperResponseMsg.get_signature()));
return;
}
if (mapperResponse.empty())
@@ -91,11 +88,8 @@ void Manager::createHelper(const vector<string>& files)
}
const auto& host = mapperResponse.cbegin()->first;
- auto m = b.new_method_call(
- host.c_str(),
- OBJ_INTERNAL,
- IFACE_INTERNAL,
- "Create");
+ auto m =
+ b.new_method_call(host.c_str(), OBJ_INTERNAL, IFACE_INTERNAL, "Create");
m.append(APPLICATION_CORED, files);
b.call_noreply(m);
}
diff --git a/core_manager.hpp b/core_manager.hpp
index 1a79982..18b7125 100644
--- a/core_manager.hpp
+++ b/core_manager.hpp
@@ -1,10 +1,11 @@
#pragma once
-#include <map>
+#include "config.h"
#include "dump_utils.hpp"
#include "watch.hpp"
-#include "config.h"
+
+#include <map>
namespace phosphor
{
@@ -20,9 +21,9 @@ using UserMap = phosphor::dump::inotify::UserMap;
* Refer openbmc/issues/#2287 for more details.
*/
#ifdef UBI_CORE_FILE_WORKAROUND
- static constexpr auto coreFileEvent = IN_CREATE;
+static constexpr auto coreFileEvent = IN_CREATE;
#else
- static constexpr auto coreFileEvent = IN_CLOSE_WRITE;
+static constexpr auto coreFileEvent = IN_CLOSE_WRITE;
#endif
/** @class Manager
@@ -30,50 +31,45 @@ using UserMap = phosphor::dump::inotify::UserMap;
*/
class Manager
{
- public:
- Manager() = delete;
- Manager(const Manager&) = default;
- Manager& operator=(const Manager&) = delete;
- Manager(Manager&&) = delete;
- Manager& operator=(Manager&&) = delete;
- virtual ~Manager() = default;
-
- /** @brief Constructor to create core watch object.
- * @param[in] event - Dump manager sd_event loop.
- */
- Manager(const EventPtr& event) :
- eventLoop(event.get()),
- coreWatch(eventLoop,
- IN_NONBLOCK,
- coreFileEvent,
- EPOLLIN,
- CORE_FILE_DIR,
- std::bind(
- std::mem_fn(
- &phosphor::dump::core::Manager::watchCallback),
- this, std::placeholders::_1))
- {}
+ public:
+ Manager() = delete;
+ Manager(const Manager&) = default;
+ Manager& operator=(const Manager&) = delete;
+ Manager(Manager&&) = delete;
+ Manager& operator=(Manager&&) = delete;
+ virtual ~Manager() = default;
- private:
- /** @brief Helper function for initiating dump request using
- * D-bus internal create interface.
- * @param [in] files - Core files list
- */
- void createHelper(const std::vector<std::string>& files);
+ /** @brief Constructor to create core watch object.
+ * @param[in] event - Dump manager sd_event loop.
+ */
+ Manager(const EventPtr& event) :
+ eventLoop(event.get()),
+ coreWatch(eventLoop, IN_NONBLOCK, coreFileEvent, EPOLLIN, CORE_FILE_DIR,
+ std::bind(std::mem_fn(
+ &phosphor::dump::core::Manager::watchCallback),
+ this, std::placeholders::_1))
+ {
+ }
+ private:
+ /** @brief Helper function for initiating dump request using
+ * D-bus internal create interface.
+ * @param [in] files - Core files list
+ */
+ void createHelper(const std::vector<std::string>& files);
- /** @brief Implementation of core watch call back
- * @param [in] fileInfo - map of file info path:event
- */
- void watchCallback(const UserMap& fileInfo);
+ /** @brief Implementation of core watch call back
+ * @param [in] fileInfo - map of file info path:event
+ */
+ void watchCallback(const UserMap& fileInfo);
- /** @brief sdbusplus Dump event loop */
- EventPtr eventLoop;
+ /** @brief sdbusplus Dump event loop */
+ EventPtr eventLoop;
- /** @brief Core watch object */
- Watch coreWatch;
+ /** @brief Core watch object */
+ Watch coreWatch;
};
-} // namepsace core
+} // namespace core
} // namespace dump
} // namespace phosphor
diff --git a/core_manager_main.cpp b/core_manager_main.cpp
index 4ef6095..e680c12 100644
--- a/core_manager_main.cpp
+++ b/core_manager_main.cpp
@@ -1,10 +1,11 @@
-#include <sdbusplus/bus.hpp>
-#include <phosphor-logging/elog-errors.hpp>
-
-#include "xyz/openbmc_project/Common/error.hpp"
#include "config.h"
+
#include "core_manager.hpp"
#include "watch.hpp"
+#include "xyz/openbmc_project/Common/error.hpp"
+
+#include <phosphor-logging/elog-errors.hpp>
+#include <sdbusplus/bus.hpp>
int main(int argc, char* argv[])
{
diff --git a/dump_entry.cpp b/dump_entry.cpp
index d7878c9..6048b1c 100644
--- a/dump_entry.cpp
+++ b/dump_entry.cpp
@@ -1,8 +1,9 @@
-#include <phosphor-logging/log.hpp>
-
#include "dump_entry.hpp"
+
#include "dump_manager.hpp"
+#include <phosphor-logging/log.hpp>
+
namespace phosphor
{
namespace dump
@@ -12,14 +13,14 @@ using namespace phosphor::logging;
void Entry::delete_()
{
- //Delete Dump file from Permanent location
+ // Delete Dump file from Permanent location
try
{
fs::remove_all(file.parent_path());
}
catch (fs::filesystem_error& e)
{
- //Log Error message and continue
+ // Log Error message and continue
log<level::ERR>(e.what());
}
@@ -28,4 +29,4 @@ void Entry::delete_()
}
} // namespace dump
-} // namepsace phosphor
+} // namespace phosphor
diff --git a/dump_entry.hpp b/dump_entry.hpp
index 2942704..e6b7ec5 100644
--- a/dump_entry.hpp
+++ b/dump_entry.hpp
@@ -1,14 +1,13 @@
#pragma once
-#include <experimental/filesystem>
-
-#include <sdbusplus/bus.hpp>
-#include <sdbusplus/server/object.hpp>
-
#include "xyz/openbmc_project/Dump/Entry/server.hpp"
#include "xyz/openbmc_project/Object/Delete/server.hpp"
#include "xyz/openbmc_project/Time/EpochTime/server.hpp"
+#include <experimental/filesystem>
+#include <sdbusplus/bus.hpp>
+#include <sdbusplus/server/object.hpp>
+
namespace phosphor
{
namespace dump
@@ -18,9 +17,9 @@ template <typename T>
using ServerObject = typename sdbusplus::server::object::object<T>;
using EntryIfaces = sdbusplus::server::object::object<
- sdbusplus::xyz::openbmc_project::Dump::server::Entry,
- sdbusplus::xyz::openbmc_project::Object::server::Delete,
- sdbusplus::xyz::openbmc_project::Time::server::EpochTime>;
+ sdbusplus::xyz::openbmc_project::Dump::server::Entry,
+ sdbusplus::xyz::openbmc_project::Object::server::Delete,
+ sdbusplus::xyz::openbmc_project::Time::server::EpochTime>;
namespace fs = std::experimental::filesystem;
@@ -33,55 +32,49 @@ class Manager;
*/
class Entry : public EntryIfaces
{
- public:
- Entry() = delete;
- Entry(const Entry&) = delete;
- Entry& operator=(const Entry&) = delete;
- Entry(Entry&&) = delete;
- Entry& operator=(Entry&&) = delete;
- ~Entry() = default;
+ public:
+ Entry() = delete;
+ Entry(const Entry&) = delete;
+ Entry& operator=(const Entry&) = delete;
+ Entry(Entry&&) = delete;
+ Entry& operator=(Entry&&) = delete;
+ ~Entry() = default;
- /** @brief Constructor for the Dump Entry Object
- * @param[in] bus - Bus to attach to.
- * @param[in] objPath - Object path to attach to
- * @param[in] dumpId - Dump id.
- * @param[in] timeStamp - Dump creation timestamp
- * since the epoch.
- * @param[in] fileSize - Dump file size in bytes.
- * @param[in] file - Dump file name.
- * @param[in] parent - The dump entry's parent.
- */
- Entry(sdbusplus::bus::bus& bus,
- const std::string& objPath,
- uint32_t dumpId,
- uint64_t timeStamp,
- uint64_t fileSize,
- const fs::path& file,
- Manager& parent):
- EntryIfaces(bus, objPath.c_str(), true),
- file(file),
- parent(parent),
- id(dumpId)
- {
- size(fileSize);
- elapsed(timeStamp);
- // Emit deferred signal.
- this->emit_object_added();
- };
+ /** @brief Constructor for the Dump Entry Object
+ * @param[in] bus - Bus to attach to.
+ * @param[in] objPath - Object path to attach to
+ * @param[in] dumpId - Dump id.
+ * @param[in] timeStamp - Dump creation timestamp
+ * since the epoch.
+ * @param[in] fileSize - Dump file size in bytes.
+ * @param[in] file - Dump file name.
+ * @param[in] parent - The dump entry's parent.
+ */
+ Entry(sdbusplus::bus::bus& bus, const std::string& objPath, uint32_t dumpId,
+ uint64_t timeStamp, uint64_t fileSize, const fs::path& file,
+ Manager& parent) :
+ EntryIfaces(bus, objPath.c_str(), true),
+ file(file), parent(parent), id(dumpId)
+ {
+ size(fileSize);
+ elapsed(timeStamp);
+ // Emit deferred signal.
+ this->emit_object_added();
+ };
- /** @brief Delete this d-bus object.
- */
- void delete_() override ;
+ /** @brief Delete this d-bus object.
+ */
+ void delete_() override;
- private:
- /** @Dump file name */
- fs::path file;
+ private:
+ /** @Dump file name */
+ fs::path file;
- /** @brief This entry's parent */
- Manager& parent;
+ /** @brief This entry's parent */
+ Manager& parent;
- /** @brief This entry's id */
- uint32_t id;
+ /** @brief This entry's id */
+ uint32_t id;
};
} // namespace dump
diff --git a/dump_internal.hpp b/dump_internal.hpp
index 6ef0fa0..529ca21 100644
--- a/dump_internal.hpp
+++ b/dump_internal.hpp
@@ -1,10 +1,10 @@
#pragma once
+#include "xyz/openbmc_project/Dump/Internal/Create/server.hpp"
+
#include <sdbusplus/bus.hpp>
#include <sdbusplus/server/object.hpp>
-#include "xyz/openbmc_project/Dump/Internal/Create/server.hpp"
-
namespace phosphor
{
namespace dump
@@ -15,7 +15,7 @@ namespace internal
{
using CreateIface = sdbusplus::server::object::object<
- sdbusplus::xyz::openbmc_project::Dump::Internal::server::Create>;
+ sdbusplus::xyz::openbmc_project::Dump::Internal::server::Create>;
using Mgr = phosphor::dump::Manager;
/** @class Manager
@@ -24,36 +24,34 @@ using Mgr = phosphor::dump::Manager;
*/
class Manager : public CreateIface
{
- public:
- Manager() = delete;
- Manager(const Manager&) = delete;
- Manager& operator=(const Manager&) = delete;
- Manager(Manager&&) = delete;
- Manager& operator=(Manager&&) = delete;
- virtual ~Manager() = default;
-
- /** @brief Constructor to put object onto bus at a dbus path.
- * @param[in] bus - Bus to attach to.
- * @param[in] dumpMgr - Dump Manager object
- * @param[in] path - Path to attach at.
- */
- Manager(sdbusplus::bus::bus& bus, Mgr& dumpMgr, const char* path):
- CreateIface(bus, path),
- dumpMgr(dumpMgr) {};
-
- /** @brief Implementation for Create
- * Create BMC Dump based on the Dump type.
- *
- * @param[in] type - Type of the Dump.
- * @param[in] fullPaths - List of absolute paths to the files
- * to be included as part of Dump package.
- */
- void create(
- Type type,
- std::vector<std::string> fullPaths) override;
- private:
- /** @brief Dump Manager object. */
- Mgr& dumpMgr;
+ public:
+ Manager() = delete;
+ Manager(const Manager&) = delete;
+ Manager& operator=(const Manager&) = delete;
+ Manager(Manager&&) = delete;
+ Manager& operator=(Manager&&) = delete;
+ virtual ~Manager() = default;
+
+ /** @brief Constructor to put object onto bus at a dbus path.
+ * @param[in] bus - Bus to attach to.
+ * @param[in] dumpMgr - Dump Manager object
+ * @param[in] path - Path to attach at.
+ */
+ Manager(sdbusplus::bus::bus& bus, Mgr& dumpMgr, const char* path) :
+ CreateIface(bus, path), dumpMgr(dumpMgr){};
+
+ /** @brief Implementation for Create
+ * Create BMC Dump based on the Dump type.
+ *
+ * @param[in] type - Type of the Dump.
+ * @param[in] fullPaths - List of absolute paths to the files
+ * to be included as part of Dump package.
+ */
+ void create(Type type, std::vector<std::string> fullPaths) override;
+
+ private:
+ /** @brief Dump Manager object. */
+ Mgr& dumpMgr;
};
} // namespace internal
diff --git a/dump_manager.cpp b/dump_manager.cpp
index 15df65b..d9326e0 100644
--- a/dump_manager.cpp
+++ b/dump_manager.cpp
@@ -1,15 +1,17 @@
-#include <unistd.h>
-#include <sys/inotify.h>
-#include <regex>
-
-#include <phosphor-logging/elog.hpp>
-#include <phosphor-logging/elog-errors.hpp>
+#include "config.h"
#include "dump_manager.hpp"
+
#include "dump_internal.hpp"
#include "xyz/openbmc_project/Common/error.hpp"
#include "xyz/openbmc_project/Dump/Create/error.hpp"
-#include "config.h"
+
+#include <sys/inotify.h>
+#include <unistd.h>
+
+#include <phosphor-logging/elog-errors.hpp>
+#include <phosphor-logging/elog.hpp>
+#include <regex>
namespace phosphor
{
@@ -22,14 +24,12 @@ using namespace phosphor::logging;
namespace internal
{
-void Manager::create(
- Type type,
- std::vector<std::string> fullPaths)
+void Manager::create(Type type, std::vector<std::string> fullPaths)
{
dumpMgr.phosphor::dump::Manager::captureDump(type, fullPaths);
}
-} //namepsace internal
+} // namespace internal
uint32_t Manager::createDump()
{
@@ -37,17 +37,16 @@ uint32_t Manager::createDump()
return captureDump(Type::UserRequested, paths);
}
-uint32_t Manager::captureDump(
- Type type,
- const std::vector<std::string>& fullPaths)
+uint32_t Manager::captureDump(Type type,
+ const std::vector<std::string>& fullPaths)
{
- //Type to dreport type string map
- static const std::map<Type, std::string> typeMap =
- {{Type::ApplicationCored, "core"},
- {Type::UserRequested, "user"},
- {Type::InternalFailure, "elog"}};
+ // Type to dreport type string map
+ static const std::map<Type, std::string> typeMap = {
+ {Type::ApplicationCored, "core"},
+ {Type::UserRequested, "user"},
+ {Type::InternalFailure, "elog"}};
- //Get Dump size.
+ // Get Dump size.
auto size = getAllowedSize();
pid_t pid = fork();
@@ -55,24 +54,18 @@ uint32_t Manager::captureDump(
if (pid == 0)
{
fs::path dumpPath(BMC_DUMP_PATH);
- auto id = std::to_string(lastEntryId + 1);
+ auto id = std::to_string(lastEntryId + 1);
dumpPath /= id;
- //get dreport type map entry
+ // get dreport type map entry
auto tempType = typeMap.find(type);
- execl("/usr/bin/dreport",
- "dreport",
- "-d", dumpPath.c_str(),
- "-i", id.c_str(),
- "-s", std::to_string(size).c_str(),
- "-q",
- "-v",
- "-p", fullPaths.empty() ? "" : fullPaths.front().c_str(),
- "-t", tempType->second.c_str(),
- nullptr);
-
- //dreport script execution is failed.
+ execl("/usr/bin/dreport", "dreport", "-d", dumpPath.c_str(), "-i",
+ id.c_str(), "-s", std::to_string(size).c_str(), "-q", "-v", "-p",
+ fullPaths.empty() ? "" : fullPaths.front().c_str(), "-t",
+ tempType->second.c_str(), nullptr);
+
+ // dreport script execution is failed.
auto error = errno;
log<level::ERR>("Error occurred during dreport function execution",
entry("ERRNO=%d", error));
@@ -80,12 +73,8 @@ uint32_t Manager::captureDump(
}
else if (pid > 0)
{
- auto rc = sd_event_add_child(eventLoop.get(),
- nullptr,
- pid,
- WEXITED | WSTOPPED,
- callback,
- nullptr);
+ auto rc = sd_event_add_child(eventLoop.get(), nullptr, pid,
+ WEXITED | WSTOPPED, callback, nullptr);
if (0 > rc)
{
// Failed to add to event loop
@@ -97,8 +86,7 @@ uint32_t Manager::captureDump(
else
{
auto error = errno;
- log<level::ERR>("Error occurred during fork",
- entry("ERRNO=%d", error));
+ log<level::ERR>("Error occurred during fork", entry("ERRNO=%d", error));
elog<InternalFailure>();
}
@@ -107,16 +95,15 @@ uint32_t Manager::captureDump(
void Manager::createEntry(const fs::path& file)
{
- //Dump File Name format obmcdump_ID_EPOCHTIME.EXT
- static constexpr auto ID_POS = 1;
- static constexpr auto EPOCHTIME_POS = 2;
+ // Dump File Name format obmcdump_ID_EPOCHTIME.EXT
+ static constexpr auto ID_POS = 1;
+ static constexpr auto EPOCHTIME_POS = 2;
std::regex file_regex("obmcdump_([0-9]+)_([0-9]+).([a-zA-Z0-9]+)");
std::smatch match;
std::string name = file.filename();
- if (!((std::regex_search(name, match, file_regex)) &&
- (match.size() > 0)))
+ if (!((std::regex_search(name, match, file_regex)) && (match.size() > 0)))
{
log<level::ERR>("Invalid Dump file name",
entry("FILENAME=%s", file.filename().c_str()));
@@ -130,17 +117,12 @@ void Manager::createEntry(const fs::path& file)
{
auto id = stoul(idString);
// Entry Object path.
- auto objPath = fs::path(OBJ_ENTRY) / std::to_string(id);
-
- entries.insert(std::make_pair(id,
- std::make_unique<Entry>(
- bus,
- objPath.c_str(),
- id,
- stoull(msString),
- fs::file_size(file),
- file,
- *this)));
+ auto objPath = fs::path(OBJ_ENTRY) / std::to_string(id);
+
+ entries.insert(std::make_pair(
+ id,
+ std::make_unique<Entry>(bus, objPath.c_str(), id, stoull(msString),
+ fs::file_size(file), file, *this)));
}
catch (const std::invalid_argument& e)
{
@@ -181,25 +163,18 @@ void Manager::watchCallback(const UserMap& fileInfo)
else if ((IN_CREATE == i.second) && fs::is_directory(i.first))
{
auto watchObj = std::make_unique<Watch>(
- eventLoop,
- IN_NONBLOCK,
- IN_CLOSE_WRITE,
- EPOLLIN,
- i.first,
- std::bind(
- std::mem_fn(
- &phosphor::dump::Manager::watchCallback),
- this, std::placeholders::_1));
+ eventLoop, IN_NONBLOCK, IN_CLOSE_WRITE, EPOLLIN, i.first,
+ std::bind(std::mem_fn(&phosphor::dump::Manager::watchCallback),
+ this, std::placeholders::_1));
childWatchMap.emplace(i.first, std::move(watchObj));
}
-
}
}
void Manager::removeWatch(const fs::path& path)
{
- //Delete Watch entry from map.
+ // Delete Watch entry from map.
childWatchMap.erase(path);
}
@@ -211,20 +186,20 @@ void Manager::restore()
return;
}
- //Dump file path: <BMC_DUMP_PATH>/<id>/<filename>
+ // Dump file path: <BMC_DUMP_PATH>/<id>/<filename>
for (const auto& p : fs::directory_iterator(dir))
{
auto idStr = p.path().filename().string();
- //Consider only directory's with dump id as name.
- //Note: As per design one file per directory.
+ // Consider only directory's with dump id as name.
+ // Note: As per design one file per directory.
if ((fs::is_directory(p.path())) &&
std::all_of(idStr.begin(), idStr.end(), ::isdigit))
{
- lastEntryId = std::max(lastEntryId,
- static_cast<uint32_t>(std::stoul(idStr)));
+ lastEntryId =
+ std::max(lastEntryId, static_cast<uint32_t>(std::stoul(idStr)));
auto fileIt = fs::directory_iterator(p.path());
- //Create dump entry d-bus object.
+ // Create dump entry d-bus object.
if (fileIt != fs::end(fileIt))
{
createEntry(fileIt->path());
@@ -240,7 +215,7 @@ size_t Manager::getAllowedSize()
auto size = 0;
- //Get current size of the dump directory.
+ // Get current size of the dump directory.
for (const auto& p : fs::recursive_directory_iterator(BMC_DUMP_PATH))
{
if (!fs::is_directory(p))
@@ -249,17 +224,17 @@ size_t Manager::getAllowedSize()
}
}
- //Convert size into KB
+ // Convert size into KB
size = size / 1024;
- //Set the Dump size to Maximum if the free space is greater than
- //Dump max size otherwise return the available size.
+ // Set the Dump size to Maximum if the free space is greater than
+ // Dump max size otherwise return the available size.
size = (size > BMC_DUMP_TOTAL_SIZE ? 0 : BMC_DUMP_TOTAL_SIZE - size);
if (size < BMC_DUMP_MIN_SPACE_REQD)
{
- //Reached to maximum limit
+ // Reached to maximum limit
elog<QuotaExceeded>(Reason("Not enough space: Delete old dumps"));
}
if (size > BMC_DUMP_MAX_SIZE)
@@ -270,5 +245,5 @@ size_t Manager::getAllowedSize()
return size;
}
-} //namespace dump
-} //namespace phosphor
+} // namespace dump
+} // namespace phosphor
diff --git a/dump_manager.hpp b/dump_manager.hpp
index f12d7ff..f414752 100644
--- a/dump_manager.hpp
+++ b/dump_manager.hpp
@@ -1,17 +1,17 @@
#pragma once
-#include <experimental/filesystem>
-
-#include <sdbusplus/bus.hpp>
-#include <sdbusplus/server/object.hpp>
-#include <xyz/openbmc_project/Dump/Create/server.hpp>
+#include "config.h"
-#include "xyz/openbmc_project/Dump/Internal/Create/server.hpp"
-#include "xyz/openbmc_project/Collection/DeleteAll/server.hpp"
#include "dump_entry.hpp"
#include "dump_utils.hpp"
#include "watch.hpp"
-#include "config.h"
+#include "xyz/openbmc_project/Collection/DeleteAll/server.hpp"
+#include "xyz/openbmc_project/Dump/Internal/Create/server.hpp"
+
+#include <experimental/filesystem>
+#include <sdbusplus/bus.hpp>
+#include <sdbusplus/server/object.hpp>
+#include <xyz/openbmc_project/Dump/Create/server.hpp>
namespace phosphor
{
@@ -29,9 +29,9 @@ using UserMap = phosphor::dump::inotify::UserMap;
using Type =
sdbusplus::xyz::openbmc_project::Dump::Internal::server::Create::Type;
-using CreateIface = sdbusplus::server::object::object <
- sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll,
- sdbusplus::xyz::openbmc_project::Dump::server::Create >;
+using CreateIface = sdbusplus::server::object::object<
+ sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll,
+ sdbusplus::xyz::openbmc_project::Dump::server::Create>;
namespace fs = std::experimental::filesystem;
@@ -45,131 +45,121 @@ using Watch = phosphor::dump::inotify::Watch;
*/
class Manager : public CreateIface
{
- friend class internal::Manager;
- friend class Entry;
-
- public:
- Manager() = delete;
- Manager(const Manager&) = default;
- Manager& operator=(const Manager&) = delete;
- Manager(Manager&&) = delete;
- Manager& operator=(Manager&&) = delete;
- virtual ~Manager() = default;
-
- /** @brief Constructor to put object onto bus at a dbus path.
- * @param[in] bus - Bus to attach to.
- * @param[in] event - Dump manager sd_event loop.
- * @param[in] path - Path to attach at.
- */
- Manager(sdbusplus::bus::bus& bus,
- const EventPtr& event, const char* path) :
- CreateIface(bus, path),
- bus(bus),
- eventLoop(event.get()),
- lastEntryId(0),
- dumpWatch(eventLoop,
- IN_NONBLOCK,
- IN_CLOSE_WRITE | IN_CREATE,
- EPOLLIN,
- BMC_DUMP_PATH,
- std::bind(
- std::mem_fn(
- &phosphor::dump::Manager::watchCallback),
- this, std::placeholders::_1))
- {}
-
- /** @brief Implementation for CreateDump
- * Method to create Dump.
- *
- * @return id - The Dump entry id number.
- */
- uint32_t createDump() override;
-
- /** @brief Implementation of dump watch call back
- * @param [in] fileInfo - map of file info path:event
- */
- void watchCallback(const UserMap& fileInfo);
-
- /** @brief Construct dump d-bus objects from their persisted
- * representations.
- */
- void restore();
-
- private:
- /** @brief Create Dump entry d-bus object
- * @param[in] fullPath - Full path of the Dump file name
- */
- void createEntry(const fs::path& fullPath);
-
- /** @brief Capture BMC Dump based on the Dump type.
- * @param[in] type - Type of the Dump.
- * @param[in] fullPaths - List of absolute paths to the files
- * to be included as part of Dump package.
- * @return id - The Dump entry id number.
- */
- uint32_t captureDump(
- Type type,
- const std::vector<std::string>& fullPaths);
-
- /** @brief Erase specified entry d-bus object
- *
- * @param[in] entryId - unique identifier of the entry
- */
- void erase(uint32_t entryId);
-
- /** @brief Erase all BMC dump entries and Delete all Dump files
- * from Permanent location
- *
- */
- void deleteAll() override;
-
- /** @brief sd_event_add_child callback
- *
- * @param[in] s - event source
- * @param[in] si - signal info
- * @param[in] userdata - pointer to Watch object
- *
- * @returns 0 on success, -1 on fail
- */
- static int callback(sd_event_source* s,
- const siginfo_t* si,
- void* userdata)
- {
- //No specific action required in
- //the sd_event_add_child callback.
- return 0;
- }
- /** @brief Remove specified watch object pointer from the
- * watch map and associated entry from the map.
- * @param[in] path - unique identifier of the map
- */
- void removeWatch(const fs::path& path);
-
- /** @brief Calculate per dump allowed size based on the available
- * size in the dump location.
- * @returns dump size in kilobytes.
- */
- size_t getAllowedSize();
-
- /** @brief sdbusplus DBus bus connection. */
- sdbusplus::bus::bus& bus;
-
- /** @brief sdbusplus Dump event loop */
- EventPtr eventLoop;
-
- /** @brief Dump Entry dbus objects map based on entry id */
- std::map<uint32_t, std::unique_ptr<Entry>> entries;
-
- /** @brief Id of the last Dump entry */
- uint32_t lastEntryId;
-
- /** @brief Dump main watch object */
- Watch dumpWatch;
-
- /** @brief Child directory path and its associated watch object map
- * [path:watch object]
- */
- std::map<fs::path, std::unique_ptr<Watch>> childWatchMap;
+ friend class internal::Manager;
+ friend class Entry;
+
+ public:
+ Manager() = delete;
+ Manager(const Manager&) = default;
+ Manager& operator=(const Manager&) = delete;
+ Manager(Manager&&) = delete;
+ Manager& operator=(Manager&&) = delete;
+ virtual ~Manager() = default;
+
+ /** @brief Constructor to put object onto bus at a dbus path.
+ * @param[in] bus - Bus to attach to.
+ * @param[in] event - Dump manager sd_event loop.
+ * @param[in] path - Path to attach at.
+ */
+ Manager(sdbusplus::bus::bus& bus, const EventPtr& event, const char* path) :
+ CreateIface(bus, path), bus(bus), eventLoop(event.get()),
+ lastEntryId(0),
+ dumpWatch(
+ eventLoop, IN_NONBLOCK, IN_CLOSE_WRITE | IN_CREATE, EPOLLIN,
+ BMC_DUMP_PATH,
+ std::bind(std::mem_fn(&phosphor::dump::Manager::watchCallback),
+ this, std::placeholders::_1))
+ {
+ }
+
+ /** @brief Implementation for CreateDump
+ * Method to create Dump.
+ *
+ * @return id - The Dump entry id number.
+ */
+ uint32_t createDump() override;
+
+ /** @brief Implementation of dump watch call back
+ * @param [in] fileInfo - map of file info path:event
+ */
+ void watchCallback(const UserMap& fileInfo);
+
+ /** @brief Construct dump d-bus objects from their persisted
+ * representations.
+ */
+ void restore();
+
+ private:
+ /** @brief Create Dump entry d-bus object
+ * @param[in] fullPath - Full path of the Dump file name
+ */
+ void createEntry(const fs::path& fullPath);
+
+ /** @brief Capture BMC Dump based on the Dump type.
+ * @param[in] type - Type of the Dump.
+ * @param[in] fullPaths - List of absolute paths to the files
+ * to be included as part of Dump package.
+ * @return id - The Dump entry id number.
+ */
+ uint32_t captureDump(Type type, const std::vector<std::string>& fullPaths);
+
+ /** @brief Erase specified entry d-bus object
+ *
+ * @param[in] entryId - unique identifier of the entry
+ */
+ void erase(uint32_t entryId);
+
+ /** @brief Erase all BMC dump entries and Delete all Dump files
+ * from Permanent location
+ *
+ */
+ void deleteAll() override;
+
+ /** @brief sd_event_add_child callback
+ *
+ * @param[in] s - event source
+ * @param[in] si - signal info
+ * @param[in] userdata - pointer to Watch object
+ *
+ * @returns 0 on success, -1 on fail
+ */
+ static int callback(sd_event_source* s, const siginfo_t* si, void* userdata)
+ {
+ // No specific action required in
+ // the sd_event_add_child callback.
+ return 0;
+ }
+ /** @brief Remove specified watch object pointer from the
+ * watch map and associated entry from the map.
+ * @param[in] path - unique identifier of the map
+ */
+ void removeWatch(const fs::path& path);
+
+ /** @brief Calculate per dump allowed size based on the available
+ * size in the dump location.
+ * @returns dump size in kilobytes.
+ */
+ size_t getAllowedSize();
+
+ /** @brief sdbusplus DBus bus connection. */
+ sdbusplus::bus::bus& bus;
+
+ /** @brief sdbusplus Dump event loop */
+ EventPtr eventLoop;
+
+ /** @brief Dump Entry dbus objects map based on entry id */
+ std::map<uint32_t, std::unique_ptr<Entry>> entries;
+
+ /** @brief Id of the last Dump entry */
+ uint32_t lastEntryId;
+
+ /** @brief Dump main watch object */
+ Watch dumpWatch;
+
+ /** @brief Child directory path and its associated watch object map
+ * [path:watch object]
+ */
+ std::map<fs::path, std::unique_ptr<Watch>> childWatchMap;
};
} // namespace dump
diff --git a/dump_manager_main.cpp b/dump_manager_main.cpp
index 174adc3..fe1a147 100644
--- a/dump_manager_main.cpp
+++ b/dump_manager_main.cpp
@@ -1,12 +1,13 @@
-#include <sdbusplus/bus.hpp>
-#include <phosphor-logging/elog-errors.hpp>
-
-#include "xyz/openbmc_project/Common/error.hpp"
#include "config.h"
-#include "dump_manager.hpp"
+
#include "dump_internal.hpp"
-#include "watch.hpp"
+#include "dump_manager.hpp"
#include "elog_watch.hpp"
+#include "watch.hpp"
+#include "xyz/openbmc_project/Common/error.hpp"
+
+#include <phosphor-logging/elog-errors.hpp>
+#include <sdbusplus/bus.hpp>
int main(int argc, char* argv[])
{
@@ -34,7 +35,7 @@ int main(int argc, char* argv[])
try
{
phosphor::dump::Manager manager(bus, eventP, DUMP_OBJPATH);
- //Restore dump d-bus objects.
+ // Restore dump d-bus objects.
manager.restore();
phosphor::dump::internal::Manager mgr(bus, manager, OBJ_INTERNAL);
phosphor::dump::elog::Watch eWatch(bus, mgr);
diff --git a/dump_serialize.cpp b/dump_serialize.cpp
index 13a8b7e..799b142 100644
--- a/dump_serialize.cpp
+++ b/dump_serialize.cpp
@@ -1,11 +1,10 @@
-#include <cereal/types/set.hpp>
+#include "dump_serialize.hpp"
+
#include <cereal/archives/binary.hpp>
+#include <cereal/types/set.hpp>
#include <fstream>
-
#include <phosphor-logging/log.hpp>
-#include "dump_serialize.hpp"
-
namespace phosphor
{
namespace dump
@@ -35,7 +34,7 @@ bool deserialize(const fs::path& path, ElogList& list)
}
return false;
}
- catch(cereal::Exception& e)
+ catch (cereal::Exception& e)
{
log<level::ERR>(e.what());
fs::remove(path);
diff --git a/dump_serialize.hpp b/dump_serialize.hpp
index ecfc934..9199da7 100644
--- a/dump_serialize.hpp
+++ b/dump_serialize.hpp
@@ -1,9 +1,10 @@
#pragma once
-#include <experimental/filesystem>
+#include "config.h"
#include "elog_watch.hpp"
-#include "config.h"
+
+#include <experimental/filesystem>
namespace phosphor
{
diff --git a/dump_utils.hpp b/dump_utils.hpp
index e985112..ba351e1 100644
--- a/dump_utils.hpp
+++ b/dump_utils.hpp
@@ -1,8 +1,9 @@
#pragma once
-#include <memory>
-#include <unistd.h>
#include <systemd/sd-event.h>
+#include <unistd.h>
+
+#include <memory>
namespace phosphor
{
@@ -25,35 +26,37 @@ using EventPtr = std::unique_ptr<sd_event, EventDeleter>;
*/
struct CustomFd
{
- private:
- /** @brief File descriptor */
- int fd = -1;
-
- public:
- CustomFd() = delete;
- CustomFd(const CustomFd&) = delete;
- CustomFd& operator=(const CustomFd&) = delete;
- CustomFd(CustomFd&&) = delete;
- CustomFd& operator=(CustomFd&&) = delete;
-
- /** @brief Saves File descriptor and uses it to do file operation
- *
- * @param[in] fd - File descriptor
- */
- CustomFd(int fd) : fd(fd) {}
-
- ~CustomFd()
- {
- if (fd >= 0)
- {
- close(fd);
- }
- }
+ private:
+ /** @brief File descriptor */
+ int fd = -1;
+
+ public:
+ CustomFd() = delete;
+ CustomFd(const CustomFd&) = delete;
+ CustomFd& operator=(const CustomFd&) = delete;
+ CustomFd(CustomFd&&) = delete;
+ CustomFd& operator=(CustomFd&&) = delete;
+
+ /** @brief Saves File descriptor and uses it to do file operation
+ *
+ * @param[in] fd - File descriptor
+ */
+ CustomFd(int fd) : fd(fd)
+ {
+ }
- int operator()() const
+ ~CustomFd()
+ {
+ if (fd >= 0)
{
- return fd;
+ close(fd);
}
+ }
+
+ int operator()() const
+ {
+ return fd;
+ }
};
} // namespace dump
diff --git a/elog_watch.cpp b/elog_watch.cpp
index 6817f8b..7369783 100644
--- a/elog_watch.cpp
+++ b/elog_watch.cpp
@@ -1,12 +1,14 @@
-#include <cereal/cereal.hpp>
-#include <phosphor-logging/elog.hpp>
-#include <sdbusplus/exception.hpp>
+#include "config.h"
#include "elog_watch.hpp"
+
#include "dump_internal.hpp"
-#include "xyz/openbmc_project/Dump/Create/error.hpp"
#include "dump_serialize.hpp"
-#include "config.h"
+#include "xyz/openbmc_project/Dump/Create/error.hpp"
+
+#include <cereal/cereal.hpp>
+#include <phosphor-logging/elog.hpp>
+#include <sdbusplus/exception.hpp>
// Register class version with Cereal
CEREAL_CLASS_VERSION(phosphor::dump::elog::Watch, CLASS_VERSION);
@@ -29,22 +31,18 @@ using AttributeMap = std::map<AttributeName, Attributes>;
using PropertyName = std::string;
using PropertyMap = std::map<PropertyName, AttributeMap>;
-Watch::Watch(sdbusplus::bus::bus& bus, IMgr& iMgr):
+Watch::Watch(sdbusplus::bus::bus& bus, IMgr& iMgr) :
iMgr(iMgr),
- addMatch(
- bus,
- sdbusplus::bus::match::rules::interfacesAdded() +
- sdbusplus::bus::match::rules::path_namespace(
- OBJ_LOGGING),
- std::bind(std::mem_fn(&Watch::addCallback),
- this, std::placeholders::_1)),
- delMatch(
- bus,
- sdbusplus::bus::match::rules::interfacesRemoved() +
- sdbusplus::bus::match::rules::path_namespace(
- OBJ_LOGGING),
- std::bind(std::mem_fn(&Watch::delCallback),
- this, std::placeholders::_1))
+ addMatch(bus,
+ sdbusplus::bus::match::rules::interfacesAdded() +
+ sdbusplus::bus::match::rules::path_namespace(OBJ_LOGGING),
+ std::bind(std::mem_fn(&Watch::addCallback), this,
+ std::placeholders::_1)),
+ delMatch(bus,
+ sdbusplus::bus::match::rules::interfacesRemoved() +
+ sdbusplus::bus::match::rules::path_namespace(OBJ_LOGGING),
+ std::bind(std::mem_fn(&Watch::delCallback), this,
+ std::placeholders::_1))
{
fs::path file(ELOG_ID_PERSIST_PATH);
@@ -81,7 +79,7 @@ void Watch::addCallback(sdbusplus::message::message& msg)
std::size_t found = objectPath.str.find("entry");
if (found == std::string::npos)
{
- //Not a new error entry skip
+ // Not a new error entry skip
return;
}
@@ -90,7 +88,7 @@ void Watch::addCallback(sdbusplus::message::message& msg)
auto search = elogList.find(eId);
if (search != elogList.end())
{
- //elog exists in the list, Skip the dump
+ // elog exists in the list, Skip the dump
return;
}
@@ -110,13 +108,13 @@ void Watch::addCallback(sdbusplus::message::message& msg)
sdbusplus::message::variant_ns::get<PropertyName>(attr->second);
if (data.empty())
{
- //No Message skip
+ // No Message skip
return;
}
if (data != INTERNAL_FAILURE)
{
- //Not a InternalFailure, skip
+ // Not a InternalFailure, skip
return;
}
@@ -125,18 +123,18 @@ void Watch::addCallback(sdbusplus::message::message& msg)
try
{
- //Save the elog information. This is to avoid dump requests
- //in elog restore path.
+ // Save the elog information. This is to avoid dump requests
+ // in elog restore path.
elogList.insert(eId);
phosphor::dump::elog::serialize(elogList);
- //Call internal create function to initiate dump
+ // Call internal create function to initiate dump
iMgr.IMgr::create(Type::InternalFailure, fullPaths);
}
catch (QuotaExceeded& e)
{
- //No action now
+ // No action now
}
return;
}
@@ -156,10 +154,10 @@ void Watch::delCallback(sdbusplus::message::message& msg)
return;
}
- //Get elog id
+ // Get elog id
auto eId = getEid(objectPath);
- //Delete the elog entry from the list and serialize
+ // Delete the elog entry from the list and serialize
auto search = elogList.find(eId);
if (search != elogList.end())
{
@@ -168,6 +166,6 @@ void Watch::delCallback(sdbusplus::message::message& msg)
}
}
-}//namespace elog
-}//namespace dump
-}//namespace phosphor
+} // namespace elog
+} // namespace dump
+} // namespace phosphor
diff --git a/elog_watch.hpp b/elog_watch.hpp
index 4730311..2c808cf 100644
--- a/elog_watch.hpp
+++ b/elog_watch.hpp
@@ -1,13 +1,13 @@
#pragma once
-#include <set>
-#include <cereal/access.hpp>
+#include "config.h"
+
+#include "dump_manager.hpp"
+#include <cereal/access.hpp>
#include <sdbusplus/bus.hpp>
#include <sdbusplus/server.hpp>
-
-#include "config.h"
-#include "dump_manager.hpp"
+#include <set>
namespace phosphor
{
@@ -27,74 +27,74 @@ using ElogList = std::set<EId>;
*/
class Watch
{
- public:
- Watch() = delete;
- ~Watch() = default;
- Watch(const Watch&) = delete;
- Watch& operator=(const Watch&) = delete;
- Watch(Watch&&) = default;
- Watch& operator=(Watch&&) = default;
-
- /** @brief constructs watch for elog add and delete signals.
- * @param[in] bus - The Dbus bus object
- * @param[in] intMgr - Dump internal Manager object
- */
- Watch(sdbusplus::bus::bus& bus, IMgr& iMgr);
- private:
-
- friend class cereal::access;
-
- /** @brief Function required by Cereal to perform serialization.
- * @tparam Archive - Cereal archive type (binary in our case).
- * @param[in] a - reference to Cereal archive.
- * @param[in] version - Class version that enables handling
- * a serialized data across code levels
- */
- template<class Archive>
- void serialize(Archive& a, const std::uint32_t version)
- {
- a(elogList);
-
- //TODO: openbmc/phosphor-debug-collector#1
- // Split into load/save so that it enables
- // version compare during serialization
- }
-
- /** @brief Callback function for error log add.
- * @details InternalError type error message initiates
- * Internal error type dump request.
- * @param[in] msg - Data associated with subscribed signal
- */
- void addCallback(sdbusplus::message::message& msg);
-
- /** @brief Callback function for error log delete.
- * @param[in] msg - Data associated with subscribed signal
- */
- void delCallback(sdbusplus::message::message& msg);
-
- /** @brief get elog ID from elog entry object string.
- * @param[in] objectPath - elog entry object path.
- * @return - elog id.
- */
- inline EId getEid(const std::string& objectPath)
- {
- fs::path path(objectPath);
- return std::stoul(path.filename());
- }
-
- /** @brief Dump internal Manager object. */
- IMgr& iMgr;
-
- /** @brief sdbusplus signal match for elog add */
- sdbusplus::bus::match_t addMatch;
-
- /** @brief sdbusplus signal match for elog delete */
- sdbusplus::bus::match_t delMatch;
-
- /** @brief List of elog ids, which have associated dumps created */
- ElogList elogList;
+ public:
+ Watch() = delete;
+ ~Watch() = default;
+ Watch(const Watch&) = delete;
+ Watch& operator=(const Watch&) = delete;
+ Watch(Watch&&) = default;
+ Watch& operator=(Watch&&) = default;
+
+ /** @brief constructs watch for elog add and delete signals.
+ * @param[in] bus - The Dbus bus object
+ * @param[in] intMgr - Dump internal Manager object
+ */
+ Watch(sdbusplus::bus::bus& bus, IMgr& iMgr);
+
+ private:
+ friend class cereal::access;
+
+ /** @brief Function required by Cereal to perform serialization.
+ * @tparam Archive - Cereal archive type (binary in our case).
+ * @param[in] a - reference to Cereal archive.
+ * @param[in] version - Class version that enables handling
+ * a serialized data across code levels
+ */
+ template <class Archive>
+ void serialize(Archive& a, const std::uint32_t version)
+ {
+ a(elogList);
+
+ // TODO: openbmc/phosphor-debug-collector#1
+ // Split into load/save so that it enables
+ // version compare during serialization
+ }
+
+ /** @brief Callback function for error log add.
+ * @details InternalError type error message initiates
+ * Internal error type dump request.
+ * @param[in] msg - Data associated with subscribed signal
+ */
+ void addCallback(sdbusplus::message::message& msg);
+
+ /** @brief Callback function for error log delete.
+ * @param[in] msg - Data associated with subscribed signal
+ */
+ void delCallback(sdbusplus::message::message& msg);
+
+ /** @brief get elog ID from elog entry object string.
+ * @param[in] objectPath - elog entry object path.
+ * @return - elog id.
+ */
+ inline EId getEid(const std::string& objectPath)
+ {
+ fs::path path(objectPath);
+ return std::stoul(path.filename());
+ }
+
+ /** @brief Dump internal Manager object. */
+ IMgr& iMgr;
+
+ /** @brief sdbusplus signal match for elog add */
+ sdbusplus::bus::match_t addMatch;
+
+ /** @brief sdbusplus signal match for elog delete */
+ sdbusplus::bus::match_t delMatch;
+
+ /** @brief List of elog ids, which have associated dumps created */
+ ElogList elogList;
};
-}//namespace elog
-}//namespace dump
-}//namespace phosphor
+} // namespace elog
+} // namespace dump
+} // namespace phosphor
diff --git a/watch.cpp b/watch.cpp
index 5d05e9c..dfee3b3 100644
--- a/watch.cpp
+++ b/watch.cpp
@@ -1,7 +1,8 @@
-#include <phosphor-logging/elog-errors.hpp>
+#include "watch.hpp"
#include "xyz/openbmc_project/Common/error.hpp"
-#include "watch.hpp"
+
+#include <phosphor-logging/elog-errors.hpp>
namespace phosphor
{
@@ -22,17 +23,10 @@ Watch::~Watch()
}
}
-Watch::Watch(const EventPtr& eventObj,
- const int flags,
- const uint32_t mask,
- const uint32_t events,
- const fs::path& path,
- UserType userFunc):
+Watch::Watch(const EventPtr& eventObj, const int flags, const uint32_t mask,
+ const uint32_t events, const fs::path& path, UserType userFunc) :
flags(flags),
- mask(mask),
- events(events),
- path(path),
- fd(inotifyInit()),
+ mask(mask), events(events), path(path), fd(inotifyInit()),
userFunc(userFunc)
{
// Check if watch DIR exists.
@@ -52,12 +46,8 @@ Watch::Watch(const EventPtr& eventObj,
elog<InternalFailure>();
}
- auto rc = sd_event_add_io(eventObj.get(),
- nullptr,
- fd(),
- events,
- callback,
- this);
+ auto rc =
+ sd_event_add_io(eventObj.get(), nullptr, fd(), events, callback, this);
if (0 > rc)
{
// Failed to add to event loop
@@ -82,9 +72,7 @@ int Watch::inotifyInit()
return fd;
}
-int Watch::callback(sd_event_source* s,
- int fd,
- uint32_t revents,
+int Watch::callback(sd_event_source* s, int fd, uint32_t revents,
void* userdata)
{
auto userData = static_cast<Watch*>(userdata);
@@ -94,15 +82,15 @@ int Watch::callback(sd_event_source* s,
return 0;
}
- //Maximum inotify events supported in the buffer
+ // Maximum inotify events supported in the buffer
constexpr auto maxBytes = sizeof(struct inotify_event) + NAME_MAX + 1;
uint8_t buffer[maxBytes];
auto bytes = read(fd, buffer, maxBytes);
if (0 > bytes)
{
- //Failed to read inotify event
- //Report error and return
+ // Failed to read inotify event
+ // Report error and return
auto error = errno;
log<level::ERR>("Error occurred during the read",
entry("ERRNO=%d", error));
@@ -121,14 +109,13 @@ int Watch::callback(sd_event_source* s,
if (mask)
{
- userMap.emplace(
- (userData->path / event->name), mask);
+ userMap.emplace((userData->path / event->name), mask);
}
offset += offsetof(inotify_event, name) + event->len;
}
- //Call user call back function in case valid data in the map
+ // Call user call back function in case valid data in the map
if (!userMap.empty())
{
userData->userFunc(userMap);
diff --git a/watch.hpp b/watch.hpp
index da1ffad..5452b20 100644
--- a/watch.hpp
+++ b/watch.hpp
@@ -1,13 +1,14 @@
#pragma once
+#include "dump_utils.hpp"
+
+#include <sys/inotify.h>
+#include <systemd/sd-event.h>
+
#include <experimental/filesystem>
#include <functional>
-#include <systemd/sd-event.h>
-#include <sys/inotify.h>
#include <map>
-#include "dump_utils.hpp"
-
namespace phosphor
{
namespace dump
@@ -17,10 +18,10 @@ namespace inotify
namespace fs = std::experimental::filesystem;
-//User specific call back function input map(path:event) type.
+// User specific call back function input map(path:event) type.
using UserMap = std::map<fs::path, uint32_t>;
-//User specific callback function wrapper type.
+// User specific callback function wrapper type.
using UserType = std::function<void(const UserMap&)>;
/** @class Watch
@@ -33,72 +34,66 @@ using UserType = std::function<void(const UserMap&)>;
*/
class Watch
{
- public:
- /** @brief ctor - hook inotify watch with sd-event
- *
- * @param[in] eventObj - Event loop object
- * @param[in] flags - inotify flags
- * @param[in] mask - Mask of events
- * @param[in] events - Events to be watched
- * @param[in] path - File path to be watched
- * @param[in] userFunc - User specific callback fnction wrapper.
- *
- */
- Watch(const EventPtr& eventObj,
- int flags,
- uint32_t mask,
- uint32_t events,
- const fs::path& path,
- UserType userFunc);
-
- Watch(const Watch&) = delete;
- Watch& operator=(const Watch&) = delete;
- Watch(Watch&&) = default;
- Watch& operator=(Watch&&) = default;
-
- /* @brief dtor - remove inotify watch and close fd's */
- ~Watch();
-
- private:
- /** @brief sd-event callback.
- * @details Collects the files and event info and call the
- * appropriate user function for further action.
- *
- * @param[in] s - event source, floating (unused) in our case
- * @param[in] fd - inotify fd
- * @param[in] revents - events that matched for fd
- * @param[in] userdata - pointer to Watch object
- *
- * @returns 0 on success, -1 on fail
- */
- static int callback(sd_event_source* s,
- int fd,
- uint32_t revents,
- void* userdata);
-
- /** initialize an inotify instance and returns file descriptor */
- int inotifyInit();
-
- /** @brief inotify flags */
- int flags;
-
- /** @brief Mask of events */
- uint32_t mask;
-
- /** @brief Events to be watched */
- uint32_t events;
-
- /** @brief File path to be watched */
- fs::path path;
-
- /** @brief dump file directory watch descriptor */
- int wd = -1;
-
- /** @brief file descriptor manager */
- CustomFd fd;
-
- /** @brief The user level callback function wrapper */
- UserType userFunc;
+ public:
+ /** @brief ctor - hook inotify watch with sd-event
+ *
+ * @param[in] eventObj - Event loop object
+ * @param[in] flags - inotify flags
+ * @param[in] mask - Mask of events
+ * @param[in] events - Events to be watched
+ * @param[in] path - File path to be watched
+ * @param[in] userFunc - User specific callback fnction wrapper.
+ *
+ */
+ Watch(const EventPtr& eventObj, int flags, uint32_t mask, uint32_t events,
+ const fs::path& path, UserType userFunc);
+
+ Watch(const Watch&) = delete;
+ Watch& operator=(const Watch&) = delete;
+ Watch(Watch&&) = default;
+ Watch& operator=(Watch&&) = default;
+
+ /* @brief dtor - remove inotify watch and close fd's */
+ ~Watch();
+
+ private:
+ /** @brief sd-event callback.
+ * @details Collects the files and event info and call the
+ * appropriate user function for further action.
+ *
+ * @param[in] s - event source, floating (unused) in our case
+ * @param[in] fd - inotify fd
+ * @param[in] revents - events that matched for fd
+ * @param[in] userdata - pointer to Watch object
+ *
+ * @returns 0 on success, -1 on fail
+ */
+ static int callback(sd_event_source* s, int fd, uint32_t revents,
+ void* userdata);
+
+ /** initialize an inotify instance and returns file descriptor */
+ int inotifyInit();
+
+ /** @brief inotify flags */
+ int flags;
+
+ /** @brief Mask of events */
+ uint32_t mask;
+
+ /** @brief Events to be watched */
+ uint32_t events;
+
+ /** @brief File path to be watched */
+ fs::path path;
+
+ /** @brief dump file directory watch descriptor */
+ int wd = -1;
+
+ /** @brief file descriptor manager */
+ CustomFd fd;
+
+ /** @brief The user level callback function wrapper */
+ UserType userFunc;
};
} // namespace inotify
OpenPOWER on IntegriCloud