summaryrefslogtreecommitdiffstats
path: root/monitor/main.cpp
diff options
context:
space:
mode:
authorMatthew Barth <msbarth@us.ibm.com>2017-08-22 11:18:19 -0500
committerMatthew Barth <msbarth@us.ibm.com>2017-08-23 16:33:36 -0500
commit6ad28430764b7d16ee7abcb9965b76ea5583008f (patch)
tree8eb3bc7cf78b1d7807a240b5e20c739f97e1db4e /monitor/main.cpp
parentd953bb25955584410bb29ddac97587b3b633d4bd (diff)
downloadphosphor-fan-presence-6ad28430764b7d16ee7abcb9965b76ea5583008f.tar.gz
phosphor-fan-presence-6ad28430764b7d16ee7abcb9965b76ea5583008f.zip
Create fan monitor init mode
Allowing fan monitor to run in an init mode will set the fans to a functional state at each poweron for fans that were non-functional at poweroff. Then fan monitor can be started in monitor mode after the fans have ramped up to full speed and can begin being monitored for faults. This also allows for the removal of fan monitor doing a sd_notify prior to fan control starting. Change-Id: I634c9b4ec8bb30860dea54c8abd1cd6c56831d25 Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
Diffstat (limited to 'monitor/main.cpp')
-rw-r--r--monitor/main.cpp49
1 files changed, 35 insertions, 14 deletions
diff --git a/monitor/main.cpp b/monitor/main.cpp
index b9c1d81..f887232 100644
--- a/monitor/main.cpp
+++ b/monitor/main.cpp
@@ -16,6 +16,7 @@
#include <phosphor-logging/log.hpp>
#include <sdbusplus/bus.hpp>
#include <systemd/sd-daemon.h>
+#include "argument.hpp"
#include "event.hpp"
#include "fan.hpp"
#include "fan_defs.hpp"
@@ -23,12 +24,33 @@
using namespace phosphor::fan::monitor;
using namespace phosphor::logging;
-
-int main()
+int main(int argc, char* argv[])
{
auto bus = sdbusplus::bus::new_default();
sd_event* events = nullptr;
std::vector<std::unique_ptr<Fan>> fans;
+ phosphor::fan::util::ArgumentParser args(argc, argv);
+
+ if (argc != 2)
+ {
+ args.usage(argv);
+ exit(-1);
+ }
+
+ Mode mode;
+ if (args["init"] == "true")
+ {
+ mode = Mode::init;
+ }
+ else if (args["monitor"] == "true")
+ {
+ mode = Mode::monitor;
+ }
+ else
+ {
+ args.usage(argv);
+ exit(-1);
+ }
auto r = sd_event_default(&events);
if (r < 0)
@@ -46,23 +68,22 @@ int main()
for (const auto& fanDef : fanDefinitions)
{
- fans.emplace_back(std::make_unique<Fan>(bus, eventPtr, fanDef));
+ fans.emplace_back(std::make_unique<Fan>(mode, bus, eventPtr, fanDef));
}
- //Tell systemd we are initialized
- r = sd_notify(0, "READY=1");
- if (r < 1) // 0 = nothing sent, < 0 is a failure
+ if (mode == Mode::init)
{
- log<level::ERR>("sd_notify did not send anything",
- entry("ERROR=%d", r));
- return -1;
+ // Fans were initialized to be functional, exit
+ return 0;
}
-
- r = sd_event_loop(eventPtr.get());
- if (r < 0)
+ else
{
- log<level::ERR>("Failed call to sd_event_loop",
- entry("ERROR=%s", strerror(-r)));
+ r = sd_event_loop(eventPtr.get());
+ if (r < 0)
+ {
+ log<level::ERR>("Failed call to sd_event_loop",
+ entry("ERROR=%s", strerror(-r)));
+ }
}
return -1;
OpenPOWER on IntegriCloud