monitor: Use only init mode when using JSON

Fan monitor is currently split into 2 modes - 'init' which is used
right after a power on, and 'monitor', which is used later after the
fans-ready target is started.  Normally, the 'init' mode just sets the
fans to functional and then exits, and the real monitoring work is done
in the 'monitor' mode.

In the future this application will need to be able to check for fan
problems as soon as it starts up after power on so that it can handle
shutting down due to missing fans.  To prepare for this, move all
functionality into the init mode, and just exit immediately when called
to run in the monitor mode.  Only do this when compiled to use the JSON
configuration, as this is new and I don't want to change how the
existing YAML setups work.

This also creates a new 'monitor_start_delay' entry in the JSON to say
how long to wait after startup before actually doing any sensor
monitoring, which then gives the same behavior as how the monitor mode
would delay by waiting for the fan control ready target, which itself is
started by fan control --init after a hardcoded delay.  This field is
optional to preserve backwards compatibility and defaults to 0s.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I623a233f50233e734f50cd9e80139c60467518d8
diff --git a/monitor/main.cpp b/monitor/main.cpp
index 04c4cf9..93a5e1d 100644
--- a/monitor/main.cpp
+++ b/monitor/main.cpp
@@ -54,6 +54,16 @@
         return 1;
     }
 
+    // If using JSON, then everything is handled in a single
+    // step - the init step.  Hopefully these can eventually be
+    // reduced into a single invocation.
+#ifdef MONITOR_USE_JSON
+    if (mode == Mode::monitor)
+    {
+        return 0;
+    }
+#endif
+
     // Attach the event object to the bus object so we can
     // handle both sd_events (for the timers) and dbus signals.
     bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
@@ -69,11 +79,13 @@
                                                  std::placeholders::_2));
 #endif
 
+#ifndef MONITOR_USE_JSON
     if (mode == Mode::init)
     {
         // Fans were initialized to be functional, exit
         return 0;
     }
+#endif
 
     return event.loop();
 }