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>
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 @@
 
     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;