-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathdump_manager_faultlog.cpp
More file actions
122 lines (99 loc) · 3.62 KB
/
dump_manager_faultlog.cpp
File metadata and controls
122 lines (99 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "config.h"
#include "dump_manager_faultlog.hpp"
#include "dump_utils.hpp"
#include "faultlog_dump_entry.hpp"
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/elog.hpp>
#include <phosphor-logging/lg2.hpp>
#include <xyz/openbmc_project/Common/File/error.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <string>
namespace phosphor
{
namespace dump
{
namespace faultlog
{
using namespace phosphor::logging;
using namespace sdbusplus::xyz::openbmc_project::Common::Error;
using namespace sdbusplus::xyz::openbmc_project::Common::File::Error;
using ErrnoOpen = xyz::openbmc_project::Common::File::Open::ERRNO;
using PathOpen = xyz::openbmc_project::Common::File::Open::PATH;
sdbusplus::message::object_path Manager::createDump(
phosphor::dump::DumpCreateParams params)
{
lg2::info("In dump_manager_fault.cpp createDump");
// Currently we ignore the parameters.
// TODO phosphor-debug-collector/issues/22: Check parameter values and
// exit early if we don't receive the expected parameters
if (params.empty())
{
lg2::info("No additional parameters received");
}
else
{
lg2::info("Got additional parameters");
}
// Get the originator id and type from params
std::string originatorId;
originatorTypes originatorType;
phosphor::dump::extractOriginatorProperties(params, originatorId,
originatorType);
// Get the id
auto id = lastEntryId + 1;
auto idString = std::to_string(id);
auto objPath = std::filesystem::path(baseEntryPath) / idString;
std::filesystem::path faultLogFilePath(
std::string(FAULTLOG_DUMP_PATH) + idString);
std::ofstream faultLogFile;
errno = 0;
faultLogFile.open(faultLogFilePath,
std::ofstream::out | std::fstream::trunc);
if (faultLogFile.is_open())
{
lg2::info("faultLogFile is open");
faultLogFile << "This is faultlog file #" << idString << " at "
<< std::string(FAULTLOG_DUMP_PATH) + idString << std::endl;
faultLogFile.close();
}
else
{
lg2::error(
"Failed to open fault log file at {FILE_PATH}, errno: {ERRNO}, "
"strerror: {STRERROR}, OBJECTPATH: {OBJECT_PATH}, ID: {ID}",
"FILE_PATH", faultLogFilePath, "ERRNO", errno, "STRERROR",
strerror(errno), "OBJECT_PATH", objPath, "ID", id);
elog<Open>(ErrnoOpen(errno), PathOpen(objPath.c_str()));
}
try
{
lg2::info("dump_manager_faultlog.cpp: add faultlog entry");
uint64_t timestamp =
std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::system_clock::now().time_since_epoch())
.count();
entries.insert(std::make_pair(
id,
std::make_unique<faultlog::Entry>(
bus, objPath.c_str(), id, timestamp,
std::filesystem::file_size(faultLogFilePath), faultLogFilePath,
phosphor::dump::OperationStatus::Completed, originatorId,
originatorType, *this)));
}
catch (const std::invalid_argument& e)
{
lg2::error("Error in creating dump entry, errormsg: {ERROR}, "
"OBJECTPATH: {OBJECT_PATH}, ID: {ID}",
"ERROR", e, "OBJECT_PATH", objPath, "ID", id);
elog<InternalFailure>();
}
lastEntryId++;
lg2::info("End of dump_manager_faultlog.cpp createDump");
return objPath.string();
}
} // namespace faultlog
} // namespace dump
} // namespace phosphor