summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJayanth Othayoth <ojayanth@in.ibm.com>2017-08-26 03:03:47 -0500
committerJayanth Othayoth <ojayanth@in.ibm.com>2017-09-01 04:12:12 -0500
commit9a56bfa96c96c855f1ad9c4efe04639eaa33a2f2 (patch)
treeb3c1b85ef2fb3273e18607d807d0c8b620fb9957
parent217fb5f2e040533e38c36569211242da328ca439 (diff)
downloadphosphor-debug-collector-9a56bfa96c96c855f1ad9c4efe04639eaa33a2f2.tar.gz
phosphor-debug-collector-9a56bfa96c96c855f1ad9c4efe04639eaa33a2f2.zip
Add core file name validation in core manager
Move the core file name validation from dreport to core manager. systemd-coredump creates temporary file in core file path prior to actual core file creation. This check will help to limit dump creation only for the new core files. Change-Id: I196d3f372d85aae0a7a36ba7171e6bfd2ff4991b Signed-off-by: Jayanth Othayoth <ojayanth@in.ibm.com>
-rw-r--r--core_manager.cpp30
-rwxr-xr-xtools/dreport12
2 files changed, 28 insertions, 14 deletions
diff --git a/core_manager.cpp b/core_manager.cpp
index f48e8dc..eb6cef5 100644
--- a/core_manager.cpp
+++ b/core_manager.cpp
@@ -1,3 +1,6 @@
+#include <regex>
+#include <experimental/filesystem>
+
#include <phosphor-logging/log.hpp>
#include "core_manager.hpp"
@@ -22,12 +25,31 @@ void watchCallback(const UserMap& fileInfo)
for (const auto& i : fileInfo)
{
// Get list of debug files.
- if (IN_CLOSE_WRITE == i.second)
+ if (IN_CLOSE_WRITE != i.second)
+ {
+ continue;
+ }
+
+ namespace fs = std::experimental::filesystem;
+ fs::path file(i.first);
+ std::string name = file.filename();
+
+ /*
+ As per coredump source code systemd-coredump uses below format
+ https://github.com/systemd/systemd/blob/master/src/coredump/coredump.c
+ /var/lib/systemd/coredump/core.%s.%s." SD_ID128_FORMAT_STR “
+ systemd-coredump also creates temporary file in core file path prior
+ 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('.')))
{
- files.push_back(i.first.string());
+ //Consider only file name start with "core."
+ files.push_back(file);
}
}
- if(!files.empty())
+
+ if (!files.empty())
{
createHelper(files);
}
@@ -40,7 +62,7 @@ void createHelper(const vector<string>& files)
constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper";
constexpr auto IFACE_INTERNAL("xyz.openbmc_project.Dump.Internal.Create");
constexpr auto APPLICATION_CORED =
- "xyz.openbmc_project.Dump.Internal.Create.Type.ApplicationCored";
+ "xyz.openbmc_project.Dump.Internal.Create.Type.ApplicationCored";
auto b = sdbusplus::bus::new_default();
auto mapper = b.new_method_call(
diff --git a/tools/dreport b/tools/dreport
index 0b5f77b..41b53d7 100755
--- a/tools/dreport
+++ b/tools/dreport
@@ -336,21 +336,13 @@ function collect_data()
# https://github.com/systemd/systemd/blob/master/src/coredump/coredump.c
# /var/lib/systemd/coredump/core.%s.%s." SD_ID128_FORMAT_STR “.
# <process ID>.%s000000"
-# Added additional check to make sure that user provided in
-# systemd-coredump format.
function set_pid()
{
- #from coredump.c file.
- CORE_BASE_STRING="/var/lib/systemd/coredump/core"
-
#Escape bash characters in file name
file=$(printf %q "$optional_file")
- string=$(echo $file | awk -F . '{ print $1}')
- if [ "$CORE_BASE_STRING" = "$string" ]; then
- #matching systemd-coredump core file format.
- core_pid=$(echo $file | awk -F . '{ print $5}')
- fi
+ #matching systemd-coredump core file format.
+ core_pid=$(echo $file | awk -F . '{ print $5}')
}
# @brief Capture debug data based on the input command array.
OpenPOWER on IntegriCloud