handler: Add check for file existence for BM mode

/tmp/BMReady.flag indicates that we are in BM mode.

Tested:
Verified both cases -
- Mar 21 11:17:52 ipmid[1130]: /tmp/BMReady.flag exists so we must be in BM mode
- Mar 21 10:37:04 ipmid[1076]: Unable to find /tmp/BMReady so we must not be in BM mode

Signed-off-by: Brandon Kim <brandonkim@google.com>
Change-Id: I9fa99b40afea7e48ce7e1f9c47e8f081b71b897f
diff --git a/handler.cpp b/handler.cpp
index 564eab8..bc8f9bd 100644
--- a/handler.cpp
+++ b/handler.cpp
@@ -72,6 +72,16 @@
 #if BARE_METAL
     return static_cast<uint8_t>(BmcMode::BM_MODE);
 #else
+    std::error_code ec;
+    if (fs::exists(BM_SIGNAL_PATH, ec))
+    {
+        std::fprintf(stderr, "%s exists so we must be in BM mode\n",
+                     BM_SIGNAL_PATH);
+        return static_cast<uint8_t>(BmcMode::BM_MODE);
+    }
+
+    std::fprintf(stderr, "Unable to find %s so we must not be in BM mode\n",
+                 BM_SIGNAL_PATH);
     return static_cast<uint8_t>(BmcMode::NON_BM_MODE);
 #endif
 }
diff --git a/meson.build b/meson.build
index 6384f73..578638b 100644
--- a/meson.build
+++ b/meson.build
@@ -19,6 +19,7 @@
 
 bm_conf_data = configuration_data()
 bm_conf_data.set10('BARE_METAL', get_option('bare_metal'))
+bm_conf_data.set_quoted('BM_SIGNAL_PATH', get_option('bm-signal-path'))
 bm_conf_h = configure_file(
   output: 'bm_config.h',
   configuration: bm_conf_data)
diff --git a/meson_options.txt b/meson_options.txt
index a91d641..64245c0 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -1,3 +1,4 @@
 option('tests', type: 'feature', description: 'Build tests')
 option('static-bifurcation', type: 'string', value: '/usr/share/google-ipmi-sys/bifurcation.json', description: 'Path to Static Bifurcation Json config')
 option('bare_metal', type: 'boolean', value: false, description: 'Bare Metal Mode Flag')
+option('bm-signal-path', type: 'string', value: '/tmp/BMReady.flag', description: 'Path to the flag to indicate that BM mode is ready')