blob: d0376a5c84d915d2f9fd8d7c261ec6f6fe471e10 [file] [log] [blame]
Jayanth Othayotha320c7c2017-06-14 07:17:21 -05001#include <unistd.h>
2
3#include <phosphor-logging/elog-errors.hpp>
4
5#include "dump_manager.hpp"
6#include "dump_internal.hpp"
7#include "xyz/openbmc_project/Common/error.hpp"
8#include "config.h"
9
10namespace phosphor
11{
12namespace dump
13{
14
15using namespace sdbusplus::xyz::openbmc_project::Common::Error;
16using namespace phosphor::logging;
17
18namespace internal
19{
20
21void Manager::create(
22 Type type,
23 std::vector<std::string> fullPaths)
24{
25 // TODO openbmc/openbmc#1795
26 // Add implementaion of internal create function.
27}
28
29} //namepsace internal
30
31uint32_t Manager::createDump()
32{
33 std::vector<std::string> paths;
34
35 return captureDump(Type::UserRequested, paths);
36}
37
38uint32_t Manager::captureDump(
39 Type type,
40 const std::vector<std::string>& fullPaths)
41{
42 pid_t pid = fork();
43
44 // TODO openbmc/openbmc#1795
45 // Add Dump location info.
46 if (pid == 0)
47 {
48 execl("/usr/bin/ffdc", "ffdc", nullptr);
49
50 //ffdc script execution is failed.
51 auto error = errno;
52 log<level::ERR>("Error occurred during ffdc function execution",
53 entry("ERRNO=%d", error));
54 elog<InternalFailure>();
55 }
56 else if (pid > 0)
57 {
58 auto rc = sd_event_add_child(eventLoop.get(),
59 nullptr,
60 pid,
61 WEXITED | WSTOPPED,
62 callback,
63 nullptr);
64 if (0 > rc)
65 {
66 // Failed to add to event loop
67 log<level::ERR>("Error occurred during the sd_event_add_child call",
68 entry("rc=%d", rc));
69 elog<InternalFailure>();
70 }
71 }
72 else
73 {
74 auto error = errno;
75 log<level::ERR>("Error occurred during fork",
76 entry("ERRNO=%d", error));
77 elog<InternalFailure>();
78 }
79
80 return ++lastEntryId;
81}
82
83void Manager::createEntry(const fs::path& file)
84{
85 // TODO openbmc/openbmc#1795
86 // Get Dump ID and Epoch time from Dump file name.
87 // Validate the Dump file name.
88 auto id = lastEntryId;
89
90 //Get Epoch time.
91 auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(
92 std::chrono::system_clock::now().time_since_epoch()).count();
93
94 // Entry Object path.
95 auto objPath = fs::path(OBJ_ENTRY) / std::to_string(id);
96
97 auto size = fs::file_size(file);
98
99 entries.insert(std::make_pair(id,
100 std::make_unique<Entry>(
101 bus,
102 objPath.c_str(),
103 id,
104 ms,
105 size,
106 file,
107 *this)));
108}
109
110void Manager::erase(uint32_t entryId)
111{
112 entries.erase(entryId);
113}
114
115} //namespace dump
116} //namespace phosphor